| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\common\model;
- class CustomerModel extends BaseModel
- {
- protected $table = 'erp_customer';
- // public function getSexAttr($value) {
- // return ['', '男', '女', '未知'][$value];
- // }
- public function doesItExist($mobile) {
- $customer = $this->where([
- ["mobile", '=',$mobile],
- ["is_delete", '=', 0],
- ])->find();
- return $customer ? true : false;
- }
- protected function genSchema(array $schema)
- {
- // TODO: Implement genSchema() method.
- }
- /**
- * @param array $params
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function findByPaginate(array $params) {
- $where = [
- ['is_delete', '=', 0]
- ];
- if(isset($params['name_zh']))
- array_push($where,['name_zh', 'like', "%".$params['name_zh']."%"]);
- if(isset($params['name_en']))
- array_push($where,['name_en', 'like', "%".$params['name_en']."%"]);
- if(isset($params['mobile']))
- array_push($where,['mobile', 'like', "%".$params['mobile']."%"]);
- return $this->where($where)
- ->order('create_time','desc')
- ->paginate(['list_rows'=>10, "query" => $params]);
- }
- public function findByName($name) {
- return $this->where([
- ['is_delete','=', 0],
- ['name_zh|name_en', '=', $name]
- ])->find();
- }
- public function findByMobile($mobile) {
- return $this->where([
- ['is_delete','=', 0],
- ['mobile', '=', $mobile]
- ])->find();
- }
- }
|