瀏覽代碼

添加客户OK

shish 6 年之前
父節點
當前提交
c5575d096a

+ 14 - 3
app/business/controllers/UserController.php

@@ -3,8 +3,11 @@
 namespace business\controllers;
 
 use biz\admin\services\AdminService;
+use biz\merchant\services\MerchantExtendService;
 use biz\user\services\UserAssetService;
+use biz\user\services\UserIntegralService;
 use biz\user\services\UserService;
+use common\services\xhMerchantExtendService;
 use Yii;
 use common\components\stringUtil;
 use common\components\util;
@@ -91,14 +94,22 @@ class UserController extends BaseController
 		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
 		$source = $userSource['name'];
 		$user = UserService::replaceUser($originalInfo, $source, $merchantId);
+		
+		//等级
+		$memberLevel = isset($post['memberLevel']) ? $post['memberLevel'] : 0;
+		$extend = MerchantExtendService::getByMerchantId($this->merchantId);
+		$gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
+		$growth = isset($gradeList[$memberLevel]['growth']) ? $gradeList[$memberLevel]['growth'] : 0;
 
+		//余额成长值更新
 		$userId = $user['id'];
 		$balance = isset($post['balance']) && is_numeric($post['balance']) ? $post['balance'] : 0;
-		$memberLevel = isset($post['memberLevel']) && is_numeric($post['memberLevel']) ? $post['memberLevel'] : 0;
-		$data = ['balance' => $balance, 'memberLevel' => $memberLevel];
+		$data = ['balance' => $balance,'growth'=>$growth];
 		UserAssetService::updateByUserId($userId, $data);
 
+		//会员升级
+		UserIntegralService::increaseToUpgrade(0, $growth, 0, $userId, $merchantId, $extend);
 		util::ok();
 	}
-
+	
 }

+ 8 - 0
app/business/web/index.php

@@ -15,5 +15,13 @@ $config = yii\helpers\ArrayHelper::merge(
     require(__DIR__ . '/../config/main-local.php')
 );
 
+//调用使用的输出方法
+function dd($out)
+{
+	echo '<pre>';
+	print_r($out);
+	Yii::$app->end();
+}
+
 $application = new yii\web\Application($config);
 $application->run();

+ 22 - 0
biz/merchant/services/MerchantExtendService.php

@@ -4,6 +4,7 @@ namespace biz\merchant\services;
 
 use biz\base\services\BaseService;
 use biz\merchant\classes\MerchantExtendClass;
+use common\components\arrayUtil;
 use Yii;
 
 class MerchantExtendService extends BaseService
@@ -16,4 +17,25 @@ class MerchantExtendService extends BaseService
 		return MerchantExtendClass::getByMerchantId($id, $returnType);
 	}
 	
+	//积分等级列表 shish 2019.12.1
+	public static function getGradeList($extend, $order = 'asc')
+	{
+		$gradeStr = $extend['gradeList'];
+		$data = [];
+		if (!empty($gradeStr)) {
+			$arr = explode("I", $gradeStr);
+			$arr = array_filter($arr);
+			foreach ($arr as $key => $val) {
+				$son = explode("_", $val);
+				$discount = $son[2];
+				if (strlen($discount) == 1) {
+					$discount .= '0';
+				}
+				$data[$son[0]] = ['level' => $son[0], 'growth' => $son[1], 'discount' => $discount];
+			}
+		}
+		$data = arrayUtil::sort($data, 'level', $order);
+		return $data;
+	}
+	
 }

+ 1 - 2
biz/user/models/UserAsset.php

@@ -18,7 +18,7 @@ class UserAsset extends Base
 	public function rules()
 	{
 		return [
-			[['userId', 'merchantId', 'totalBuyNum', 'integral', 'point', 'discount', 'isMember', 'memberLevel'], 'integer'],
+			[['userId', 'merchantId', 'totalBuyNum', 'integral', 'discount', 'isMember', 'memberLevel'], 'integer'],
 			[['totalExpend', 'totalIncome', 'totalRecharge', 'balance'], 'number'],
 			[['createTime'], 'required'],
 			[['createTime', 'updateTime'], 'safe'],
@@ -41,7 +41,6 @@ class UserAsset extends Base
 			'totalBuyNum' => 'Total Buy Num',
 			'balance' => 'Balance',
 			'integral' => 'Integral',
-			'point' => 'Point',
 			'discount' => 'Discount',
 			'isMember' => 'Is Member',
 			'memberLevel' => 'Member Level',

+ 6 - 35
biz/user/services/UserAssetService.php

@@ -3,7 +3,11 @@
 namespace biz\user\services;
 
 use biz\base\services\BaseService;
+use biz\merchant\services\MerchantExtendService;
+use biz\merchant\services\MerchantService;
 use biz\user\classes\UserAssetClass;
+use common\components\weixinUtil;
+use common\services\xhTMessageService;
 use Yii;
 
 class UserAssetService extends BaseService
@@ -22,7 +26,7 @@ class UserAssetService extends BaseService
 	{
 		return UserAssetClass::getByUserIds($ids, $indexBy);
 	}
-
+	
 	public static function updateByUserId($userId, $data)
 	{
 		self::updateByCondition(['userId' => $userId], $data);
@@ -37,38 +41,5 @@ class UserAssetService extends BaseService
 		}
 		return true;
 	}
-	
-	/**
-	 * 是否还可以领取优惠卷 -1否 0可领首次的 1可领二次的 2可领三次
-	 * $payCallback false 表示支付回调的流程没执行完,消费次数还没加上,但我要确认是否能领卷,所以先手动加上
-	 */
-	public static function couldGetCoupon($userId, $payCallback = true)
-	{
-		//暂时关闭领卷功能 shish 2019.10.5
-		return -1;
-		/**商家是否开通领卷功能**/
-		$asset = self::getByUserId($userId);
-		$getCouponNum = isset($asset['getCouponNum']) ? $asset['getCouponNum'] : 0;
-		$totalBuyNum = isset($asset['totalBuyNum']) ? $asset['totalBuyNum'] : 0;
-		if ($payCallback == false) {
-			$totalBuyNum++;
-		}
-		$num = (int)$getCouponNum + (int)$totalBuyNum;
-		if ($num == 0) {
-			//没有消费过并且没有领过优惠券,发首次卷
-			$flag = 0;
-		} elseif ($num == 1) {
-			//消费过一次或领过一次卷,发二次卷
-			$flag = 1;
-		} elseif ($totalBuyNum == 2 || $num == 3) {
-			//消费过二次(包括还领过一次卷)发三次卷
-			$flag = 2;
-		} else {
-			//其它情况没有卷可以领取
-			$flag = -1;
-		}
-		Yii::info('getCouponNum:' . $getCouponNum . ' totalBuyNum:' . $totalBuyNum . ' flag:' . $flag);
-		return $flag;
-	}
-	
+
 }

+ 38 - 33
biz/user/services/UserIntegralService.php

@@ -4,63 +4,68 @@ namespace biz\user\services;
 
 
 use biz\base\services\BaseService;
-use common\components\util;
-
+use biz\merchant\services\MerchantService;
 use common\services\xhMerchantExtendService;
 use common\services\xhTMessageService;
 use common\services\xhUserAssetService;
 use common\services\xhUserService;
 use Yii;
-use linslin\yii2\curl;
-use common\components\stringUtil;
-use common\components\configDict;
 use common\components\weixinUtil;
-use common\models\xhUser;
+
 
 class UserIntegralService extends BaseService
 {
-	/**
-	 * 增加积分并升级
-	 */
-	public static function increaseToUpgrade($preIntegral, $integral, $preLevel, $userId, $merchantId, $merchantExtend)
+	
+	//增加成长值引导等级增加 shish 2019.12.1
+	public static function increaseToUpgrade($preGrowth, $growth, $preLevel, $userId, $merchantId, $merchantExtend)
 	{
-		if ($integral <= $preIntegral) {
+		if ($growth <= $preGrowth) {
 			return ['status' => false, 'msg' => '没有增加积分'];
 		}
-		$gradeList = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');//获取会员积分等级关系
+		//获取会员积分等级关系
+		$gradeList = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
 		if (empty($gradeList)) {
 			return ['status' => false, 'msg' => '没有会员等级信息'];
 		}
 		$gainLevel = 0;
 		$gainDiscount = 0;
 		foreach ($gradeList as $key => $val) {
-			$gradeLevel = (int)$val['level'];
-			$gradePoint = (int)$val['integral'];
+			$currentLevel = (int)$val['level'];
+			$currentGrowth = (int)$val['growth'];
 			$gradeDiscount = $val['discount'];
-			if ($integral >= $gradePoint && $preLevel < $gradeLevel) {
-				$gainLevel = $gradeLevel;
+			if ($growth >= $currentGrowth && $preLevel < $currentLevel) {
+				$gainLevel = $currentLevel;
 				$gainDiscount = $gradeDiscount;
 				break;
 			}
 		}
-		if (!empty($gainLevel)) {//会员积分达到新等级
-			xhUserService::updateById($userId, ['isMember' => 1]);
-			xhUserAssetService::updateByUserId($userId, ['memberLevel' => $gradeLevel, 'isMember' => 1]);
-			
-			$allTM = xhTMessageService::getList($merchantId);//积分变动通知
-			$shortTempId = 'OPENTM205211943';
-			if (isset($allTM[$shortTempId])) {
-				$tempId =  $allTM[$shortTempId];
-				$tmData = ["touser" => $openId, "template_id" => $tempId,
-					"url" => Yii::$app->params['frontUrl'] . '/center/right?account=' . $merchant['id'],
-					"data" => [
-						"first" => ["value" => "恭喜,您已升为{$gainLevel}级会员。购物享{$gainDiscount}折优惠", "color" => "#173177"],
-						"keyword1" => ["value" => $user['userName'], "color" => "#173177"],
-						"keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
-						"remark" => ["value" => "祝您生活愉快!", "color" => "#173177"],],];
-				//weixinUtil::sendTaskInform($tmData, $merchant);
-			}
+		if (empty($gainLevel)) {//会员积分达到新等级
+			return ['status' => false, 'msg' => '没有升级'];
+		}
+		xhUserService::updateById($userId, ['isMember' => 1]);
+		xhUserAssetService::updateByUserId($userId, ['memberLevel' => $gainLevel, 'isMember' => 1]);
+
+		$allTM = xhTMessageService::getList($merchantId);//积分变动通知
+		$shortTempId = 'OPENTM205211943';
+		if (isset($allTM[$shortTempId]) == false) {
+			return ['status' => false, 'msg' => '已升级未通知,没有找到消息系统'];
+		}
+		$merchant = MerchantService::getBYId($merchantId);
+		$user = UserService::getById($userId);
+		$openId = isset($user['openId']) ? $user['openId'] : '';
+		if (empty($openId)) {
+			return ['status' => false, 'msg' => '已升级未通知,客户信息不完整'];
 		}
+		$tempId = $allTM[$shortTempId];
+		$tmData = ["touser" => $openId, "template_id" => $tempId,
+			"url" => Yii::$app->params['frontUrl'] . '/center/right?account=' . $merchant['id'],
+			"data" => [
+				"first" => ["value" => "恭喜,您已升为{$gainLevel}级会员。购物享{$gainDiscount}折优惠", "color" => "#173177"],
+				"keyword1" => ["value" => $user['userName'], "color" => "#173177"],
+				"keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
+				"remark" => ["value" => "祝您生活愉快!", "color" => "#173177"],],];
+		weixinUtil::sendTaskInform($tmData, $merchant);
 		
 	}
+	
 }

+ 2 - 6
common/components/weixinUtil.php

@@ -184,7 +184,7 @@ class weixinUtil
 		$result = $curl->get($url);
 		$result = Json::decode($result);
 		if (isset($result['errcode'])) {
-			//TODO 异常
+		
 		} else {
 			return $result;
 		}
@@ -439,10 +439,7 @@ class weixinUtil
 		return $response;
 	}
 	
-	/**
-	 * 微信api不支持中文转义的json结构
-	 * @param array $arr
-	 */
+	//微信api不支持中文转义的json结构
 	static function json_encode($arr)
 	{
 		if (count($arr) == 0) return "[]";
@@ -479,7 +476,6 @@ class weixinUtil
 					$str .= 'true';
 				else
 					$str .= '"' . addslashes($value) . '"'; //All other things
-				// :TODO: Is there any more datatype we should be in the lookout for? (Object?)
 				$parts [] = $str;
 			}
 		}

+ 1 - 1
common/services/xhMerchantExtendService.php

@@ -68,7 +68,7 @@ class xhMerchantExtendService
 				if (strlen($discount) == 1) {
 					$discount .= '0';
 				}
-				$data[$son[0]] = ['level' => $son[0], 'integral' => $son[1], 'discount' => $discount];
+				$data[$son[0]] = ['level' => $son[0], 'growth' => $son[1], 'discount' => $discount];
 			}
 		}
 		$data = arrayUtil::sort($data, 'level', $order);

+ 0 - 10
common/services/xhUserAssetService.php

@@ -21,16 +21,6 @@ class xhUserAssetService {
 	public static function updateByUserId($userId,$data)
 	{
 		xhUserAsset::updateByCondition(['userId' => $userId], $data);
-		self::getByUserId($userId);
-		$cacheKey			= configDict::getCacheKey('xhUserAsset').$userId;
-		$params				= [$cacheKey];
-		if(!empty($data)){
-			foreach($data as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-			Yii::$app->redis->executeCommand('HMSET',$params);
-		}
 	}
 
 	public static function add($userId,$data)

+ 1 - 0
sql.txt

@@ -5,6 +5,7 @@ ALTER TABLE xhUserAsset MODIFY `integral` INT NOT NULL DEFAULT 0 COMMENT '积分
 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;
 
 shish 2019.11.30
 ALTER TABLE xhGoods DROP COLUMN `multiPrice`;