12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use DB;
- class SyncCustSaler extends Command {
- protected $signature = 'SyncCustSaler';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '同步复购、客户第一次下单销售';
- public function handle()
- {
- $this->syncFugou();
- }
-
- public function syncFugou(){
- $customers = DB::table('customers')->select('id', 'phone')->where('phone','>','')->get();
- $customers = json_decode(json_encode($customers), true);
- foreach($customers as $k=>$v){
- //更新第一单为非复购
- $first_order = DB::table('order')->select('id')->where('receiverMobile', $v['phone'])->where('is_del',0)->orderBy('createTime', 'asc')->first();
- if(empty($first_order)) continue;
- DB::table('order')->where('id', $first_order->id)->update(['is_fugou'=>0]);
- //单数
- $order_count = DB::table('order')->where('receiverMobile', $v['phone'])->where('is_del', 0)->count();
- if($order_count>1){
- //是复购
- DB::table('customers')->where('id', $v['id'])->update(['is_fugou'=>1]);
- DB::table('order')->where('id', '!=', $first_order->id)->where('receiverMobile', $v['phone'])->where('is_del',0)->update(['is_fugou'=>1]);
- }else{
- DB::table('customers')->where('id', $v['id'])->update(['is_fugou'=>0]);
- }
- }
- }
- public function SyncCustSaler(){
- $customers = DB::table('customers')->select('id', 'phone')->where('phone','>','')->get();
- $customers = json_decode(json_encode($customers), true);
- foreach($customers as $k=>$v){
- $order = DB::table('order')->select('admin_id')->where('receiverMobile', $v['phone'])->where('is_del', 0)->orderBy('createTime', 'asc')->first();
- if(empty($order)){
- echo "\n".$v['phone']." 失败,未找到订单:";
- continue;
- }
- $admin_id = $order->admin_id;
- $res = DB::table('customers')->where('id', $v['id'])->update(['admin_id'=>$admin_id]);
- echo "\n".$v['phone']." 结果:".$res;
- }
- }
- }
|