| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\common\model;
- class StoreProductModel extends BaseModel
- {
- protected $table = 'erp_store_product';
- protected function genSchema(array $schema)
- {
- // TODO: Implement genSchema() method.
- }
- /**
- * @return \think\model\relation\HasOne
- */
- public function store()
- {
- return self::hasOne(StoreModel::class,'id','store_id')->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();
- }
- }
|