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; } } }