| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <?php
- namespace hd\controllers;
- use bizHd\admin\services\AdminService;
- use bizHd\custom\classes\CustomClass;
- use bizHd\custom\services\CustomService;
- use biz\sj\classes\MerchantExtendClass;
- use biz\sj\services\MerchantAssetService;
- use biz\sj\services\MerchantRemarkService;
- use bizHd\user\services\UserAssetService;
- use bizHd\user\services\UserGrowthService;
- use bizHd\user\services\UserService;
- use bizHd\user\services\UserUpgradeService;
- use common\components\wxUtil;
- 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;
- use bizHd\message\services\SmsService;
- use bizHd\user\classes\UserClass;
- use yii\helpers\Json;
- class UserController extends BaseController
- {
- public $guestAccess = ['my-profile', 'discount'];
- //客户列表 ssh 2019.11.30
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $search = isset($get['search']) ? $get['search'] : '';
- $where = ['sjId' => $this->sjId];
- if (!empty($search)) {
- if (stringUtil::isMobile($search)) {
- $where['mobile'] = $search;
- } else {
- $where['name'] = ['like', $search];
- }
- }
- $list = CustomService::getCustomList($where);
- util::success($list);
- }
- //获取客户基本和资产信息 ssh 2019.11.30
- public function actionDetail()
- {
- $userId = Yii::$app->request->get('userId');
- $info = UserService::getUserInfo($userId);
- if (isset($info['sjId']) == false || $this->sjId != $info['sjId']) {
- util::fail('没有权限');
- }
- util::success($info);
- }
- //获取客户详情,包括基本信息、资产、订单和备注 2019.11.30
- public function actionUserDetail()
- {
- $info = [
- 'id' => '12545132',
- 'mobile' => '15280215347',
- 'subscribe' => 1,
- 'sex' => 0,
- 'userName' => '慈善的人',
- 'address' => '',
- 'visitTimeFormat' => "今天 10:57",
- 'sourceType' => 0,
- 'userAsset' => [
- 'balance' => 0.00,
- 'totalBuyNum' => 1,
- 'totalExpend' => 3,
- 'growth' => 30,
- 'getCouponNum' => 3,
- 'inviteNum' => 1,
- 'discount' => 1.00
- ],
- 'remarkList' => [],
- 'orderList' => [
- [
- 'id' => 215360,
- 'createTime' => '2021-01-31 10:58:13',
- 'actPrice' => 20.9,
- 'payWay' => 0,
- 'sendNum' => '79',
- 'status' => 5,
- ]
- ],
- ];
- util::success($info);
- $userId = Yii::$app->request->get('userId');
- $info = UserService::getFullUserInfo($userId);
- UserService::valid($info, $this->sjId);
- $list = MerchantRemarkService::getRemarkList($userId);
- $info['remarkList'] = $list;
- util::success($info);
- }
- //添加客户,申请会员时会自动同步资产 ssh 2019.11.30
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- if (isset($post['mobile']) == false || stringUtil::isMobile($post['mobile']) == false) {
- util::fail('请输入手机号');
- }
- if ($post['mobile'] != $post['confirmMobile']) {
- util::fail('二次输入手机号不一样');
- }
- $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
- AdminService::verifyPayPassword($this->adminId, $payPassword);
- $mobile = $post['mobile'];
- $user = UserService::getByMobile($mobile, $this->sjId);
- if (!empty($user)) {
- util::fail('手机号已使用');
- }
- $post['sjId'] = $this->sjId;
- $post['member'] = $post['memberLevel'];
- UserService::addUser($post);
- util::complete();
- }
- //重置客户密码
- 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->sjId);
- UserService::updateById($userId, ['payPassword' => password_hash($password, PASSWORD_BCRYPT)]);
- util::complete();
- }
- //获取登陆客户的资产 ssh 2019.11.22
- public function actionAsset()
- {
- $asset = UserAssetService::getByUserId($this->adminId);
- util::success($asset);
- }
- //客户获取自己的优惠情况 ssh 2021.2.1
- public function actionDiscount()
- {
- $get = Yii::$app->request->get();
- $customId = $get['customId'] ?? 0;
- if (empty($customId)) {
- $customId = $this->customId;
- }
- if (empty($customId)) {
- util::fail('没有找到客户信息');
- }
- $info = CustomClass::getCustomInfo($customId);
- CustomClass::valid($info, $this->shopId);
- $level = $info['member'] ?? 0;
- $discount = $info['discount'] ?? 1;
- $discount = [
- 'member' => ['level' => $level, 'discount' => $discount],
- 'coupon' => [],
- ];
- util::success($discount);
- }
- //小程序用户完整信息 ssh 2019.12.12
- public function actionMiniFullInfo()
- {
- $post = Yii::$app->request->post();
- $iv = isset($post['iv']) ? $post['iv'] : '';
- $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
- $appId = $this->sj['miniAppId'];
- $sjId = $this->sjId;
- $miniOpenId = $this->user['miniOpenId'];
- if (empty($miniOpenId)) {
- util::fail('mini_open_id empty');
- }
- $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- Yii::info($result . ' ' . $errCode);
- util::fail('获取用户信息失败');
- }
- Yii::info('小程序获取用户信息:' . $result);
- $originalInfo = Json::decode($result);
- $source = UserClass::$userSourceId['mini']['name'];
- $user = UserService::replaceUser($originalInfo, $source, $sjId);
- $userId = $user['id'];
- $userInfo = UserService::getUserInfo($userId);
- util::success($userInfo);
- }
- //小程序用户手机号
- public function actionMiniMobile()
- {
- $post = Yii::$app->request->post();
- $iv = $post['iv'];
- $encryptedData = $post['encryptedData'];
- $sjId = $this->sjId;
- $merchant = $this->sj->attributes;
- $appId = $merchant['miniAppId'];
- $miniOpenId = $this->user['miniOpenId'];
- $user = $this->user;
- if (!empty($user) && !empty($user['mobile'])) {
- $userId = $user['id'];
- util::success(['mobile' => $user['mobile']]);
- }
- $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($sessionKey)) {
- util::fail('系统错误,sesstion empty');
- }
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- util::fail('解密失败');
- }
- $arr = Json::decode($result);
- $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
- if (empty($mobile)) {
- util::fail('没有获取手机号,请重试');
- }
- $userId = $user['id'];
- UserService::becomeMember($user, $merchant, ['mobile' => $mobile]);
- util::success(['mobile' => $mobile]);
- }
- //密码修改
- public function actionPassword()
- {
- $post = Yii::$app->request->post();
- $old = isset($post['old']) ? $post['old'] : '';
- $new = isset($post['new']) ? $post['new'] : '';
- $confirm = isset($post['confirm']) ? $post['confirm'] : '';
- if (empty($new)) {
- util::fail('请输入新密码');
- }
- if ($new != $confirm) {
- util::fail('二次密码不一致');
- }
- $userId = $this->adminId;
- $user = UserService::getUserInfo($userId);
- if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
- if (empty($old)) {
- util::fail('请填写旧密码');
- }
- if (password_verify($old, $user['payPassword']) == false) {
- util::fail('旧密码错误');
- }
- }
- UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
- util::complete('修改成功');
- }
- //申请会员 ssh 2019.12.18
- public function actionApplyMember()
- {
- $post = Yii::$app->request->post();
- $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
- if (stringUtil::isMobile($mobile) == false) {
- util::fail('请输入手机号');
- }
- $userId = $this->adminId;
- $asset = UserAssetService::getByUserId($userId);
- if (isset($asset['member']) && $asset['member'] != -1) {
- util::fail('已经是会员了');
- }
- $code = isset($post['code']) ? $post['code'] : '';
- $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
- if (empty($cacheCode) || $cacheCode != $code) {
- util::fail('验证码错误');
- }
- $update = [];
- if (isset($post['realName']) && !empty($post['realName'])) {
- $update['realName'] = $post['realName'];
- }
- if (isset($post['birthday']) && !empty($post['birthday'])) {
- $update['birthday'] = $post['birthday'];
- }
- $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]);
- if ($userId == $user['id']) {
- util::fail('手机号已验证');
- }
- if (!empty($user)) {
- util::fail('手机号已经注册过了');
- }
- $update['mobile'] = $mobile;
- UserService::becomeMember($this->user, $this->sj->attributes, $update);
- util::complete('注册成功');
- }
- //用户基本信息和资产 ssh 2019.12.19
- public function actionMyProfile()
- {
- $custom = $this->custom;
- $growth = 100;
- $id = $custom['id'] ?? 0;
- $name = $custom['name'] ?? '';
- $user = [
- 'id' => $id,
- 'userName' => $name,
- 'member' => 2,
- ];
- $nextLevelGrowth = MerchantExtendClass::getNextLevelGrowth($growth, $this->sjExtend);
- $user['userAsset'] = [
- 'nextLevelGrowth' => $nextLevelGrowth,
- 'growth' => 0,
- 'balance' => 0,
- 'member' => 2,
- 'discount' => 0.88
- ];
- util::success($user);
- }
- //登陆客户的信息 ssh 2020.3.12
- public function actionLoginDetail()
- {
- $user = $this->user;
- util::success($user);
- }
- }
|