where('is_delete', 0); } public function product() { return self::hasOne(ProductModel::class,'id','product_id')->where('is_delete', 0); } public function doesItExist($store_id, $product_id) { return $this->where([ ["store_id", '=', $store_id], ["product_id", '=', $product_id], ["is_delete", '=', 0] ])->find(); } /** * @param array $params * @return \think\Paginator * @throws \think\db\exception\DbException */ public function findByPaginate(array $params) { // if(!is_null($params['bar_code'])) // array_push($where,['bar_code', 'like', "%".$params['bar_code']."%"]); // if(!is_null($params['category_id']) && $params['category_id'] > 0) // array_push($where,['category_id', '=', $params['category_id']]); // if(!is_null($params['is_serve'])) // array_push($where,['is_serve', '=', $params['is_serve']]); $store_where = [ ['is_delete','=', 0], ]; $product_where = [ ['is_delete','=', 0], ]; if($params['store_id'] > 0) array_push($store_where,["id", "=", $params['store_id']]); return $this->where('erp_store_product.is_delete',0) ->hasWhere('store', $store_where) ->hasWhere('product',$product_where) ->with(['store', 'product']) ->order(isset($params['sort']) ? $params['sort'] : 'create_time','desc') ->paginate(['list_rows'=>10, "query" => $params]); } public function search(array $params) { $where = [ ['is_delete', '=', 0], ['store_id', '=', $params['store_id']] ]; if($params['bar_code']) array_push($where, ['product_bar_code', 'like', '%'.$params['bar_code'].'%']); if($params['product_name']) array_push($where, ['product_name', 'like', '%'.$params['product_name'].'%']); return $this->where($where) ->with('product') ->page($params['page']) ->paginate($params['size'] ?? 10); } public function fetchRelationsByOrder($ids = []) { $where = [ ['id', 'in', $ids], ['is_delete', '=', 0] ]; return $this->where($where) ->with('product') ->select(); } public function fetchByStoreIdAndProductIds($s_id, $p_ids) { $where = [ ['product_id', 'in', $p_ids], ['store_id', '=', $s_id], ['is_delete', '=', 0] ]; return $this->where($where) ->select(); } }