getCustomerList(); } catch (\Exception $e) { echo $e->getMessage(); } } public function getCustomerList() { $page = $this->page; $offset = ($page - 1) * $this->limit; //分页获取用户列表数据 $list = Customer::select('id','phone','name','fanTime')->offset($offset)->limit($this->limit)->get(); $list = json_decode(json_encode($list),true); if(count($list) > 0){ $this->page++; sleep(1); $this->updateOrInsert($list); $this->getCustomerList(); } else { echo 'SUCCESS';die; } } public function updateOrInsert ( $data ) { foreach ( $data as $value ) { //遍历用户 统计每个用户的订单情况 $order = Order::select(DB::raw('count(1) as num, SUM(receivedAmount) AS totalReceiveAmount, SUM(freight_cost) AS totalFreightCost, SUM(aftersale_fee) as totalAftersaleFee, SUM(refund_price) AS totalRefundPrice, SUM(cost) as totalCost'))->where('receiverMobile',$value['phone'])->where('is_del',0)->first(); $params['totalReceivedAmount'] = $order->totalReceiveAmount; $params['totalOrderNumber'] = $order->num; $params['totalCost'] = $order->totalCost; $params['totalRefundPrice'] = $order->totalRefundPrice; $params['totalFreightCost'] = $order->totalFreightCost; $params['totalAftersaleFee'] = $order->totalAftersaleFee; $params['grossProfit'] = ($params['totalReceivedAmount'] + $params['totalRefundPrice']) - ($params['totalCost'] + $params['totalFreightCost'] + $params['totalAftersaleFee']); $params['grossProfitRatio'] = $params['totalReceivedAmount'] == 0 ? 0 : ($params['grossProfit'] / $params['totalReceivedAmount']); $res = CustomerOrderDay::where('customer_id',$value['id'])->first(); if($res){ CustomerOrderDay::where('customer_id',$value['id'])->update($params); } else { $params['customer_id'] = $value['id']; $params['name'] = $value['name']; $params['phone'] = $value['phone']; $params['fanTime'] = $value['fanTime']; CustomerOrderDay::insert($params); } } } }