ProductModel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\common\model;
  3. class ProductModel extends BaseModel
  4. {
  5. protected $table = 'erp_product';
  6. protected function genSchema(array $schema)
  7. {
  8. // TODO: Implement genSchema() method.
  9. }
  10. /**
  11. * @param array $params
  12. * @return \think\Paginator
  13. * @throws \think\db\exception\DbException
  14. */
  15. public function findByPaginate(array $params) {
  16. $where = [
  17. ['is_delete', '=', 0]
  18. ];
  19. if(!is_null($params['bar_code']))
  20. array_push($where,['bar_code', 'like', "%".$params['bar_code']."%"]);
  21. if(!is_null($params['category_id']) && $params['category_id'] > 0)
  22. array_push($where,['category_id', '=', $params['category_id']]);
  23. if(!is_null($params['is_serve']))
  24. array_push($where,['is_serve', '=', $params['is_serve']]);
  25. return $this->where($where)->order('create_time','desc')->paginate(['list_rows'=>10, "query" => $params]);
  26. }
  27. public function findProducts($text = null) {
  28. $or_where = [];
  29. if(strlen($text) > 0) {
  30. array_push($or_where, ['name|bar_code', 'like', '%'.$text.'%']);
  31. }
  32. return $this->where('is_delete', 0)->where($or_where)->page(1,10)->select();
  33. }
  34. public function doesItExist($bar_code) {
  35. $customer = $this->where([
  36. ["bar_code", '=', $bar_code],
  37. ["is_delete", '=', 0]
  38. ])->find();
  39. return $customer ? true : false;
  40. }
  41. }