Răsfoiți Sursa

消息队列

shish 6 ani în urmă
părinte
comite
de44e37ef3

+ 12 - 8
app/business/controllers/BaseController.php

@@ -27,9 +27,13 @@ class BaseController extends PublicController
 		//token验证
 		$adminId = jwt::getLoginId();
 		if (empty($adminId)) {
-			$this->validate = false;
+			//本地环境请求接口没有登陆用户时设置一个默认管理员
+			if (getenv('YII_ENV') == 'local') {
+				$adminId = 6;
+			} else {
+				$this->validate = false;
+			}
 		}
-		
 		//游客可以访问的方法
 		if (in_array($action->id, $this->withoutLogin)) {
 			$this->validate = true;
@@ -37,12 +41,12 @@ class BaseController extends PublicController
 		if ($this->validate == false) {
 			util::notLogin();
 		}
-		if(httpUtil::isWx()){
-            //授权方式获取客户信息 xhAdmin userId存的是每个公众号店长的微信userId
-            $admin = AdminService::getByCondition(['userId' => $adminId]);
-        }else{
-            $admin = AdminService::getById($adminId);
-        }
+		if (httpUtil::isWx()) {
+			//授权方式获取客户信息 xhAdmin userId存的是每个公众号店长的微信userId
+			$admin = AdminService::getByCondition(['userId' => $adminId]);
+		} else {
+			$admin = AdminService::getById($adminId);
+		}
 		if (empty($admin)) {
 			util::fail('没有找到管理员,但已经获取客户ID:' . $adminId);
 		}

+ 13 - 4
app/business/controllers/TestController.php

@@ -3,6 +3,7 @@
 namespace business\controllers;
 
 use biz\merchant\services\MerchantService;
+use biz\message\services\InformAdminService;
 use common\components\wxUtil;
 use Yii;
 use common\components\util;
@@ -10,6 +11,8 @@ use common\components\util;
 class TestController extends BaseController
 {
 	
+	public $withoutLogin = ['inform'];
+	
 	//添加订单
 	public function actionAddOrder()
 	{
@@ -19,13 +22,13 @@ class TestController extends BaseController
 		require_once $dada . 'client/dadaResponse.php';
 		require_once $dada . 'config/config.php';
 		require_once $dada . 'model/orderModel.php';
-		
+
 		// isOnline 判断是否是测试环境,会有不同的域名等
 		$isOnline = false;
 		$sourceId = 1000000;
 		// 初始化一个config
 		$config = new \Config($sourceId, $isOnline);
-		
+
 		$orderModel = new \OrderModel();
 		$orderModel->setShopNo('11047059');
 		$orderModel->setOriginId('2018091100000002');
@@ -77,12 +80,18 @@ class TestController extends BaseController
 	public function actionFocus()
 	{
 		$name = '花卉宝';
-		if(getenv('YII_ENV') == 'dev'){
+		if (getenv('YII_ENV') == 'dev') {
 			$name = '花美灵';
 		}
 		$merchant = MerchantService::getByCondition(['merchantName' => $name]);
 		$list = wxUtil::getSubscribeUserList($merchant);
 		dd($list);
 	}
-
+	
+	//宝贝售出提醒 shish 2020.1.30
+	public function actionInform()
+	{
+		InformAdminService::addInform(12362, 'income', []);
+	}
+	
 }

+ 42 - 37
biz/message/classes/InformAdminClass.php

@@ -10,44 +10,17 @@ class InformAdminClass extends BaseClass
 	
 	public static $baseFile = '\biz\message\models\InformAdmin';
 	
-	//宝贝售出通知 shish 2019.12.24
-	public static function goodsSoldInformAdmin($params, $admin, $TMList)
-	{
-		$informWay = isset($admin['openId']) && !empty($admin['openId']) && isset($admin['subscribe']) && $admin['subscribe'] == 1 ? 'wx' : 'sms';
-		$totalFee = 199;
-		$orderSn = '2051229823132466';
-		$orderName = '商品';
-		$userName = '石头';
-		$data = ['tMessage' => '', 'content' => '', 'briefContent' => ''];
-		$data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
-		if ($informWay == 'wx') {
-			//收入提醒
-			$openId = $admin['openId'];
-			$shortTempId = 'OPENTM207422813';
-			$tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
-			$tMessage = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderSn, "data" => [
-				"first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
-				"keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
-				"keyword2" => ["value" => $orderName, "color" => "#173177"],
-				"keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
-				"keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
-				"keyword5" => ["value" => $userName, "color" => "#173177"],
-				"remark" => ["value" => '点此查看详细、编辑收花人信息。', "color" => "#173177"]]];
-			$data['tMessage'] = json_encode($tMessage);
-		}
-		if ($informWay == 'sms') {
-			$msg = "客户" . $userName . "付款" . $totalFee . '元';
-			$data['content'] = $msg;
-		}
-		return $data;
-	}
-	
-	//通知员工 shish
+	//增加通知员工 shish
 	public static function addInform($params, $admin, $type, $TMList)
 	{
 		switch ($type) {
 			case 'goodsSold':
-				$respond = self::goodsSoldInformAdmin($params, $admin, $TMList);
+				//宝贝售出
+				$respond = self::goodsSoldInform($params, $admin, $TMList);
+				break;
+			case 'income':
+				//收入提醒
+				$respond = self::incomeInform($params, $admin, $TMList);
 				break;
 			default:
 		}
@@ -57,6 +30,38 @@ class InformAdminClass extends BaseClass
 		$msg = serialize($data);
 		$producer->publish($msg, 'exInform', 'routeInform');
 	}
+
+	public static function incomeInform()
+	{
+		return [];
+	}
+	
+	
+	//宝贝售出通知 shish 2019.12.24
+	public static function goodsSoldInform($params, $admin, $TMList)
+	{
+		$totalFee = 199;
+		$orderSn = '2051229823132466';
+		$orderName = '商品';
+		$userName = '石头';
+		$data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
+		//收入提醒
+		$openId = $admin['openId'];
+		$shortTempId = 'OPENTM207422813';
+		$tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
+		$tMessage = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderSn, "data" => [
+			"first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
+			"keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
+			"keyword2" => ["value" => $orderName, "color" => "#173177"],
+			"keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
+			"keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
+			"keyword5" => ["value" => $userName, "color" => "#173177"],
+			"remark" => ["value" => '点此查看详细、编辑收花人信息。', "color" => "#173177"]]];
+		$data['tMessage'] = json_encode($tMessage);
+		$msg = "客户" . $userName . "付款" . $totalFee . '元';
+		$data['content'] = $msg;
+		return $data;
+	}
 	
 	//门店收入提醒 shish 2019.12.24
 	public static function shopIncomeInformAdmin2($data, $merchantId = 0)
@@ -90,7 +95,7 @@ class InformAdminClass extends BaseClass
 	}
 	
 	//宝贝售出通知 shish 2019.12.24
-	public static function goodsSoldInformAdmin2($merchantId)
+	public static function goodsSoldInform2($merchantId)
 	{
 		$TMList = xhTMessageService::getList($merchantId);
 		$merchant = MerchantService::getById($merchantId);
@@ -116,11 +121,11 @@ class InformAdminClass extends BaseClass
 			}
 		}
 	}
-
+	
 	//添加通知内容 shish 2020.1.8
 	public static function addData($data)
 	{
 		self::add($data);
 	}
-
+	
 }

+ 7 - 12
biz/message/services/InformAdminService.php

@@ -23,9 +23,9 @@ class InformAdminService extends BaseService
 		if (empty($adminList)) {
 			return false;
 		}
-		//本地环境不进行通知
+		//本地环境取消通知
 		if (getenv('YII_ENV') == 'local') {
-			return false;
+			//return false;
 		}
 		$TMList = xhTMessageService::getList($merchantId);
 		foreach ($adminList as $adminKey => $admin) {
@@ -33,7 +33,7 @@ class InformAdminService extends BaseService
 		}
 	}
 	
-	//消费通知队列 shish 2020.1.1
+	//消费通知内容 shish 2020.1.1
 	public static function consumeInformQueue($data)
 	{
 		//['messageType'=>'inform','informWay'=>'wx','userType'=>'admin','id'=>1,'mobile'=>'15280215347','tMessage'=>'','content'=>'','briefContent'=>'']
@@ -43,24 +43,21 @@ class InformAdminService extends BaseService
 		$merchantId = $admin['merchantId'];
 		$mobile = $data['mobile'];
 		$merchant = MerchantService::getMerchantById($merchantId);
-		$hasSend = false;
+		$hasSend = 0;
 		$noticeWay = 0;
 		if ($informWay == 'wx') {
 			$tMessage = json_decode($data['tMessage'], true);
 			wxUtil::sendTaskInform($tMessage, $merchant);
-			Yii::info('tm:' . json_encode($respond));
-			$hasSend = true;
+			$hasSend = 1;
 			$noticeWay = 0;
 		}
 		if ($informWay == 'sms') {
 			$msg = $data['content'];
 			sms::merchantSend($mobile, $msg, $merchant);
-			$hasSend = true;
+			$hasSend = 1;
 			$noticeWay = 1;
 		}
-		
 		//存入数据库
-		$hasSend = 0;
 		$informData = [
 			'userId' => $admin['userId'],
 			'adminId' => $id,
@@ -68,14 +65,12 @@ class InformAdminService extends BaseService
 			'noticeType' => 0,
 			'content' => $data['briefContent'],
 			'noticeWay' => $noticeWay,
-			'status' => 1,
+			'status' => $hasSend,
 			'sourceType' => 0,
 			'sourceId' => 0,
 			'addTime' => time(),
 			'createTime' => date("Y-m-d H:i:s"),
 		];
 		InformAdminClass::addData($informData);
-		
 	}
-	
 }

+ 4 - 15
common/services/xhMerchantAssetService.php

@@ -94,21 +94,10 @@ class xhMerchantAssetService
 					}
 				}
 				//sourceType 0商城 1门店 2微信朋友圈 3美团
-				if ($order['sourceType'] == 0) {
-					//商城下单通知
-					$data = [];
-					InformAdminService::goodsSoldInformAdmin($data);
-				} elseif ($order['sourceType'] == 1) {
-					//门店收入通知
-					$data = [];
-					InformAdminService::shopIncomeInformAdmin($data);
-				} elseif ($order['sourceType'] == 2) {
-					//美团收入通知
-					$data = [];
-					InformAdminService::meiTuanIncomeInformAdmin($data);
-				} else {
-
-				}
+				//收入提醒 shish 2020.1.30
+				$params = ['sourceType' => $order['sourceType']];
+				$type = '';
+				InformAdminService::addInform($merchantId, $type, $params);
 				break;
 			default:
 		}

+ 1 - 1
console/controllers/UpgradeController.php

@@ -958,7 +958,7 @@ CREATE TABLE `xhInformUser` (
 		$sql = "truncate `xhCategory`;insert  into `xhCategory`(`id`,`parentId`,`merchantId`,`categoryName`,`description`,`img`,`goodsNum`,`sold`,`inTurn`,`status`) values (1,0,12358,'花束','唯美花束','',0,0,15,1),(2,0,12358,'花盒','时尚花盒','',0,0,14,1),(3,0,12358,'开业花篮','开业花篮','',0,0,0,1),(4,0,12358,'婚礼用花','婚礼用花','',0,0,0,1),(5,0,12358,'会议用花','会议用花','',0,0,0,1),(9,0,12358,'蝴蝶兰专区','蝴蝶兰','',0,0,4,1),(87,0,12358,'花篮','时尚礼篮','',0,0,4,1),(88,0,12358,'植物-微景观','植物-微景观','',0,0,4,1);";
 		Yii::$app->db->createCommand($sql)->execute();
 		
-		//更新菜单与商品对应关系
+		//更新国兰分类与商品对应关系
 		Yii::$app->db->createCommand("truncate `xhGoodsCategory`;")->execute();
 		$goodsCategory = Yii::$app->db2->createCommand('select * from `xhGoodsCategory` where `merchantId`=12358')->queryAll();
 		if (!empty($goodsCategory)) {