| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\api\service;
- use app\BaseService;
- use app\common\model\AdminModel;
- use app\common\model\CustomerModel;
- use app\common\model\CustomerZueCoinModel;
- use app\common\model\StoreModel;
- use app\common\model\ZueCoinRecordModel;
- class CustomerService extends BaseService
- {
- private $customerModel;
- private $adminModel;
- private $storeModel;
- private $customerZueCoinModel;
- private $zueCoinRecordModel;
- public function __construct()
- {
- $this->customerModel = new CustomerModel();
- $this->adminModel = new AdminModel();
- $this->storeModel = new StoreModel();
- $this->customerZueCoinModel = new CustomerZueCoinModel();
- $this->zueCoinRecordModel = new ZueCoinRecordModel();
- }
- public function add(array $params) {
- $isExist = $this->customerModel->doesItExist($params['mobile']);
- if ($isExist)
- return $this->fail(lang("Fail to add. Data duplication"));
- if(isset($params['follow_user_id'])) {
- $follow_user = $this->adminModel->findById($params['follow_user_id']);
- if (!$follow_user)
- return $this->fail(lang("The employees dont exist"));
- $params['follow_username'] = $follow_user->nickname;
- }
- if(isset($params['store_id'])) {
- $store = $this->storeModel->findById($params['store_id']);
- if(!$store)
- return $this->fail(lang("Stores do not exist"));
- $params['store_abbr'] = $store->abbr;
- }
- $params['create_user_id'] =$params['admin_id'];
- $params['create_username'] = $params['admin_name'];
- $params['create_time'] = time();
- $params['update_time'] = time();
- $customer = $this->customerModel->create($params);
- if(isset($params['zue_coin']) && $params['zue_coin'] > 0) {
- if (!isset($params['lose_time']))
- return $this->fail(lang("Please enter the Zue Coin expiration time"));
- $zueCoin = $this->customerZueCoinModel->create([
- 'customer_id' => $customer->id,
- 'zue_coin' => $params['zue_coin'],
- 'lose_time' => strtotime($params['lose_time']),
- 'create_time' => time(),
- 'update_time' => time()
- ]);
- $this->zueCoinRecordModel->save([
- 'zue_coin_id' => $zueCoin->id,
- 'origin' => 0,
- 'change' => $params['zue_coin'],
- 'after' => $params['zue_coin'],
- 'reason' => 2,
- 'create_time' => time(),
- 'update_time' => time()
- ]);
- $customer['zue_coin'] = $zueCoin;
- }
- return $this->ok($customer->id);
- }
- }
|