| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\common\model;
- class ProductModel extends BaseModel
- {
- protected $table = 'erp_product';
- protected function genSchema(array $schema)
- {
- // TODO: Implement genSchema() method.
- }
- public function category() {
- return self::hasOne(ProductCategoryModel::class,'id','category_id');
- }
- public function company() {
- return self::hasOne(CompanyModel::class,'id','company_id');
- }
- /**
- * @param array $params
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function findByPaginate(array $params) {
- $where = [
- ['erp_product.is_delete', '=', 0]
- ];
- if(!is_null($params['bar_code']))
- array_push($where,['erp_product.bar_code', 'like', "%".$params['bar_code']."%"]);
- if(!is_null($params['category_id']) && $params['category_id'] > 0)
- array_push($where,['erp_product.category_id', '=', $params['category_id']]);
- if(!is_null($params['is_serve']))
- array_push($where,['erp_product.is_serve', '=', $params['is_serve']]);
- return $this->with(['category', 'company'])
- ->where($where)
- ->order('create_time','desc')
- ->paginate(['list_rows'=>10, "query" => $params]);
- }
- public function fetchByStock($params) {
- $where = [
- ['erp_product.is_delete', '=', 0]
- ];
- return $this->with(['category', 'company'])
- ->where($where)
- ->order('create_time','desc')
- ->paginate(['list_rows'=>10, "query" => $params]);
- }
- public function findProducts($text = null) {
- $or_where = [];
- if(strlen($text) > 0) {
- array_push($or_where, ['name|bar_code', 'like', '%'.$text.'%']);
- }
- return $this
- ->where('is_delete', 0)
- ->where($or_where)
- ->page(1,10)
- ->select();
- }
- public function doesItExist($bar_code) {
- $customer = $this->where([
- ["bar_code", '=', $bar_code],
- ["is_delete", '=', 0]
- ])->find();
- return $customer ? true : false;
- }
- }
|