链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Models;
  3. use App\Admin\Common\Rpc;
  4. use Dcat\Admin\Traits\HasDateTimeFormatter;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\DB;
  7. class ImsCjdcOrderMain extends Model
  8. {
  9. use HasDateTimeFormatter;
  10. //protected $table = 'ims_cjdc_order_main';
  11. protected $table = 'lanzu_order_main';
  12. public $timestamps = false;
  13. public function imsCjdcUser()
  14. {
  15. return $this->hasOne('\App\Models\ImsCjdcUser', 'id', 'user_id');
  16. }
  17. public function market()
  18. {
  19. return $this->hasOne('\App\Models\ImsCjdcMarket', 'id', 'market_id');
  20. }
  21. /**
  22. * 变更订单状态,
  23. * @param $oid //主订单id
  24. * @param $state //订单状态
  25. */
  26. public function modifyState($oid, $state)
  27. {
  28. $where = [];
  29. $where['state'] = $state;
  30. $where['updated_at'] = time();
  31. if ($state == 3) {
  32. $where['receive_time'] = time();
  33. } elseif ($state == 4) {
  34. $where['complete_time'] = time();
  35. } elseif ($state == 6) {
  36. $where['cancel_time'] = time();
  37. }
  38. return self::where('id', $oid)->update($where);
  39. }
  40. public function updateShippingType($oid, $type)
  41. {
  42. return self::where('id', $oid)->update(['shipping_type' => $type]);
  43. }
  44. public static function getOrderData($oid)
  45. {
  46. $order = ImsCjdcOrderMain::where('id', $oid)->first()->toArray();
  47. $order['created_at'] = date('Y-m-d H:i:s', $order['created_at']);
  48. $order['updated_at'] = $order['updated_at'] ? date('Y-m-d H:i:s', $order['updated_at']) : null;
  49. $order['pay_type'] = config('order.pay_type')[$order['pay_type']];
  50. $order['shipping_type'] = config('order.shipping_type')[$order['shipping_type']];
  51. $order['horseman_name'] = $order['shipping_name'] ?? LanzuServiceHorseman::getName($order['horseman_id']);
  52. //获取市场经纬度
  53. //$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray();
  54. //$order['distance'] = Rpc::getDistance($market['lng'],$market['lat'],$order['lng'],$order['lat'])['result'];
  55. if ($order['delivery_distance'] > 1000) {
  56. $order['delivery_distance'] = number_format(($order['delivery_distance'] / 1000), 1) . 'km';
  57. } else {
  58. $order['delivery_distance'] .= '米';
  59. }
  60. return $order;
  61. }
  62. public static function getOrderStateCount($state, $marketId = null)
  63. {
  64. if ($marketId) {
  65. $count = self::where('state', $state)
  66. ->where('type', 1)
  67. ->where('market_id',$marketId)
  68. ->count();
  69. }else{
  70. $count = self::where('state', $state)
  71. ->where('type', 1)
  72. ->count();
  73. }
  74. return $count;
  75. }
  76. }