Sfoglia il codice sorgente

充值可以推送消息

shish 6 anni fa
parent
commit
ec4c41a79f

+ 10 - 0
app/business/controllers/BaseController.php

@@ -7,6 +7,8 @@ use biz\auth\services\MenuService;
 use biz\goods\services\CategoryRelateService;
 use biz\goods\services\UsageRelationService;
 use biz\merchant\services\AdminService;
+use biz\merchant\services\MerchantAssetService;
+use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
 use common\components\error;
 use common\components\jwt;
@@ -60,12 +62,20 @@ class BaseController extends PublicController
 			util::fail('没有找到商家信息');
 		}
 		$merchant = MerchantService::getById($merchantId);
+		$merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
+		$merchantAsset = MerchantAssetService::getByMerchantId($merchantId);
 		Yii::$app->params['adminId'] = $adminId;
 		Yii::$app->params['admin'] = $admin;
 		Yii::$app->params['merchantId'] = $merchantId;
 		Yii::$app->params['merchant'] = $merchant;
+		Yii::$app->params['merchant'] = $merchant;
+		Yii::$app->params['merchantAsset'] = $merchantAsset;
+		Yii::$app->params['merchantExtend'] = $merchantExtend;
 		$this->adminId = $adminId;
 		$this->merchantId = $merchantId;
+		$this->merchant = $merchant;
+		$this->merchantExtend = $merchantExtend;
+		$this->merchantAsset = $merchantAsset;
 		return parent::beforeAction($action);
 	}
 	

+ 1 - 1
common/services/xhRechargeService.php

@@ -151,7 +151,7 @@ class xhRechargeService
 			$totalBalance = stringUtil::calcAdd($userAsset['balance'], $rechargeAmount);
 			$totalRecharge = stringUtil::calcAdd($userAsset['totalRecharge'], $rechargeAmount);
 			$merchantTotalRecharge = stringUtil::calcAdd($merchantAsset['totalRecharge'], $rechargeAmount);
-			
+
 			$rechargeData = [
 				'id' => stringUtil::generateOrderNo($merchantId, $userId),
 				'payWay' => $payWay,

+ 107 - 102
common/services/xhUserAssetService.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace common\services;
+
 use biz\user\services\UserIntegralService;
 use common\models\xhActive;
 use Yii;
@@ -8,8 +10,9 @@ use common\components\stringUtil;
 use common\components\weixinUtil;
 use common\models\xhUserAsset;
 
-class xhUserAssetService {
-
+class xhUserAssetService
+{
+	
 	/**
 	 * 获取用户资产信息
 	 */
@@ -17,144 +20,146 @@ class xhUserAssetService {
 	{
 		return xhUserAsset::find()->where(['userId' => $userId])->asArray()->one();
 	}
-
-	public static function updateByUserId($userId,$data)
+	
+	public static function updateByUserId($userId, $data)
 	{
 		xhUserAsset::updateByCondition(['userId' => $userId], $data);
 	}
-
-	public static function add($userId,$data)
+	
+	public static function add($userId, $data)
 	{
-		$user	= xhUserAsset::add($data);
+		$user = xhUserAsset::add($data);
 		self::getByUserId($userId);
 		return $user;
 	}
-
+	
 	/**
 	 * 用户资金变化增加积分
 	 * 充值、微信付款、余额付款等改变用户资产
 	 * 此方法用于资金增减并引起积分增加,会员等级升级
 	 */
-	public static function ioChangeAsset($user, $userAsset,$upAssetData,$merchant,$merchantExtend, $order, $capitalType)
+	public static function ioChangeAsset($user, $userAsset, $upAssetData, $merchant, $merchantExtend, $order, $capitalType)
 	{
-		$userId							= $user['id'];
-		$merchantId						= $merchant['id'];
-		$orderId						= $order['id'];
-		$openId							= $user['openId'];
-		$integral						= isset($upAssetData['integral']) ? $upAssetData['integral'] : 0;
-		$preLevel						= $userAsset['memberLevel'];
-		$preIntegral					= $userAsset['integral'];
-		$addIntegral					= stringUtil::calcSub($integral, $preIntegral);
+		$userId = $user['id'];
+		$merchantId = $merchant['id'];
+		$orderId = $order['id'];
+		$openId = $user['openId'];
+		$integral = isset($upAssetData['integral']) ? $upAssetData['integral'] : 0;
+		$preLevel = $userAsset['memberLevel'];
+		$preIntegral = $userAsset['integral'];
+		$addIntegral = stringUtil::calcSub($integral, $preIntegral);
 
+		$allTM = xhTMessageService::getList($merchantId);
+		
 		//没有积分,后续升级流程不需要再走
-		if(empty($integral)){
+		if (empty($integral)) {
 			self::updateByUserId($userId, $upAssetData);
 			return;
 		}
-		$typeList						= configDict::getConfig('capitalType');//充值支付涉及的流水类型列表
-		switch($capitalType){//根据流水类型定制通知内容
-
+		$typeList = configDict::getConfig('capitalType');//充值支付涉及的流水类型列表
+		switch ($capitalType) {//根据流水类型定制通知内容
+			
 			case $typeList['xhOrder']['id']://购买商品
-				$goodsNum				= $order['goodsNum'];
-				$totalFee				= $order['actPrice'];
-				$name					= $order['orderName'];
-				$sourceType				= $order['sourceType'];
-				if($sourceType == 0){
-					$shortTempId			= 'OPENTM202297555';//下单成功通知
-					$tempId					= $allTM[$shortTempId];
+				$goodsNum = $order['goodsNum'];
+				$totalFee = $order['actPrice'];
+				$name = $order['orderName'];
+				$sourceType = $order['sourceType'];
+				if ($sourceType == 0) {
+					$shortTempId = 'OPENTM202297555';//下单成功通知
+					$tempId = $allTM[$shortTempId];
 					$data = [
 						"touser" => $openId,
 						"template_id" => $tempId,
-						"url" => Yii::$app->params['frontUrl']."/center/order-detail?id=$orderId&account=".$merchant['id'],
+						"url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=$orderId&account=" . $merchant['id'],
 						"data" => [
-						"first" => ["value" => '亲,您已成功下单!',"color" => "#173177"],
-						"keyword1" => ["value" => (string)$orderId,"color" => "#173177"],
-						"keyword2" => ["value" => $name,"color" => "#173177"],
-						"keyword3" => ["value" => $goodsNum.'件',"color" => "#173177"],
-						"keyword4" => ["value" => number_format($totalFee,2).'元',"color" => "#173177"],
-						"keyword5" => ["value" => '微信支付',"color" => "#173177"],
-						"remark" => ["value" => "","color" => "#173177"]]];
-					weixinUtil::sendTaskInform($data,$merchant);
-				}else{
-					if($addIntegral > 0){
-						$shortTempId				= 'TM00230';
-						$tempId						= $allTM[$shortTempId];
-						$changeData					= ["touser" => $openId,"template_id" => $tempId,
-							"url" => Yii::$app->params['frontUrl']."/center/order-detail?id=$orderId&account=".$merchant['id'],
+							"first" => ["value" => '亲,您已成功下单!', "color" => "#173177"],
+							"keyword1" => ["value" => (string)$orderId, "color" => "#173177"],
+							"keyword2" => ["value" => $name, "color" => "#173177"],
+							"keyword3" => ["value" => $goodsNum . '件', "color" => "#173177"],
+							"keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
+							"keyword5" => ["value" => '微信支付', "color" => "#173177"],
+							"remark" => ["value" => "", "color" => "#173177"]]];
+					weixinUtil::sendTaskInform($data, $merchant);
+				} else {
+					if ($addIntegral > 0) {
+						$shortTempId = 'TM00230';
+						$tempId = $allTM[$shortTempId];
+						$changeData = ["touser" => $openId, "template_id" => $tempId,
+							"url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=$orderId&account=" . $merchant['id'],
 							"data" => [
-							"first"		=> ["value" => "您在本店购物获得积分","color" => "#173177"],
-							"FieldName" => ["value" => "会员名称","color" => "#0F0F0F"],
-							"Account" => ["value" => $user['userName'],"color" => "#173177"],
-							"change"	=> ["value" => "增加","color" => "#0F0F0F"],
-							"CreditChange"	=> ["value" => $addIntegral,"color" => "#173177"],
-							"CreditTotal"	=> ["value" => $integral,"color" => "#173177"],
-							"Remark"	=> ["value" => "点此查看订单明细、添加编辑收花人信息","color" => "#173177"],],];
-						weixinUtil::sendTaskInform($changeData,$merchant);
+								"first" => ["value" => "您在本店购物获得积分", "color" => "#173177"],
+								"FieldName" => ["value" => "会员名称", "color" => "#0F0F0F"],
+								"Account" => ["value" => $user['userName'], "color" => "#173177"],
+								"change" => ["value" => "增加", "color" => "#0F0F0F"],
+								"CreditChange" => ["value" => $addIntegral, "color" => "#173177"],
+								"CreditTotal" => ["value" => $integral, "color" => "#173177"],
+								"Remark" => ["value" => "点此查看订单明细、添加编辑收花人信息", "color" => "#173177"],],];
+						weixinUtil::sendTaskInform($changeData, $merchant);
 					}
 				}
 				break;
-
+			
 			case $typeList['xhActiveOrder']['id']://活动报名
-
-				$activeId					= $order['activeId'];
-				$active						= xhActiveService::getById($activeId);
-				$newApplyNum				= $active['applyNum'] + 1;//活动报名人数+1
-				xhActiveService::updateById($activeId, ['applyNum'=>$newApplyNum]);
-				$shortTempId				= 'TM00575';//报名成功通知
-				$tempId						= $allTM[$shortTempId];
-				$changeData					= ["touser" => $openId,"template_id" => $tempId,
-					"url" => Yii::$app->params['frontUrl'].'/active/order?id='.$orderId.'&account='.$merchant['id'],
+				
+				$activeId = $order['activeId'];
+				$active = xhActiveService::getById($activeId);
+				$newApplyNum = $active['applyNum'] + 1;//活动报名人数+1
+				xhActiveService::updateById($activeId, ['applyNum' => $newApplyNum]);
+				$shortTempId = 'TM00575';//报名成功通知
+				$tempId = $allTM[$shortTempId];
+				$changeData = ["touser" => $openId, "template_id" => $tempId,
+					"url" => Yii::$app->params['frontUrl'] . '/active/order?id=' . $orderId . '&account=' . $merchant['id'],
 					"data" => [
-					"first"		=> ["value" => "您好,您已报名成功","color" => "#173177"],
-					"keynote1" => ["value" => $active['title'],"color" => "#173177"],
-					"keynote2" => ["value" => date("m-d H:i",$active['startTime']),"color" => "#173177"],
-					"keynote3"	=> ["value" => $active['address'],"color" => "#173177"],
-					"remark"	=> ["value" => "欢迎您的参加哦!","color" => "#173177"],],];
-				weixinUtil::sendTaskInform($changeData,$merchant);
+						"first" => ["value" => "您好,您已报名成功", "color" => "#173177"],
+						"keynote1" => ["value" => $active['title'], "color" => "#173177"],
+						"keynote2" => ["value" => date("m-d H:i", $active['startTime']), "color" => "#173177"],
+						"keynote3" => ["value" => $active['address'], "color" => "#173177"],
+						"remark" => ["value" => "欢迎您的参加哦!", "color" => "#173177"],],];
+				weixinUtil::sendTaskInform($changeData, $merchant);
 				break;
-
+			
 			case $typeList['xhRecharge']['id']://现金充值
-				$totalBalance	= isset($upAssetData['balance']) ? $upAssetData['balance'] : 0;
-				$rechargeAmount	= $order['amount'];
-				$url			= empty($user['payPassword']) ? Yii::$app->params['frontUrl'].'/center/password?account='.$merchant['id'] : '';
-				$remark			= empty($user['payPassword']) ? '您还没有设置支付密码!点此进行设置。' : '您当前帐户余额:'.$totalBalance.'元';
-				$shortTempId	= 'TM00006';//充值成功通知用户
-				$tempId			= $allTM[$shortTempId];
-				$data 			= ["touser" => $openId,"template_id" => $tempId,"url" => $url,"data" => [
-					"first"		=> ["value" => '亲,您已充值成功。',"color" => "#173177"],
-					"accountType" => ["value" => '会员类型',"color" => "#000000"],
-					"account"	=> ["value" => '普通',"color" => "#173177"],
-					"amount"	=> ["value" => $rechargeAmount.'元',"color" => "#173177"],
-					"result"	=> ["value" => '充值成功',"color" => "#173177"],
-					"remark"	=> ["value" => $remark,"color" => "#173177"]]];
-				weixinUtil::sendTaskInform($data,$merchant);
+				$totalBalance = isset($upAssetData['balance']) ? $upAssetData['balance'] : 0;
+				$rechargeAmount = $order['amount'];
+				$url = empty($user['payPassword']) ? Yii::$app->params['frontUrl'] . '/center/password?account=' . $merchant['id'] : '';
+				$remark = empty($user['payPassword']) ? '您还没有设置支付密码!点此进行设置。' : '您当前帐户余额:' . $totalBalance . '元';
+				$shortTempId = 'TM00006';//充值成功通知用户
+				$tempId = $allTM[$shortTempId];
+				$data = ["touser" => $openId, "template_id" => $tempId, "url" => $url, "data" => [
+					"first" => ["value" => '亲,您已充值成功。', "color" => "#173177"],
+					"accountType" => ["value" => '会员类型', "color" => "#000000"],
+					"account" => ["value" => '普通', "color" => "#173177"],
+					"amount" => ["value" => $rechargeAmount . '元', "color" => "#173177"],
+					"result" => ["value" => '充值成功', "color" => "#173177"],
+					"remark" => ["value" => $remark, "color" => "#173177"]]];
+				weixinUtil::sendTaskInform($data, $merchant);
 				break;
-
+			
 			case $typeList['xhUserUnite']['id']:
-				if($addIntegral > 0){
-					$shortTempId				= 'TM00230';
-					$tempId						= $allTM[$shortTempId];
-					$changeData					= ["touser" => $openId,"template_id" => $tempId,
-					"url" => Yii::$app->params['frontUrl'].'/center/right?account='.$merchant['id'],
-					"data" => [
-					"first"		=> ["value" => "支付宝绑定成功,获得积分:","color" => "#173177"],
-					"FieldName" => ["value" => "会员名称","color" => "#0F0F0F"],
-					"Account" => ["value" => $user['userName'],"color" => "#173177"],
-					"change"	=> ["value" => "增加","color" => "#0F0F0F"],
-					"CreditChange"	=> ["value" => $addIntegral,"color" => "#173177"],
-					"CreditTotal"	=> ["value" => $integral,"color" => "#173177"],
-					"Remark"	=> ["value" => "点此查看明细!","color" => "#173177"],],];
-					weixinUtil::sendTaskInform($changeData,$merchant);
+				if ($addIntegral > 0) {
+					$shortTempId = 'TM00230';
+					$tempId = $allTM[$shortTempId];
+					$changeData = ["touser" => $openId, "template_id" => $tempId,
+						"url" => Yii::$app->params['frontUrl'] . '/center/right?account=' . $merchant['id'],
+						"data" => [
+							"first" => ["value" => "支付宝绑定成功,获得积分:", "color" => "#173177"],
+							"FieldName" => ["value" => "会员名称", "color" => "#0F0F0F"],
+							"Account" => ["value" => $user['userName'], "color" => "#173177"],
+							"change" => ["value" => "增加", "color" => "#0F0F0F"],
+							"CreditChange" => ["value" => $addIntegral, "color" => "#173177"],
+							"CreditTotal" => ["value" => $integral, "color" => "#173177"],
+							"Remark" => ["value" => "点此查看明细!", "color" => "#173177"],],];
+					weixinUtil::sendTaskInform($changeData, $merchant);
 				}
 				break;
-
+			
 			default:
-
+			
 		}
 		//新增积分
-		UserIntegralService::increaseToUpgrade($preIntegral,$integral, $preLevel, $userId, $merchantId, $merchantExtend);
-
+		UserIntegralService::increaseToUpgrade($preIntegral, $integral, $preLevel, $userId, $merchantId, $merchantExtend);
+		
 		self::updateByUserId($userId, $upAssetData);
 	}
-
+	
 }

+ 2 - 2
common/services/xhWxOpenService.php

@@ -9,10 +9,10 @@ class xhWxOpenService {
 
 	public static function getById($id=0)
 	{
-		$merchant		= xhWxOpen::getByCondition($condition);
+		$merchant		= xhWxOpen::getByCondition(['id'=>$id]);
 		return $merchant;
 	}
-	
+
 	public static function updateById($id, $data)
 	{
 		xhWxOpen::updateById($id, $data);