Ver Fonte

客户相关

shish há 5 anos atrás
pai
commit
9c2072fcf5
3 ficheiros alterados com 193 adições e 191 exclusões
  1. 178 190
      app/shop/controllers/UserController.php
  2. 12 0
      biz/custom/services/CustomService.php
  3. 3 1
      sql.sql

+ 178 - 190
app/shop/controllers/UserController.php

@@ -3,6 +3,7 @@
 namespace shop\controllers;
 
 use biz\admin\services\AdminService;
+use biz\custom\services\CustomService;
 use biz\merchant\services\MerchantAssetService;
 use biz\merchant\services\MerchantRemarkService;
 use biz\user\services\UserAssetService;
@@ -29,30 +30,17 @@ class UserController extends BaseController
     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->sjId];
-        switch ($type) {
-            case 1:
-                //粉丝
-                $where['subscribe'] = 1;
-                break;
-            case 2:
-                //会员
-                $where['member>'] = 0;
-                break;
-            default:
-        }
+        $where = ['sjId' => $this->sjId];
         if (!empty($search)) {
             if (stringUtil::isMobile($search)) {
                 $where['mobile'] = $search;
             } else {
-                $where['userName'] = ['like', $search];
+                $where['name'] = ['like', $search];
             }
         }
+        //$list = CustomService::getOldCustomList($where);
         $list = UserService::getUserList($where);
-        $list['asset'] = MerchantAssetService::getByMerchantId($this->sjId);
         util::success($list);
     }
 
@@ -239,179 +227,179 @@ class UserController extends BaseController
         UserService::updateById($userId, ['payPassword' => password_hash($password, PASSWORD_BCRYPT)]);
         util::complete();
     }
-	
-	//获取登陆客户的资产 shish 2019.11.22
-	public function actionAsset()
-	{
-		$asset = UserAssetService::getByUserId($this->adminId);
-		util::success($asset);
-	}
-	
-	//获取登陆客户的优惠情况  shish 2019.12.3
-	public function actionDiscount()
-	{
-		$discount = UserAssetService::getDiscount($this->adminId);
-		util::success($discount);
-	}
-	
-	//小程序用户完整信息 shish 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'];
-		$merchantId = $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, $merchantId);
-		$userId = $user['id'];
-		$userInfo = UserService::getUserInfo($userId);
-		util::success($userInfo);
-	}
-	
-	//小程序用户手机号
-	public function actionMiniMobile()
-	{
-		$post = Yii::$app->request->post();
-		$iv = $post['iv'];
-		$encryptedData = $post['encryptedData'];
-		$merchantId = $this->sjId;
-		$merchant = $this->sj;
-		$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, false);
-		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('修改成功');
-	}
-	
-	//申请会员 shish 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(['merchantId' => $this->sjId, 'mobile' => $mobile]);
-		if ($userId == $user['id']) {
-			util::fail('手机号已验证');
-		}
-		if (!empty($user)) {
-			util::fail('手机号已经注册过了');
-		}
-		$update['mobile'] = $mobile;
-		UserService::becomeMember($this->user, $this->sj, $update);
-		util::complete('注册成功');
-	}
-	
-	//用户基本信息和资产 shish 2019.12.19
-	public function actionMyProfile()
-	{
-		$user = UserService::getUserInfo($this->adminId);
-		$growth = $user['userAsset']['growth'];
-		$extend = $this->sjExtend;
-		$grade = MerchantExtendService::getGradeList($extend, 'asc');
-		//下个等级的积分
-		$nextLevelGrowth = 0;
-		foreach ($grade as $val) {
-			$currentGrowth = $val['growth'];
-			if ($currentGrowth > $growth) {
-				$nextLevelGrowth = $currentGrowth;
-				break;
-			}
-		}
-		$user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
-		util::success($user);
-	}
-	
-	//登陆客户的信息 shish 2020.3.12
-	public function actionLoginDetail()
-	{
-		$user = $this->user;
-		util::success($user);
-	}
+
+    //获取登陆客户的资产 shish 2019.11.22
+    public function actionAsset()
+    {
+        $asset = UserAssetService::getByUserId($this->adminId);
+        util::success($asset);
+    }
+
+    //获取登陆客户的优惠情况  shish 2019.12.3
+    public function actionDiscount()
+    {
+        $discount = UserAssetService::getDiscount($this->adminId);
+        util::success($discount);
+    }
+
+    //小程序用户完整信息 shish 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'];
+        $merchantId = $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, $merchantId);
+        $userId = $user['id'];
+        $userInfo = UserService::getUserInfo($userId);
+        util::success($userInfo);
+    }
+
+    //小程序用户手机号
+    public function actionMiniMobile()
+    {
+        $post = Yii::$app->request->post();
+        $iv = $post['iv'];
+        $encryptedData = $post['encryptedData'];
+        $merchantId = $this->sjId;
+        $merchant = $this->sj;
+        $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, false);
+        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('修改成功');
+    }
+
+    //申请会员 shish 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(['merchantId' => $this->sjId, 'mobile' => $mobile]);
+        if ($userId == $user['id']) {
+            util::fail('手机号已验证');
+        }
+        if (!empty($user)) {
+            util::fail('手机号已经注册过了');
+        }
+        $update['mobile'] = $mobile;
+        UserService::becomeMember($this->user, $this->sj, $update);
+        util::complete('注册成功');
+    }
+
+    //用户基本信息和资产 shish 2019.12.19
+    public function actionMyProfile()
+    {
+        $user = UserService::getUserInfo($this->adminId);
+        $growth = $user['userAsset']['growth'];
+        $extend = $this->sjExtend;
+        $grade = MerchantExtendService::getGradeList($extend, 'asc');
+        //下个等级的积分
+        $nextLevelGrowth = 0;
+        foreach ($grade as $val) {
+            $currentGrowth = $val['growth'];
+            if ($currentGrowth > $growth) {
+                $nextLevelGrowth = $currentGrowth;
+                break;
+            }
+        }
+        $user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
+        util::success($user);
+    }
+
+    //登陆客户的信息 shish 2020.3.12
+    public function actionLoginDetail()
+    {
+        $user = $this->user;
+        util::success($user);
+    }
 
 }

+ 12 - 0
biz/custom/services/CustomService.php

@@ -3,6 +3,7 @@
 namespace biz\custom\services;
 
 use biz\base\services\BaseService;
+use biz\custom\classes\CustomClass;
 use Yii;
 
 class CustomService extends BaseService
@@ -10,4 +11,15 @@ class CustomService extends BaseService
 
     public static $baseFile = '\biz\custom\classes\CustomClass';
 
+    //获取客户列表,兼容老项目使用,请勿再调用 shish 2021.1.30
+    public static function getOldCustomList($where)
+    {
+        $data = CustomClass::getList('*', $where, 'visitTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        return $data;
+    }
+
 }

+ 3 - 1
sql.sql

@@ -1060,4 +1060,6 @@ CREATE TABLE `xhCustom` (
   `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
   `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
   PRIMARY KEY (`id`)
-) COMMENT='客户表';
+) COMMENT='客户表';
+ALTER TABLE `xhCustom` ADD `mobile` VARCHAR(15) NOT NULL DEFAULT '0' COMMENT '手机号' AFTER `name`;
+ALTER TABLE xhCustom ADD `visitTime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后一次访问时间' AFTER `member`;