Browse Source

升级接口可以了

shish 6 năm trước cách đây
mục cha
commit
c0fe529c1b
3 tập tin đã thay đổi với 95 bổ sung12 xóa
  1. 90 9
      app/business/controllers/UserController.php
  2. 3 3
      biz/admin/services/AdminService.php
  3. 2 0
      sql.txt

+ 90 - 9
app/business/controllers/UserController.php

@@ -7,8 +7,11 @@ use biz\merchant\services\MerchantExtendService;
 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;
@@ -78,10 +81,8 @@ class UserController extends BaseController
 			util::fail('二次输入手机号不一样');
 		}
 		$confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
-		$verify = AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
-		if ($verify == false) {
-			util::fail('密码错误');
-		}
+		AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
+		
 		$mobile = $post['mobile'];
 		$user = UserService::getByMobile($mobile);
 		if (!empty($user)) {
@@ -118,10 +119,8 @@ class UserController extends BaseController
 	{
 		$post = Yii::$app->request->post();
 		$confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
-		$verify = AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
-		if ($verify == false) {
-			util::fail('密码错误');
-		}
+		AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
+		
 		$userId = isset($post['userId']) ? $post['userId'] : 0;
 		$rechargeAmount = isset($post['rechargeAmount']) ? $post['rechargeAmount'] : 1;
 		$user = UserService::getById($userId);
@@ -142,5 +141,87 @@ class UserController extends BaseController
 		}
 		util::fail();
 	}
-
+	
+	//升级 shish 2019.12.1
+	public function actionUpgrade()
+	{
+		$post = Yii::$app->request->post();
+		$userId = isset($post['userId']) ? $post['userId'] : 0;
+		$memberLevel = isset($post['memberLevel']) ? $post['memberLevel'] : 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[$memberLevel]['growth'];//升级到当前级别需要的积分数
+		$userAsset = UserAssetService::getByUserId($userId);//用户资产
+		if (!empty($userAsset['isMember']) && $userAsset['memberLevel'] >= $memberLevel) {
+			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['memberLevel'] = $memberLevel;
+			$upData['isMember'] = 1;
+			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" => "恭喜,您已经升为{$memberLevel}级会员。", "color" => "#173177"],
+				"keyword1" => ["value" => $user['userName'], "color" => "#173177"],
+				"keyword2" => ["value" => $date, "color" => "#173177"],
+				"remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
+			]];
+		weixinUtil::sendTaskInform($data, $this->merchant);
+		util::ok();
+	}
+	
 }

+ 3 - 3
biz/admin/services/AdminService.php

@@ -8,6 +8,7 @@ use biz\base\services\BaseService;
 use biz\merchant\services\MerchantService;
 use common\components\error;
 use common\components\stringUtil;
+use common\components\util;
 use common\services\xhTMessageService;
 use Yii;
 
@@ -25,10 +26,9 @@ class AdminService extends BaseService
 	{
 		$admin = AdminClass::getById($adminId);
 		$hash = isset($admin['confirmPassword']) ? $admin['confirmPassword'] : '';
-		if (password_verify($password, $hash)) {
-			return true;
+		if (password_verify($password, $hash) == false) {
+			util::fail('密码错误');
 		}
-		return false;
 	}
 	
 	//发送到手机上 shish 2019.8.11

+ 2 - 0
sql.txt

@@ -6,6 +6,8 @@ ALTER TABLE xhUser MODIFY birthday DATE NOT NULL DEFAULT '0000-00-00' COMMENT '
 ALTER TABLE xhUserAsset DROP COLUMN `uniqueQrCode`;
 ALTER TABLE xhUserAsset DROP COLUMN `uniqueCode`;
 ALTER TABLE xhMerchantExtend ADD gradeSwitch TINYINT NOT NULL DEFAULT 1 COMMENT '会员等级修改开关 0不可再修改 1可修改' AFTER gradeList;
+DROP TABLE IF EXISTS `xhUserOldData`;
+!!!!!!老客户没给国兰导进来的要导进来客户表里
 
 shish 2019.11.30
 ALTER TABLE xhGoods DROP COLUMN `multiPrice`;