| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\api\controller;
- use app\api\service\CustomerService;
- use app\api\validate\AddCustomerValidate;
- use app\api\validate\LoginValidate;
- use app\common\model\CustomerModel;
- use app\Request;
- use think\App;
- class Customer extends \app\BaseController
- {
- private $service;
- public function __construct(App $app)
- {
- $this->service = new CustomerService();
- parent::__construct($app);
- }
- public function add(Request $request) {
- $params = (new AddCustomerValidate())->message([
- 'name_zh.require' => lang("The customer name_zh does not comply with the rule"),
- 'name_en.require' => lang("The customer name_en does not comply with the rule"),
- 'mobile.require' => lang("The mobile does not comply with the rule"),
- 'address.require' => lang("The address does not comply with the rule"),
- 'email.email' => lang("The email does not comply with the rule"),
- 'sex.require' => lang("The sex does not comply with the rule"),
- 'linkman.require' => lang("The linkman does not comply with the rule"),
- 'zue_coin.require' => lang("The zue_coin does not comply with the rule"),
- 'sun_calendar.require' => lang("The sun_calendar does not comply with the rule"),
- 'lunar_calendar.require' => lang("The lunar_calendar does not comply with the rule"),
- ])->requestBodyCheck($request);
- $res = $this->service->add($params);
- predicate($res->bool, $res->message);
- return $this->ok($res->data);
- }
- /**
- * @return \think\response\Json
- * @throws \app\exception\BaseException
- */
- public function getCustomer() {
- $params = $this->request->param();
- if(!isset($params['name']) && !isset($params['mobile']) && !isset($params['customer_id']))
- predicate(false, '搜索条件必须存在一个');
- $res = $this->service->getCustomer(
- isset($params['customer_id']) ? format_string($params['customer_id']) : null,
- isset($params['name']) ? format_string($params['name']) : null,
- isset($params['mobile']) ? format_string($params['mobile']) : null
- );
- predicate($res->bool, $res->message);
- return $this->ok($res->data);
- }
- public function search() {
- $params = $this->request->param();
- predicate(isset($params['store_id']) && $params['store_id'] > 0, 'store_id err');
- return $this->ok($this->service->search(
- $params['admin_id'],
- $params['store_id'],
- isset($params['text']) ? format_string($params['text']) : null
- ));
- }
- }
|