CustomerModel.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\common\model;
  3. class CustomerModel extends BaseModel
  4. {
  5. protected $table = 'erp_customer';
  6. // public function getSexAttr($value) {
  7. // return ['', '男', '女', '未知'][$value];
  8. // }
  9. public function doesItExist($mobile) {
  10. $customer = $this->where([
  11. ["mobile", '=',$mobile],
  12. ["is_delete", '=', 0],
  13. ])->find();
  14. return $customer ? true : false;
  15. }
  16. protected function genSchema(array $schema)
  17. {
  18. // TODO: Implement genSchema() method.
  19. }
  20. //for ($i = 2; $i< 10; $i++) {
  21. //$this->saveAll([
  22. //[
  23. //'name' => '佩佩'.$i,
  24. //'mobile' => '1557692025'.$i,
  25. //'sex'=> 1,
  26. //'sun_calendar' => '2020-'.$i.'-11',
  27. //'lunar_calendar' => '2020-'.($i-1).'-19',
  28. //'user_id' => 100000,
  29. //'username' => 'Caviar.',
  30. //'relation' => '朋友'.$i,
  31. //'address' => '巴西'.$i,
  32. //'email' => $i.'@163.com',
  33. //'store_id' => 1,
  34. //'linkman' => 'A_Caviar'
  35. //]
  36. //]);
  37. //}
  38. /**
  39. * @param array $params
  40. * @return \think\Paginator
  41. * @throws \think\db\exception\DbException
  42. */
  43. public function findByPaginate(array $params) {
  44. $where = [
  45. ['is_delete', '=', 0]
  46. ];
  47. if(isset($params['name_zh']))
  48. array_push($where,['name_zh', 'like', "%".$params['name_zh']."%"]);
  49. if(isset($params['name_en']))
  50. array_push($where,['name_en', 'like', "%".$params['name_en']."%"]);
  51. if(isset($params['mobile']))
  52. array_push($where,['mobile', 'like', "%".$params['mobile']."%"]);
  53. return $this->where($where)->order('create_time','desc')->paginate(['list_rows'=>10, "query" => $params]);
  54. }
  55. }