StoreProductModel.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\common\model;
  3. class StoreProductModel extends BaseModel
  4. {
  5. protected $table = 'erp_store_product';
  6. protected function genSchema(array $schema)
  7. {
  8. // TODO: Implement genSchema() method.
  9. }
  10. public function store()
  11. {
  12. return self::hasOne(StoreModel::class,'id','store_id');
  13. }
  14. public function product()
  15. {
  16. return self::hasOne(ProductModel::class,'id','product_id');
  17. }
  18. public function doesItExist($store_id, $product_id) {
  19. return $this->where([
  20. ["store_id", '=', $store_id],
  21. ["product_id", '=', $product_id],
  22. ["is_delete", '=', 0]
  23. ])->find();
  24. }
  25. /**
  26. * @param array $params
  27. * @return \think\Paginator
  28. * @throws \think\db\exception\DbException
  29. */
  30. public function findByPaginate(array $params) {
  31. // if(!is_null($params['bar_code']))
  32. // array_push($where,['bar_code', 'like', "%".$params['bar_code']."%"]);
  33. // if(!is_null($params['category_id']) && $params['category_id'] > 0)
  34. // array_push($where,['category_id', '=', $params['category_id']]);
  35. // if(!is_null($params['is_serve']))
  36. // array_push($where,['is_serve', '=', $params['is_serve']]);
  37. $store_where = [
  38. ['is_delete','=', 0],
  39. ];
  40. $product_where = [
  41. ['is_delete','=', 0],
  42. ];
  43. if($params['store_id'] > 0)
  44. array_push($store_where,["id", "=", $params['store_id']]);
  45. return $this->where('erp_store_product.is_delete',0)
  46. ->hasWhere('store', $store_where)
  47. ->hasWhere('product',$product_where)
  48. ->with(['store', 'product'])
  49. ->order(isset($params['sort']) ? $params['sort'] : 'create_time','desc')
  50. ->paginate(['list_rows'=>10, "query" => $params]);
  51. }
  52. }