StoreProductModel.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  11. * @return \think\model\relation\HasOne
  12. */
  13. public function store()
  14. {
  15. return self::hasOne(StoreModel::class,'id','store_id');
  16. }
  17. public function product()
  18. {
  19. return self::hasOne(ProductModel::class,'id','product_id');
  20. }
  21. public function doesItExist($store_id, $product_id) {
  22. return $this->where([
  23. ["store_id", '=', $store_id],
  24. ["product_id", '=', $product_id],
  25. ["is_delete", '=', 0]
  26. ])->find();
  27. }
  28. /**
  29. * @param array $params
  30. * @return \think\Paginator
  31. * @throws \think\db\exception\DbException
  32. */
  33. public function findByPaginate(array $params) {
  34. // if(!is_null($params['bar_code']))
  35. // array_push($where,['bar_code', 'like', "%".$params['bar_code']."%"]);
  36. // if(!is_null($params['category_id']) && $params['category_id'] > 0)
  37. // array_push($where,['category_id', '=', $params['category_id']]);
  38. // if(!is_null($params['is_serve']))
  39. // array_push($where,['is_serve', '=', $params['is_serve']]);
  40. $store_where = [
  41. ['is_delete','=', 0],
  42. ];
  43. $product_where = [
  44. ['is_delete','=', 0],
  45. ];
  46. if($params['store_id'] > 0)
  47. array_push($store_where,["id", "=", $params['store_id']]);
  48. return $this->where('erp_store_product.is_delete',0)
  49. ->hasWhere('store', $store_where)
  50. ->hasWhere('product',$product_where)
  51. ->with(['store', 'product'])
  52. ->order(isset($params['sort']) ? $params['sort'] : 'create_time','desc')
  53. ->paginate(['list_rows'=>10, "query" => $params]);
  54. }
  55. }