Customer.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\service\CustomerService;
  4. use app\api\validate\AddCustomerValidate;
  5. use app\api\validate\LoginValidate;
  6. use app\common\model\CustomerModel;
  7. use app\Request;
  8. use think\App;
  9. class Customer extends \app\BaseController
  10. {
  11. private $service;
  12. public function __construct(App $app)
  13. {
  14. $this->service = new CustomerService();
  15. parent::__construct($app);
  16. }
  17. public function add(Request $request) {
  18. $params = (new AddCustomerValidate())->message([
  19. 'name_zh.require' => lang("The customer name_zh does not comply with the rule"),
  20. 'name_en.require' => lang("The customer name_en does not comply with the rule"),
  21. 'mobile.require' => lang("The mobile does not comply with the rule"),
  22. 'address.require' => lang("The address does not comply with the rule"),
  23. 'email.email' => lang("The email does not comply with the rule"),
  24. 'sex.require' => lang("The sex does not comply with the rule"),
  25. 'linkman.require' => lang("The linkman does not comply with the rule"),
  26. 'zue_coin.require' => lang("The zue_coin does not comply with the rule"),
  27. 'sun_calendar.require' => lang("The sun_calendar does not comply with the rule"),
  28. 'lunar_calendar.require' => lang("The lunar_calendar does not comply with the rule"),
  29. ])->requestBodyCheck($request);
  30. $res = $this->service->add($params);
  31. predicate($res->bool, $res->message);
  32. return $this->ok($res->data);
  33. }
  34. /**
  35. * @return \think\response\Json
  36. * @throws \app\exception\BaseException
  37. */
  38. public function getCustomer() {
  39. $params = $this->request->param();
  40. if(!isset($params['name']) && !isset($params['mobile']) && !isset($params['customer_id']))
  41. predicate(false, '搜索条件必须存在一个');
  42. $res = $this->service->getCustomer(
  43. isset($params['customer_id']) ? format_string($params['customer_id']) : null,
  44. isset($params['name']) ? format_string($params['name']) : null,
  45. isset($params['mobile']) ? format_string($params['mobile']) : null
  46. );
  47. predicate($res->bool, $res->message);
  48. return $this->ok($res->data);
  49. }
  50. }