OrderCountContentJob.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2018/9/19
  5. * Time: 下午3:37
  6. */
  7. namespace app\Jobs;
  8. use app\backend\modules\charts\models\OrderIncomeCount;
  9. use Carbon\Carbon;
  10. use Illuminate\Bus\Queueable;
  11. use Illuminate\Queue\SerializesModels;
  12. use Illuminate\Queue\InteractsWithQueue;
  13. use Illuminate\Contracts\Queue\ShouldQueue;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Schema;
  16. class OrderCountContentJob implements ShouldQueue
  17. {
  18. use InteractsWithQueue, Queueable, SerializesModels;
  19. protected $orderModel;
  20. protected $countModel;
  21. public function __construct($orderModel)
  22. {
  23. $this->orderModel = $orderModel;
  24. }
  25. public function handle()
  26. {
  27. $data = [
  28. 'uniacid' => $this->orderModel->uniacid,
  29. 'price' => $this->orderModel->price,
  30. 'uid' => $this->orderModel->uid,
  31. 'order_sn' => $this->orderModel->order_sn,
  32. 'order_id' => $this->orderModel->id,
  33. 'status' => $this->orderModel->status,
  34. 'plugin_id' => $this->orderModel->plugin_id,
  35. 'dispatch_price' => $this->orderModel->dispatch_price,
  36. 'shop_name' => $this->orderModel->shop_name,
  37. 'cost_price' => $this->costPrice(),
  38. //'day_time' => Carbon::today()->getTimestamp(),/
  39. 'day_time' => strtotime(date('Ymd',$this->orderModel->created_at)),//应该以订单创建时间为准,而不是以队列执行的时间
  40. ];
  41. $data['address'] = $this->address();
  42. $data['buy_name'] = $this->buyName();
  43. $parent = $this->referrerName();
  44. $data['parent_id'] = $parent['parent_id'];
  45. $data['parent_name'] = $parent['nickname'];
  46. // $build = OrderIncomeCount::where('order_id',$this->orderModel->id)->first();
  47. // if ($build) {
  48. // return $build;
  49. // } else {
  50. $build = OrderIncomeCount::create($data);
  51. // }
  52. return $build;
  53. }
  54. public function address()
  55. {
  56. $build = DB::table('yz_order_address')
  57. ->select()
  58. ->where('order_id', $this->orderModel->id);
  59. $content = $build->first()['address'];
  60. if (empty($content)) {
  61. return '';
  62. }
  63. return $content;
  64. }
  65. public function buyName()
  66. {
  67. $build = DB::table('mc_members')
  68. ->select()
  69. ->where('uid', $this->orderModel->uid);
  70. $content = $build->first()['nickname'];
  71. if (empty($content)) {
  72. return '';
  73. }
  74. return $content;
  75. }
  76. public function referrerName()
  77. {
  78. $referrerTable = DB::table('yz_member')
  79. ->select()
  80. ->where('member_id', $this->orderModel->uid);
  81. $parent_id = $referrerTable->first()['parent_id'];
  82. if ($parent_id) {
  83. $build = DB::table('mc_members')
  84. ->select()
  85. ->where('uid', $parent_id);
  86. $content['nickname'] = $build->first()['nickname'];
  87. $content['parent_id'] = $parent_id;
  88. } else {
  89. $content['nickname'] = '总店';
  90. $content['parent_id'] = 0;
  91. }
  92. return $content;
  93. }
  94. //记录商家名称
  95. // public function shopName()
  96. // {
  97. // if ($this->orderModel->is_plugin) {
  98. // $supplierTable = DB::table('yz_supplier_order')
  99. // ->select()
  100. // ->where('order_id', $this->orderModel->id);
  101. // $supplier_id = $supplierTable->first()['supplier_id'];
  102. // $build = DB::table('yz_supplier')
  103. // ->select()
  104. // ->where('id', $supplier_id);
  105. // $content = $build->first()['username'];
  106. // if (empty($content)) {
  107. // $content = '供应商';
  108. // }
  109. //
  110. // } elseif ($this->orderModel->plugin_id == 31) {
  111. // $cashierTable = DB::table('yz_plugin_cashier_order')
  112. // ->select()
  113. // ->where('order_id', $this->orderModel->id);
  114. // $cashier_id = $cashierTable->first()['cashier_id'];
  115. // $build = DB::table('yz_store')
  116. // ->select()
  117. // ->where('cashier_id', $cashier_id);
  118. // $content = $build->first()['store_name'];
  119. // if (empty($content)) {
  120. // $content = '收银台';
  121. // }
  122. //
  123. // } elseif ($this->orderModel->plugin_id == 32) {
  124. // $storeTable = DB::table('yz_plugin_store_order')
  125. // ->select()
  126. // ->where('order_id', $this->orderModel->id);
  127. // $store_id = $storeTable->first()['store_id'];
  128. // $build = DB::table('yz_store')
  129. // ->select()
  130. // ->where('id', $store_id);
  131. // $content = $build->first()['store_name'];
  132. // if (empty($content)) {
  133. // return '门店';
  134. // }
  135. //
  136. // } else {
  137. // $content = '平台自营';
  138. // }
  139. // return $content;
  140. // }
  141. //记录成本价
  142. public function costPrice()
  143. {
  144. if ($this->orderModel->plugin_id == 32) {
  145. $order = DB::table('yz_plugin_store_order')
  146. ->select()
  147. ->where('order_id', $this->orderModel->id)
  148. ->first();
  149. $cost_price = $order['amount'];
  150. } else if ($this->orderModel->plugin_id == 31) {
  151. $order = DB::table('yz_plugin_cashier_order')
  152. ->select()
  153. ->where('order_id', $this->orderModel->id)
  154. ->first();
  155. $cost_price = $order['amount'];
  156. } else if ($this->orderModel->plugin_id == 33) {
  157. $order = DB::table('yz_plugin_hotel_order')
  158. ->select()
  159. ->where('order_id', $this->orderModel->id)
  160. ->first();
  161. $cost_price = $order['amount'];
  162. } else if ($this->orderModel->plugin_id == 36) {
  163. $order = DB::table('yz_plugin_hotel_cashier_order')
  164. ->select()
  165. ->where('order_id', $this->orderModel->id)
  166. ->first();
  167. $cost_price = $order['amount'];
  168. } else {
  169. $cost_price = $this->orderModel->cost_amount;
  170. }
  171. return $cost_price;
  172. }
  173. }