| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- namespace business\controllers;
- use biz\admin\services\AdminService;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantRemarkService;
- use biz\user\services\UserAssetService;
- use biz\user\services\UserIntegralService;
- use biz\user\services\UserService;
- use common\components\weixinUtil;
- use common\services\xhMerchantExtendService;
- use common\services\xhRechargeService;
- use common\services\xhTMessageService;
- use common\services\xhUserIntegralService;
- use Yii;
- use common\components\stringUtil;
- use common\components\util;
- class UserController extends BaseController
- {
-
- //客户列表 shish 2019.11.30
- public function actionList()
- {
- $get = Yii::$app->request->get();
- //组建where
- $type = isset($get['type']) ? $get['type'] : -1;
- $search = isset($get['search']) ? $get['search'] : '';
- $where = ['merchantId' => $this->merchantId];
- switch ($type) {
- case 1:
- //粉丝
- $where['subscribe'] = 1;
- break;
- case 2:
- //会员
- $where['member>'] = -1;
- break;
- default:
- }
- if (!empty($search)) {
- if (stringUtil::isMobile($search)) {
- $where['mobile'] = $search;
- } else {
- $where['userName'] = ['like', $search];
- }
- }
- $list = UserService::getUserList($where);
- $list['asset'] = $this->merchantAsset;
- util::success($list);
- }
-
- //获取客户基本和资产信息 shish 2019.11.30
- public function actionDetail()
- {
- $userId = Yii::$app->request->get('userId');
- $info = UserService::getUserInfo($userId);
- if (isset($info['merchantId']) == false || $this->merchantId != $info['merchantId']) {
- util::fail('没有权限');
- }
- util::success($info);
- }
-
- //获取客户详情,包括基本信息、资产、订单和备注 2019.11.30
- public function actionUserDetail()
- {
- $userId = Yii::$app->request->get('userId');
- $info = UserService::getFullUserInfo($userId);
- UserService::valid($info, $this->merchantId);
-
- $list = MerchantRemarkService::getRemarkList($userId);
- $info['remarkList'] = $list;
- util::success($info);
- }
-
- //添加客户,申请会员时会自动同步资产 shish 2019.11.30
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- if ($post['mobile'] != $post['confirmMobile']) {
- util::fail('二次输入手机号不一样');
- }
- $confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
- AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
-
- $mobile = $post['mobile'];
- $user = UserService::getByMobile($mobile, $this->merchantId);
- if (!empty($user)) {
- util::fail('手机号已使用,客户已存在');
- }
- $post['merchantId'] = $this->merchantId;
- $post['member'] = $post['memberLevel'];
- UserService::addUser($post);
- util::ok();
- }
-
- //充值 shish 2019.12.1
- public function actionRecharge()
- {
- $post = Yii::$app->request->post();
- $confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
- AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
-
- $userId = isset($post['userId']) ? $post['userId'] : 0;
- $rechargeAmount = isset($post['rechargeAmount']) ? $post['rechargeAmount'] : 1;
- $user = UserService::getById($userId);
- if (empty($user)) {
- util::fail('找不到客户');
- }
- if ($user['merchantId'] != $this->merchantId) {
- util::fail('您没有权限操作');
- }
- $userAsset = UserAssetService::getByUserId($userId);
- $totalBalance = $userAsset['balance'] + $rechargeAmount;
- $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
- $upData['balance'] = $totalBalance;
- $upData['totalRecharge'] = $totalRecharge;
- $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->merchant, $this->merchantExtend, $this->merchantAsset);
- if ($return['code'] == 'A0001') {
- util::ok();
- }
- util::fail();
- }
-
- //升级 shish 2019.12.1
- public function actionUpgrade()
- {
- $post = Yii::$app->request->post();
- $userId = isset($post['userId']) ? $post['userId'] : 0;
- $member = isset($post['member']) ? $post['member'] : 0;
- $user = UserService::getById($userId);
- if (empty($user)) {
- util::fail('客户不存在');
- }
- if ($user['merchantId'] != $this->merchantId) {
- util::fail('您没有权限操作');
- }
-
- $confirmPassword = $post['confirmPassword'];
- AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
-
- $grade = xhMerchantExtendService::getGradeList($this->merchantExtend, 'desc');
- $newLevelGrowth = $grade[$member]['growth'];//升级到当前级别需要的积分数
- $userAsset = UserAssetService::getByUserId($userId);//用户资产
- if ($userAsset['member'] != -1 && $userAsset['member'] >= $member) {
- util::fail('客户已经达到此级别了');
- }
-
- $now = time();
- $date = date("Y-m-d H:i", $now);
-
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
-
- $addGrowth = $newLevelGrowth - $userAsset['growth'];
- //升级后的成长值
- $upData['growth'] = $newLevelGrowth;
- $upData['member'] = $member;
- UserAssetService::updateByUserId($userId, $upData);
-
- $integralData = [
- 'userId' => $userId,
- 'userName' => $user['userName'],
- 'merchantId' => $this->merchantId,
- 'relateId' => '',
- 'integral' => $newLevelGrowth,
- 'num' => $addGrowth,
- 'io' => 1,
- 'payWay' => 4,
- 'alipayId' => '',
- 'event' => '店长操作升级',
- 'operatorId' => $userId,
- 'createTime' => $date,
- 'capitalType' => 0,
- 'addTime' => $now,
- ];
- //用户兑换型积分流水增加
- //xhUserIntegralService::add($integralData);
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail();
- }
- $allTM = xhTMessageService::getList($this->merchantId);
- $openId = isset($user['openId']) ? $user['openId'] : '';
- if (empty($openId)) {
- util::ok();
- }
- $shortTempId = 'OPENTM205211943';//升级通知
- if (isset($allTM[$shortTempId]) == false) {
- util::ok();
- }
- $tempId = $allTM[$shortTempId];
- $data = [
- "touser" => $openId, "template_id" => $tempId, "url" => '',
- "data" => [
- "first" => ["value" => "恭喜,您已经升为{$member}级会员。", "color" => "#173177"],
- "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
- "keyword2" => ["value" => $date, "color" => "#173177"],
- "remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
- ]];
- weixinUtil::sendTaskInform($data, $this->merchant);
- util::ok();
- }
-
- //重置客户密码
- public function actionResetPayPassword()
- {
- $post = Yii::$app->request->post();
- $userId = isset($post['userId']) ? $post['userId'] : 0;
- $password = isset($post['password']) ? $post['password'] : 0;
- $info = UserService::getById($userId);
- UserService::valid($info, $this->merchantId);
- UserService::updateById($userId, ['payPassword' => password_hash($password, PASSWORD_BCRYPT)]);
- util::ok();
- }
-
- }
|