where('store_id', $store_id)->order('id','desc')->find(); if(!$order) return "{$store_abbr}10000001"; $code = (int)str_ireplace($store_abbr, '', $order->no) + 1; return "{$store_abbr}{$code}"; } public function products() { return $this->hasMany(OrderProductModel::class, 'order_id','id')->where('is_delete',0); } public function payments() { return $this->hasMany(OrderPaymentModel::class, 'order_id','id')->where('is_delete',0); } public function annuals() { return $this->hasMany(OrderAnnualFeeModel::class, 'order_id','id')->where('is_delete',0); } public function proceeds() { return $this->hasMany(OrderProceedsModel::class, 'order_id','id')->where('is_delete',0); } public function store() { return $this->hasOne(StoreModel::class, 'id', 'store_id'); } public function findByPaginate(array $params) { $where = [ ['is_delete', '=', 0] ]; if($params['store_id'] > 0) array_push($where,['store_id', '=', $params['store_id']]); if($params['type'] > 0) array_push($where,['type', '=', $params['type']]); return $this->where($where) ->with(['products','store']) ->order('update_time','desc') ->paginate(['list_rows'=>10, "query" => $params]); } public function report(array $params) { $where = [ ['is_delete', '=', 0] ]; if($params['store_id'] > 0) array_push($where,['store_id', '=', $params['store_id']]); if($params['type'] > 0) array_push($where,['type', '=', $params['type']]); return $this->where($where) ->with(['products','store']) ->order('create_time','desc') ->select(); } public function findById($id) { return $this->where('is_delete',0) ->with([ 'products', 'payments', 'payments.payment_channel', 'annuals', 'proceeds' ])->find($id); } /** * @param $params * @param bool $verify * @return array * @throws \think\db\exception\DbException */ public function search($params, $verify = false) { $where = [ ['is_delete', '=', 0], ['type', '=', $params['type']], ['store_id', '=', $params['store_id']], ]; if (isset($params['order_no']) && strlen($params['order_no']) > 0) array_push($where, ['no', 'like', '%'.$params['order_no'].'%']); if (isset($params['start_time']) && $params['start_time'] > 0) array_push($where, ['create_time', '>=', $params['start_time']]); if (isset($params['end_time']) && $params['end_time'] > 0) array_push($where, ['create_time', '<=', $params['end_time']]); if (isset($params['obj_name']) && strlen($params['obj_name']) > 0) array_push($where, ['obj_names', 'like', '%'.$params['obj_name'].'%']); $query = $this->where($where) ->with(['products', 'payments']); if (isset($params['advisor_id'])) $query->where("FIND_IN_SET('{$params['advisor_id']}', advisor_ids)"); if (!$verify) { $query->where("FIND_IN_SET('{$params['admin_id']}', advisor_ids)"); } return $query->order('update_time', 'desc') ->page($params['page'] ?? 1) ->paginate($params['size'] ?? 10) ->toArray(); } public function fetchOrderByCustomerId($c_id) { return $this->where([ ['is_delete', '=', 0], ['customer_id', '=', $c_id] ]) ->order('create_time','desc') ->select() ->toArray(); } /** * @param $customer_id * @param int $page * @param int $size * @return array * @throws \think\db\exception\DbException */ public function fetchByCustomerId($customer_id, $page = 1, $size = 10) { return $this->where([ ['is_delete', '=', 0], ['customer_id', '=', $customer_id] ]) ->with(['products', 'payments']) ->order('update_time', 'desc') ->page($page) ->paginate($size) ->toArray(); } public function fetchOrderByReturn($admin_id, $store_id, $no = null, $customer_name = null, $page = 1, $size = 10, $verify = false) { $where = [ ['is_delete', '=', 0], ['type', '=', 1], ['store_id', '=', $store_id], ]; if (isset($no) && strlen($no) > 0) array_push($where, ['no', 'like', '%'.$no.'%']); if ($customer_name) array_push($where, ['customer_name', 'like', '%'.$customer_name.'%']); $query = $this->where($where) ->with(['products']); if (!$verify) { $query->where("FIND_IN_SET('{$admin_id}', advisor_ids)"); } return $query->order('update_time', 'desc') ->page($page) ->paginate($size); } public function findByOrderNo($admin_id, $order_no, $verify = false) { $where = [ ['is_delete', '=', 0], ['type', '=', 1], ]; if (isset($order_no) && strlen($order_no) > 0) array_push($where, ['no', '=', $order_no]); // array_push($where, ['no', 'like', '%'.$order_no.'%']); $query = $this->where($where) ->with(['products']); if (!$verify) { $query->where("FIND_IN_SET('{$admin_id}', advisor_ids)"); } return $query->order('update_time', 'desc') ->find(); } }