shish 6 lat temu
rodzic
commit
38a24badaa

+ 71 - 7
biz/MQ/services/InformAdminService.php

@@ -1,22 +1,86 @@
 <?php
+
 namespace biz\MQ\services;
+
+use biz\admin\classes\AdminClass;
+use biz\admin\services\AdminService;
 use biz\base\services\BaseService;
+use biz\merchant\services\MerchantService;
+use common\components\sms;
+use common\components\util;
 use Yii;
 use linslin\yii2\curl;
+
 class InformAdminService extends BaseService
 {
-
+	
 	public static $baseFile = '\biz\MQ\classes\InformAdminClass';
+	
+	//门店收入提醒 shish 2019.12.24
+	public static function shopIncomeInformAdmin($data, $merchantId = 0)
+	{
+		$TMList = xhTMessageService::getList($merchantId);
+		$adminList = AdminClass::getAllNoticeAdmin($merchantId);
+		$merchant = MerchantService::getById($merchantId);
+		$shortTempId = 'OPENTM207422813';//收入提醒
+		if (isset($TMList[$shortTempId]) == false) {
+			util::fail('没有找到公众号的消息模样:' . $shortTempId);
+		}
+		$tempId = $TMList[$shortTempId];
+		foreach ($adminList as $adminKey => $admin) {
+			$openId = $admin['openId'];
+			if (!empty($openId) && $admin['subscribe'] == 1) {
+				$data = ["touser" => $openId, "template_id" => $tempId,
+					"url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderId, "data" => [
+						"first" => ["value" => $userName . $payWay . '付款', "color" => "#173177"],
+						"keyword1" => ["value" => $totalFee . '元', "color" => "#173177"],
+						"keyword2" => ["value" => '客户付款', "color" => "#173177"],
+						"keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
+						"remark" => ["value" => "点击查看明细", "color" => "#173177"]]];
+				$respond = weixinUtil::sendTaskInform($data, $merchant);
+				Yii::info('tm:' . json_encode($respond));
+			} else {
+				$mobile = $admin['mobile'];
+				$msg = "客户" . $userName . "付款" . $totalFee . '元';
+				sms::merchantSend($mobile, $msg, $merchant);
+			}
+		}
+	}
 
 	//宝贝售出通知 shish 2019.12.24
+	//有多少人要通知
 	public static function goodsSoldInformAdmin($data)
 	{
-		$focus = true;
-		if($focus == true){
-			TMessageService::adminGoodsSold($data);
-		}else{
-			SmsService::adminGoodsSold($data);
+		$TMList = xhTMessageService::getList($merchantId);
+		$adminList = AdminClass::getAllNoticeAdmin($merchantId);
+		$merchant = MerchantService::getById($merchantId);
+		$shortTempId = 'OPENTM207422813';//收入提醒
+		if (isset($TMList[$shortTempId]) == false) {
+			util::fail('没有找到公众号的消息模样:' . $shortTempId);
+		}
+		$tempId = $TMList[$shortTempId];
+		foreach ($adminList as $adminKey => $admin) {
+			$openId = $admin['openId'];
+			if (!empty($openId) && $admin['subscribe'] == 1) {
+				$tmData = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderId, "data" => [
+					"first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
+					"keyword1" => ["value" => (string)$orderId, "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"]]];
+				$respond = weixinUtil::sendTaskInform($tmData, $merchant);
+				Yii::info('tm:' . json_encode($respond));
+			} else {
+				$mobile = $admin['mobile'];
+				$msg = "客户" . $userName . "付款" . $totalFee . '元';
+				sms::merchantSend($mobile, $msg, $merchant);
+			}
 		}
-	}
 
+
+
+	}
+	
 }

+ 0 - 6
biz/MQ/services/SmsService.php

@@ -31,10 +31,4 @@ class SmsService extends BaseService
 		return $cacheCode;
 	}
 
-	//商家宝贝售出提醒 shish 2019.12.24
-	public static function adminGoodsSold($data)
-	{
-
-	}
-
 }

+ 35 - 6
biz/admin/classes/AdminClass.php

@@ -2,9 +2,7 @@
 
 namespace biz\admin\classes;
 
-use biz\admin\services\AdminRoleService;
 use biz\user\classes\UserClass;
-use biz\user\services\UserService;
 use common\components\util;
 use Yii;
 use biz\base\classes\BaseClass;
@@ -27,8 +25,9 @@ class AdminClass extends BaseClass
 	{
 		$roleIdList = array_column($list, 'roleId');
 		$userIdList = array_column($list, 'userId');
-		$userInfo = UserService::getByIds($userIdList, null, 'id');
-		$roleInfo = AdminRoleService::getByIds($roleIdList, null, 'id');
+		
+		$userInfo = UserClass::getByIds($userIdList, null, 'id');
+		$roleInfo = AdminRoleClass::getByIds($roleIdList, null, 'id');
 		$prefix = Yii::$app->params['imgUrl'];
 		foreach ($list as $key => $val) {
 			$roleId = $val['roleId'];
@@ -150,12 +149,12 @@ class AdminClass extends BaseClass
 				util::fail('您选择的微信已经绑定别的帐号');
 			}
 		}
-
+		
 		//密码留空不修改密码
 		if (isset($data['password']) && empty($data['password'])) {
 			unset($data['password']);
 		}
-
+		
 		$adminName = $data['adminName'];
 		if ($adminName != $admin['adminName']) {
 			$adminNameList = self::getAdminNameList($merchantId);
@@ -166,4 +165,34 @@ class AdminClass extends BaseClass
 		self::updateById($id, $data);
 	}
 	
+	//取商家需要收款通知的全部员工 shish 2019.12.24
+	public static function getAllNoticeAdmin($merchantId)
+	{
+		$list = self::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1]);
+		if (empty($list)) {
+			util::fail('此商家没有员工,请检查原因');
+		}
+		//需要收款通知的需要拿到是否关注公众号
+		$ids = array_column($list, 'userId');
+		$userInfo = UserClass::getByIds($ids);
+		foreach ($list as $key => $val) {
+			if ($val['incomeNotice'] == 0) {
+				unset($list[$key]);
+				continue;
+			}
+			$userId = $val['userId'];
+			$list[$key]['openId'] = isset($userInfo[$userId]) ? $userInfo[$userId]['openId'] : '';
+			$list[$key]['subscribe'] = isset($userInfo[$userId]) ? $userInfo[$userId]['subscribe'] : 0;
+			$list[$key]['mobile'] = isset($userInfo[$userId]) ? $userInfo[$userId]['mobile'] : '';
+		}
+		return $list;
+	}
+	
+	//取商家的全部员工 shish 2019.12.24
+	public static function getAllAdmin($merchantId, $notice)
+	{
+		$list = self::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1]);
+		return $list;
+	}
+	
 }

+ 17 - 4
biz/admin/services/AdminService.php

@@ -6,6 +6,7 @@ use biz\admin\classes\AdminClass;
 use biz\auth\services\AuthService;
 use biz\base\services\BaseService;
 use biz\merchant\services\MerchantService;
+use biz\user\services\UserService;
 use common\components\error;
 use common\components\stringUtil;
 use common\components\util;
@@ -47,7 +48,7 @@ class AdminService extends BaseService
 	}
 	
 	//员工获取权限 shish 2019.11.25
-	public static function getAuth($adminId,$merchantId)
+	public static function getAuth($adminId, $merchantId)
 	{
 		$admin = self::getById($adminId);
 		$roleId = isset($admin['roleId']) ? $admin['roleId'] : 0;
@@ -89,15 +90,27 @@ class AdminService extends BaseService
 		return $data;
 	}
 	
+	//取商家的全部有效管理员 shish 2019.12.24
+	public static function getAllAdmin($merchantId, $notice = false)
+	{
+		AdminClass::getAllAdmin($merchantId, $notice);
+	}
+	
+	//取商家需要收款通知的全部员工 shish 2019.12.24
+	public static function getAllNoticeAdmin($merchantId)
+	{
+		return AdminClass::getAllNoticeAdmin($merchantId);
+	}
+	
 	//添加员工
 	public static function addAdmin($data)
 	{
 		return AdminClass::addAdmin($data);
 	}
-
+	
 	public static function updateAdmin($admin, $post)
 	{
-		return AdminClass::updateAdmin($admin,$post);
+		return AdminClass::updateAdmin($admin, $post);
 	}
 	
 	//获取员工信息 shish 2019.12.8
@@ -111,7 +124,7 @@ class AdminService extends BaseService
 	{
 		return AdminClass::deleteAdmin($admin, $adminId);
 	}
-
+	
 	//验证权限 shish 2019.12.9
 	public static function valid($admin, $merchantId)
 	{

+ 30 - 2
common/components/sms.php

@@ -2,14 +2,42 @@
 
 namespace common\components;
 
+use biz\merchant\services\MerchantAssetService;
 use biz\weixin\services\WxOpenService;
 use Yii;
+
 /**
  * 短信接口
  */
 class sms
 {
 	
+	//商家发短信 shish 2019.12.24
+	public static function merchantSend($mobile, $msg, $merchant)
+	{
+		$merchantId = $merchant['id'];
+		$asset = MerchantAssetService::getByMerchantId($merchantId, true);
+		$remainSmsNum = $asset->remainSmsNum;
+		if ($remainSmsNum <= 0) {
+			Yii::info($merchant['merchantName'] . '短信余额不足');
+			return false;
+		}
+		$asset->remainSmsNum = --$remainSmsNum;
+		$asset->save();
+		self::freeSend($mobile, $msg, $merchant);
+	}
+	
+	//自由发送无限制 shish 2019.12.24
+	public static function freeSend($mobile, $msg, $merchant = null)
+	{
+		$open = WxOpenService::getById(1);
+		$openName = $open['openName'];
+		$sms = new chuanglanSMS('N2890342', 'abc178c7');
+		$sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$openName}】";
+		$msg .= $sign;
+		$sms->send($mobile, $msg);
+	}
+	
 	//发短信
 	public static function send($mobile, $msg, $merchant = null)
 	{
@@ -35,10 +63,10 @@ class sms
 		if ($num > 10) {
 			util::fail('您今天申请的短信条数达到上限');
 		}
-
+		
 		Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']);
 		Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]);
 		$sms->send($mobile, $msg);
 	}
-
+	
 }

+ 21 - 65
common/services/xhMerchantAssetService.php

@@ -2,6 +2,7 @@
 
 namespace common\services;
 
+use biz\MQ\services\InformAdminService;
 use biz\stat\services\StatIncomeCategoryService;
 use biz\stat\services\StatIncomeSourceService;
 use Yii;
@@ -58,7 +59,8 @@ class xhMerchantAssetService
 		Yii::$app->redis->executeCommand('DEL', [$key]);
 		return self::getByMerchantId($merchantId);
 	}
-	
+
+	//收入后资产变更 shish 2019.12.24
 	public static function incomeChangeAsset($merchant, $merchantAsset, $updateData, $order, $capitalType)
 	{
 		$merchantId = $merchant['id'];
@@ -66,23 +68,6 @@ class xhMerchantAssetService
 		$openMerchantId = $openMerchant['id'];
 		$orderId = $order['id'];
 		$date = date("Y-m-d H:i");
-		$allTM = xhTMessageService::getList($merchantId);
-		
-		//商家收益通知人暂时写死掉
-		$adminOpenIdArr = [
-			//国兰
-			'wx193341a4a80f6ea3' => ['o4c8Vs54PQh32nkgG8R3m4VuGTvw', 'o4c8VszacQJyrzu651CAu0sCsfPc'],
-			//花美灵
-			'wx84d95afcb7b594eb' => ['oTFbYvsjwgVwXggwtlM2ESAKwuN8', 'oTFbYvqP6qwdCCkdFB9GYnlzDIUg'],
-			//花卉宝
-			'wx66dd83ff8744f7a8' => ['o1ka30xHBAK2rSmfezJEv9-V3tIQ'],
-			//雨非轩老店
-			'wxdb97a39f719f38f9' => ['oTezys9qZSZZyUeL-c1ZzoYP1GFU'],
-			//雨非轩新店
-			'wx6fe0ae87d6051e7b' => ['oeJ5puPaiBz_-ZPeYmhxXyY0K9tU'],
-		];
-		$adminOpenIdList = $adminOpenIdArr[$merchant['wxAppId']];
-		
 		$totalFee = 0;
 		$payWayList = configDict::getConfig('payWayName');
 		$payWay = isset($order['payWay']) ? $order['payWay'] : 0;
@@ -90,13 +75,12 @@ class xhMerchantAssetService
 		$userId = isset($order['userId']) ? $order['userId'] : 0;
 		$user = xhUserService::getById($userId);
 		$userName = isset($user['userName']) ? $user['userName'] : '游客';
-		
-		Yii::info('capitaltype:' . $capitalType);
-		
-		$typeList = configDict::getConfig('capitalType');//充值支付涉及的流水类型列表
-		switch ($capitalType) {//根据流水类型定制通知内容
-			
-			case $typeList['xhOrder']['id']://购买商品
+		//充值支付涉及的流水类型列表
+		$typeList = configDict::getConfig('capitalType');
+		//根据流水类型定制通知内容
+		switch ($capitalType) {
+			//购买商品
+			case $typeList['xhOrder']['id']:
 				$orderName = $order['bookName'];
 				$totalFee = $order['actPrice'];
 				$goodsList = xhOrderGoodsService::getAllByOrderId($orderId);
@@ -110,55 +94,27 @@ class xhMerchantAssetService
 						}
 					}
 				}
+				//商城下单后通知
 				if ($order['sourceType'] == 0) {
-					$shortTempId = 'OPENTM207327227';//宝贝售出提醒
-					$tempId = $allTM[$shortTempId];
-					if (isset($allTM[$shortTempId])) {
-						if (!empty($adminOpenIdList)) {
-							foreach ($adminOpenIdList as $adminOpenId) {
-								$tmData = ["touser" => $adminOpenId, "template_id" => $tempId, "url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderId, "data" => [
-									"first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
-									"keyword1" => ["value" => (string)$orderId, "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"]]];
-								$r = weixinUtil::sendTaskInform($tmData, $merchant);
-								Yii::info('tm:' . json_encode($r));
-							}
-						}
-					}
+					//InformAdminService::goodsSoldInformAdmin($data);
+				//门店收入后通知
 				} else {
-					
-						$shortTempId = 'OPENTM207422813';//收入提醒
-						if (isset($allTM[$shortTempId])) {
-							$tempId = $allTM[$shortTempId];
-							if (!empty($adminOpenIdList)) {
-								foreach ($adminOpenIdList as $adminOpenId) {
-									$data = ["touser" => $adminOpenId, "template_id" => $tempId,
-										"url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderId, "data" => [
-											"first" => ["value" => $userName . $payWay . '付款', "color" => "#173177"],
-											"keyword1" => ["value" => $totalFee . '元', "color" => "#173177"],
-											"keyword2" => ["value" => '客户付款', "color" => "#173177"],
-											"keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
-											"remark" => ["value" => "点击查看明细", "color" => "#173177"]]];
-									$r = weixinUtil::sendTaskInform($data, $merchant);
-									Yii::info('tm:' . json_encode($r));
-								}
-							}
-						}
-					
+					//InformAdminService::shopIncomeInformAdmin($data);
 				}
 				break;
 		}
 		$asset = self::updateByMerchantId($merchantId, $updateData);
-		Yii::info('totalfee:' . $totalFee);
-		if ($totalFee > 0) {//以下一定要排后面,否则数据不准确
+		//以下一定要排后面,否则数据不准确
+		if ($totalFee > 0) {
 			xhStatIncomeService::replace($merchantId, $totalFee, $order['payWay']);
 			xhStatIncomeMonthService::replace($merchantId, $totalFee, $order['payWay']);
 			/**收入来源资金增加**/
-			StatIncomeSourceService::replaceData(['merchantId' => $order['merchantId'], 'sourceType' => $order['sourceType'], 'amount' => $order['actPrice'], 'payWay' => $order['payWay']]);
+			StatIncomeSourceService::replaceData([
+				'merchantId' => $order['merchantId'],
+				'sourceType' => $order['sourceType'],
+				'amount' => $order['actPrice'],
+				'payWay' => $order['payWay']
+			]);
 		}
 	}
 	

+ 5 - 0
sql.txt

@@ -21,6 +21,11 @@ ALTER TABLE `xhCouponAsset` ADD `totalNum` INT NOT NULL DEFAULT 0 COMMENT '全
 ALTER TABLE `xhCouponAsset` ADD `unUseNum` INT NOT NULL DEFAULT 0 COMMENT '待使用数' AFTER `totalNum`;
 ALTER TABLE `xhCouponAsset` ADD `useNum` INT NOT NULL DEFAULT 0 COMMENT '已使用数' AFTER `unUseNum`;
 ALTER TABLE `xhCouponAsset` ADD `invalidNum` INT NOT NULL DEFAULT 0 COMMENT '已失效数' AFTER `useNum`;
+ALTER TABLE `xhOrder` MODIFY `sourceType` TINYINT NOT NULL DEFAULT 0 COMMENT '订单来源,0商城 1门店 2微信朋友圈 3美团';
+ALTER TABLE `xhAdmin` ADD platUserId INT NOT NULL DEFAULT 0 COMMENT '管理员对应的花卉宝id' AFTER `userId`;
+ALTER TABLE `xhAdmin` ADD openId VARCHAR(100) NOT NULL DEFAULT '' COMMENT '管理员对应商家公众号openId' AFTER `userId`;
+ALTER TABLE `xhAdmin` DROP COLUMN `openId`;
+ALTER TABLE `xhAdmin` ADD `delStatus` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除标识 0未删除 1已删除' AFTER `super`;
 
 2019.12.23
 ALTER TABLE `xhApply` ADD UNIQUE INDEX `mobile`(`mobile`);