where($query->getTable() . '.shop_supplier_id', -1); }else{ $query->where($query->getTable() . '.shop_supplier_id', 'in', $shop_supplier_ids); } } /** * 获取订单列表 */ public function getList($search) { $model = $this ->with(['demanduser','supplyuser',"project"]) ->order(['create_time' => 'desc']); if (!empty($search['supply_user_id'])) { $model = $model->where('supply_user_id', '=', $search['supply_user_id']); } if (!empty($search['demand_user_id'])) { $model = $model->where('demand_user_id', '=', $search['demand_user_id']); } if ($search['pay_status'] > -1) { $model = $model->where('pay_status', '=', $search['pay_status']); } if ($search['order_status'] > -1) { $model = $model->where('order_status', '=', $search['order_status']); } if (!empty($search['pay_type'])) { $model = $model->where('pay_type', '=', $search['pay_type']); } //搜索时间段 if (isset($search['create_time']) && $search['create_time'] != '') { $sta_time = array_shift($search['create_time']); $end_time = array_pop($search['create_time']); $model = $model->whereBetweenTime('create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } // if (!empty($search['nick_name'])) { // $model = $model->where('user.nickName|order.real_name|order.mobile', 'like', '%' . $search['nick_name'] . '%'); // } // 获取列表数据 return $model->paginate($search); } /** * 编辑用户 * @param $data * @return bool */ public function edit($data) { // 开启事务 $this->startTrans(); try { $this->save($data); $this->commit(); return true; } catch (\Exception $e) { $this->error = $e->getMessage(); $this->rollback(); return false; } } /** * 获取微信支付的金额 */ public function getTotalPayByDate($day,$user_ids=[],$in='true',$pay_type=10,$shop_supplier_id='') { if(is_array($day)){ $start = $day[0]; $end = $day[1]; }else{ $start = strtotime($day); $end = strtotime($day) + 86399; } $model = $this; if(!empty($user_ids)){ if($in){ $model = $model->where('user_id', 'in', $user_ids); }else{ $model = $model->where('user_id', 'not in', $user_ids); } } $money = $model->where('create_time', 'between', "$start,$end") ->where('pay_status', '=', 20) ->where('pay_type', '=', $pay_type) ->sum("pay_price"); return $money; } /** * 确认线下已支付 */ public function onCash($data) { if ( $this['pay_status'] != 10 ) { $this->error = '该订单不满足线下支付条件'; return false; } return $this->transaction(function () use ($data) { $save_data=[ 'pay_status'=>20, 'pay_time'=>time(), 'pay_type'=>40, ]; return $this->where("id","=",$data["id"])->save($save_data); }); } /** * 确认已完成订单 */ public function onFinish($data) { if ( $this['pay_status'] != 20 || $this['order_status'] != 10 ) { $this->error = '该订单不满足完成的条件'; return false; } return $this->transaction(function () use ($data) { //给供应方发放佣金 (new SupplyUserModel())->where("user_id","=",$this["supply_user_id"])->inc("money",$this["money"])->update(); $save_data=[ 'order_status'=>30, 'finish_time'=>time(), ]; return $this->where("id","=",$data["id"])->save($save_data); }); } /** * 取消订单 */ public function confirmCancel($user) { if ($this['order_status'] == 30) { $this->error = '已完成不可取消'; return false; } //订单不能取消 if($this['order_status'] != 10){ $this->error = '该订单取消失败'; return false; } // 订单取消事件 return $this->transaction(function () use ($user) { // 更新订单状态 return $this->save(['order_status' => 20]); }); } }