Няма описание

SyncCustSaler.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use DB;
  5. class SyncCustSaler extends Command {
  6. protected $signature = 'SyncCustSaler';
  7. /**
  8. * The console command description.
  9. *
  10. * @var string
  11. */
  12. protected $description = '同步复购、客户第一次下单销售';
  13. public function handle()
  14. {
  15. $this->syncFugou();
  16. }
  17. public function syncFugou(){
  18. $customers = DB::table('customers')->select('id', 'phone')->where('phone','>','')->get();
  19. $customers = json_decode(json_encode($customers), true);
  20. foreach($customers as $k=>$v){
  21. //更新第一单为非复购
  22. $first_order = DB::table('order')->select('id')->where('receiverMobile', $v['phone'])->where('is_del',0)->orderBy('createTime', 'asc')->first();
  23. if(empty($first_order)) continue;
  24. DB::table('order')->where('id', $first_order->id)->update(['is_fugou'=>0]);
  25. //单数
  26. $order_count = DB::table('order')->where('receiverMobile', $v['phone'])->where('is_del', 0)->count();
  27. if($order_count>1){
  28. //是复购
  29. DB::table('customers')->where('id', $v['id'])->update(['is_fugou'=>1]);
  30. DB::table('order')->where('id', '!=', $first_order->id)->where('receiverMobile', $v['phone'])->where('is_del',0)->update(['is_fugou'=>1]);
  31. }else{
  32. DB::table('customers')->where('id', $v['id'])->update(['is_fugou'=>0]);
  33. }
  34. }
  35. }
  36. public function SyncCustSaler(){
  37. $customers = DB::table('customers')->select('id', 'phone')->where('phone','>','')->get();
  38. $customers = json_decode(json_encode($customers), true);
  39. foreach($customers as $k=>$v){
  40. $order = DB::table('order')->select('admin_id')->where('receiverMobile', $v['phone'])->where('is_del', 0)->orderBy('createTime', 'asc')->first();
  41. if(empty($order)){
  42. echo "\n".$v['phone']." 失败,未找到订单:";
  43. continue;
  44. }
  45. $admin_id = $order->admin_id;
  46. $res = DB::table('customers')->where('id', $v['id'])->update(['admin_id'=>$admin_id]);
  47. echo "\n".$v['phone']." 结果:".$res;
  48. }
  49. }
  50. }