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('create_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', // 'payments.card_config', 'annuals', 'proceeds' ])->find($id); } }