CustomerModel.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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("mobile", $mobile)->find();
  11. return $customer ? true : false;
  12. }
  13. protected function genSchema(array $schema)
  14. {
  15. // TODO: Implement genSchema() method.
  16. }
  17. //for ($i = 2; $i< 10; $i++) {
  18. //$this->saveAll([
  19. //[
  20. //'name' => '佩佩'.$i,
  21. //'mobile' => '1557692025'.$i,
  22. //'sex'=> 1,
  23. //'sun_calendar' => '2020-'.$i.'-11',
  24. //'lunar_calendar' => '2020-'.($i-1).'-19',
  25. //'user_id' => 100000,
  26. //'username' => 'Caviar.',
  27. //'relation' => '朋友'.$i,
  28. //'address' => '巴西'.$i,
  29. //'email' => $i.'@163.com',
  30. //'store_id' => 1,
  31. //'linkman' => 'A_Caviar'
  32. //]
  33. //]);
  34. //}
  35. /**
  36. * @param array $params
  37. * @return \think\Paginator
  38. * @throws \think\db\exception\DbException
  39. */
  40. public function findCustomerPage(array $params) {
  41. $where = [
  42. 'is_delete' => 0
  43. ];
  44. if(isset($params['name'])) {
  45. array_push($where,['name', 'like', "%".$params['name']."%"]);
  46. }
  47. if(count($where) > 0) {
  48. return $this->where($where)->order('create_time','desc')->paginate(['list_rows'=>10, "query" => $params]);
  49. }
  50. return $this->order('create_time','desc')->paginate(['list_rows'=>10, "query" => $params]);
  51. }
  52. }