WxMessageClass.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. <?php
  2. namespace biz\wx\classes;
  3. use biz\base\classes\BaseClass;
  4. use biz\ghs\classes\GhsClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\shop\classes\ShopClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use common\components\dict;
  9. use common\components\noticeUtil;
  10. use common\components\util;
  11. use common\components\wxUtil;
  12. use Yii;
  13. class WxMessageClass extends BaseClass
  14. {
  15. public static $baseFile = '\biz\wx\models\WxMessage';
  16. public static function has()
  17. {
  18. return [
  19. //零售
  20. dict::getDict('ptStyle', 'hd') => [
  21. 'OPENTM417875155' => '新订单通知',
  22. 'OPENTM207430125' => '操作成功通知',
  23. 'OPENTM401915538' => '审核通知',
  24. 'OPENTM201205968' => '订单送达通知',
  25. 'OPENTM207777535' => '付款提醒',
  26. 'OPENTM207422813' => '收入提醒',
  27. 'OPENTM202297555' => '下单成功通知',
  28. 'OPENTM207327227' => '宝贝售出提醒',
  29. 'OPENTM207188526' => '付款成功',
  30. 'OPENTM411207151' => '提现成功通知',
  31. 'OPENTM416881153' => '发货通知',
  32. 'OPENTM407280253' => '退款成功通知',
  33. 'OPENTM411530050' => '充值成功提醒',
  34. 'OPENTM408238177' => '反馈进度通知',
  35. ],
  36. //供应商
  37. dict::getDict('ptStyle', 'ghs') => [
  38. 'OPENTM417875155' => '新订单通知',
  39. 'OPENTM207430125' => '操作成功通知',
  40. 'OPENTM401915538' => '审核通知',
  41. 'OPENTM201205968' => '订单送达通知',
  42. 'OPENTM207777535' => '付款提醒',
  43. 'OPENTM207422813' => '收入提醒',
  44. 'OPENTM202297555' => '下单成功通知',
  45. 'OPENTM207327227' => '宝贝售出提醒',
  46. 'OPENTM207188526' => '付款成功',
  47. 'OPENTM411207151' => '提现成功通知',
  48. 'OPENTM416881153' => '发货通知',
  49. 'OPENTM407280253' => '退款成功通知',
  50. 'OPENTM206773265' => '库存预警通知',
  51. 'OPENTM203447669' => '新客户加入通知',
  52. 'OPENTM411530050' => '充值成功提醒',
  53. 'OPENTM408238177' => '反馈进度通知',
  54. ],
  55. //商城
  56. dict::getDict('ptStyle', 'mall') => [
  57. ],
  58. ];
  59. }
  60. //初始化消息模板
  61. // ./yii.bat wx-message/init
  62. public static function init()
  63. {
  64. $wxBase = [
  65. dict::getDict('ptStyle', 'hd') => \bizHd\wx\classes\WxOpenClass::getWxInfo(),
  66. dict::getDict('ptStyle', 'ghs') => \bizHd\wx\classes\WxOpenClass::getGhsWxInfo(),
  67. dict::getDict('ptStyle', 'mall') => \bizHd\wx\classes\WxOpenClass::getMallWxInfo(),
  68. ];
  69. $message = self::getAllByCondition([], null, '*', null, true);
  70. if (!empty($message)) {
  71. foreach ($message as $item) {
  72. $ptStyle = $item->ptStyle;
  73. $wx = $wxBase[$ptStyle] ?? [];
  74. if (empty($wx)) {
  75. util::fail('没有找到微信平台信息');
  76. }
  77. $templateId = $item->templateId;
  78. $respond = wxUtil::delTMessage($wx, $templateId, $ptStyle);
  79. if (isset($respond['errcode']) && $respond['errcode'] == 0) {
  80. $item->delete();
  81. }
  82. }
  83. }
  84. $wxMessageList = self::has();
  85. foreach ($wxMessageList as $k => $message) {
  86. $ptStyle = $k;
  87. if (empty($message)) {
  88. continue;
  89. }
  90. $wx = $wxBase[$ptStyle] ?? [];
  91. foreach ($message as $shortId => $title) {
  92. $wxReturn = wxUtil::tMessageCreate($wx, $shortId, $ptStyle);
  93. echo json_encode($wxReturn) . "\n";
  94. if (isset($wxReturn['errcode']) && $wxReturn['errcode'] == 0) {
  95. $templateId = $wxReturn['template_id'];
  96. $data = [
  97. 'shortTemplateId' => $shortId,
  98. 'templateId' => $templateId,
  99. 'templateName' => $title,
  100. 'ptStyle' => $ptStyle,
  101. ];
  102. self::add($data);
  103. //Yii::warning("add tmessage:" . $title . " success\n");
  104. } else {
  105. Yii::warning("add tmessage error:" . json_encode($wxReturn) . " \n");
  106. noticeUtil::push("add wx message {$shortId} error:" . json_encode($wxReturn), '15280215347');
  107. }
  108. }
  109. }
  110. }
  111. //供应商新订单通知 ssh 20210529
  112. public static function newOrderInform($shop, $order)
  113. {
  114. $ptStyle = $shop->ptStyle;
  115. $wxBase = WxOpenClass::getWxBase();
  116. $wx = $wxBase[$ptStyle] ?? [];
  117. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  118. $shortTempId = 'OPENTM417875155';//新订单通知
  119. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  120. if (empty($tempId)) {
  121. return false;
  122. }
  123. $orderId = $order->id;
  124. $actPrice = $order->actPrice;
  125. $first = "您有新的订单,请注意查收";
  126. $customName = $order->customName ?? '';
  127. if (!empty($customName)) {
  128. $first = '下单客户:' . $customName;
  129. }
  130. $adminList = ShopAdminClass::getRemainAdmin($shop);
  131. if (empty($adminList)) {
  132. return false;
  133. }
  134. foreach ($adminList as $admin) {
  135. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  136. if (empty($openId)) {
  137. continue;
  138. }
  139. $data = [
  140. "touser" => $openId,
  141. "template_id" => $tempId,
  142. "url" => Yii::$app->params['ghsDomain'],
  143. "data" => [
  144. "first" => ["value" => $first, "color" => "#173177"],
  145. "keyword1" => ["value" => $order->orderSn, "color" => "#173177"],
  146. "keyword2" => ["value" => $actPrice, "color" => "#173177"],
  147. "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  148. "remark" => ["value" => "点击查看详情", "color" => "#173177"]
  149. ]
  150. ];
  151. $data['miniprogram']['appid'] = $wx['miniAppId'];
  152. $data['miniprogram']['pagepath'] = 'pagesOrder/detail?id=' . $orderId;
  153. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  154. }
  155. }
  156. //花店新订单通知 ssh 20210529
  157. public static function hdNewOrderInform($shop, $order)
  158. {
  159. $ptStyle = $shop->ptStyle;
  160. $wxBase = WxOpenClass::getWxBase();
  161. $wx = $wxBase[$ptStyle] ?? [];
  162. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  163. $shortTempId = 'OPENTM417875155';//新订单通知
  164. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  165. if (empty($tempId)) {
  166. return false;
  167. }
  168. $orderId = $order->id;
  169. $actPrice = $order->actPrice;
  170. $adminList = ShopAdminClass::getRemainAdmin($shop);
  171. if (empty($adminList)) {
  172. return false;
  173. }
  174. foreach ($adminList as $admin) {
  175. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  176. if (empty($openId)) {
  177. continue;
  178. }
  179. $data = [
  180. "touser" => $openId,
  181. "template_id" => $tempId,
  182. "url" => Yii::$app->params['ghsDomain'],
  183. "data" => [
  184. "first" => ["value" => "您有新的订单,请注意查收", "color" => "#173177"],
  185. "keyword1" => ["value" => $order->orderSn, "color" => "#173177"],
  186. "keyword2" => ["value" => $actPrice, "color" => "#173177"],
  187. "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  188. "remark" => ["value" => "点击查看详情", "color" => "#173177"]
  189. ]
  190. ];
  191. $data['miniprogram']['appid'] = $wx['miniAppId'];
  192. $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  193. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  194. }
  195. }
  196. //审核通过通知 ssh 20210530
  197. public static function applyPass($shop)
  198. {
  199. $ptStyle = $shop->ptStyle;
  200. $wxBase = WxOpenClass::getWxBase();
  201. $wx = $wxBase[$ptStyle] ?? [];
  202. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  203. $shortTempId = 'OPENTM401915538';//审核通过通知
  204. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  205. if (empty($tempId)) {
  206. return false;
  207. }
  208. $adminList = ShopAdminClass::getRemainAdmin($shop);
  209. if (empty($adminList)) {
  210. return false;
  211. }
  212. foreach ($adminList as $admin) {
  213. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  214. if (empty($openId)) {
  215. continue;
  216. }
  217. $data = array(
  218. "touser" => $openId,
  219. "template_id" => $tempId,
  220. "url" => Yii::$app->params['ghsDomain'],
  221. "data" => array(
  222. "first" => array(
  223. "value" => "恭喜,您的开店申请审核通过。",
  224. "color" => "#173177"
  225. ),
  226. "keyword1" => array(
  227. "value" => '审核通过',
  228. "color" => "#173177"
  229. ),
  230. "keyword2" => array(
  231. "value" => date("Y-m-d H:i:s"),
  232. "color" => "#173177"
  233. ),
  234. "remark" => array(
  235. "value" => '点击登陆后台',
  236. "color" => "#173177"
  237. )
  238. ),
  239. );
  240. $data['miniprogram']['appid'] = $wx['miniAppId'];
  241. $data['miniprogram']['pagepath'] = 'admin/home/workbench';
  242. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  243. }
  244. }
  245. //采购单下单成功 ssh 20210531
  246. public static function generateCgOrder($shop, $order)
  247. {
  248. $ptStyle = $shop->ptStyle;
  249. $wxBase = WxOpenClass::getWxBase();
  250. $wx = $wxBase[$ptStyle] ?? [];
  251. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  252. $shortTempId = 'OPENTM202297555';//下单成功通知
  253. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  254. if (empty($tempId)) {
  255. return false;
  256. }
  257. $orderId = $order->id;
  258. $orderSn = (string)$order->orderSn;
  259. $totalFee = $order->actPrice;
  260. $adminList = ShopAdminClass::getRemainAdmin($shop);
  261. if (empty($adminList)) {
  262. return false;
  263. }
  264. foreach ($adminList as $admin) {
  265. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  266. if (empty($openId)) {
  267. continue;
  268. }
  269. $data = [
  270. "touser" => $openId,
  271. "template_id" => $tempId,
  272. "url" => Yii::$app->params['ghsDomain'],
  273. "data" => [
  274. "first" => ["value" => '亲,您的采购单已生成', "color" => "#173177"],
  275. "keyword1" => ["value" => $orderSn, "color" => "#173177"],
  276. "keyword2" => ["value" => '花材', "color" => "#173177"],
  277. "keyword3" => ["value" => $order->bigNum . '/' . $order->smallNum, "color" => "#173177"],
  278. "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  279. "keyword5" => ["value" => '-', "color" => "#173177"],
  280. "remark" => ["value" => "", "color" => "#173177"]
  281. ]
  282. ];
  283. $data['miniprogram']['appid'] = $wx['miniAppId'];
  284. $data['miniprogram']['pagepath'] = 'pagesPurchase/purDetails?id=' . $orderId;
  285. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  286. }
  287. }
  288. //采购单已发货 ssh 20210531
  289. public static function cgOrderHasSend($shop, $order)
  290. {
  291. $ptStyle = $shop->ptStyle;
  292. $wxBase = WxOpenClass::getWxBase();
  293. $wx = $wxBase[$ptStyle] ?? [];
  294. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  295. $shortTempId = 'OPENTM416881153';//下单成功通知
  296. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  297. if (empty($tempId)) {
  298. return false;
  299. }
  300. $orderId = $order->id;
  301. $orderSn = (string)$order->orderSn;
  302. $adminList = ShopAdminClass::getRemainAdmin($shop);
  303. if (empty($adminList)) {
  304. return false;
  305. }
  306. $ghsShopAdminName = $order->ghsShopAdminName ?? '';
  307. foreach ($adminList as $admin) {
  308. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  309. if (empty($openId)) {
  310. continue;
  311. }
  312. $data = [
  313. "touser" => $openId,
  314. "template_id" => $tempId,
  315. "url" => Yii::$app->params['ghsDomain'],
  316. "data" => [
  317. "first" => ["value" => '亲,您的采购单已发货,请注意签收', "color" => "#173177"],
  318. "keyword1" => ["value" => $orderSn, "color" => "#173177"],
  319. "keyword2" => ["value" => date("Y-m-d H:i:s"), "color" => "#173177"],
  320. "keyword3" => ["value" => $ghsShopAdminName, "color" => "#173177"],
  321. "remark" => ["value" => "点击查看详情", "color" => "#173177"]
  322. ]
  323. ];
  324. $data['miniprogram']['appid'] = $wx['miniAppId'];
  325. $data['miniprogram']['pagepath'] = 'pagesPurchase/purDetails?id=' . $orderId;
  326. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  327. }
  328. }
  329. //零售清算欠款通知供应商 ssh 20210531
  330. public static function clearInform($shop, $order, $custom)
  331. {
  332. $ptStyle = $shop->ptStyle;
  333. $wxBase = WxOpenClass::getWxBase();
  334. $wx = $wxBase[$ptStyle] ?? [];
  335. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  336. $shortTempId = 'OPENTM207422813';//收入提醒
  337. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  338. if (empty($tempId)) {
  339. return false;
  340. }
  341. $actPrice = $order->actPrice;
  342. $name = $custom->name ?? '';
  343. $customId = $custom->id;
  344. $adminList = ShopAdminClass::getRemainAdmin($shop);
  345. if (empty($adminList)) {
  346. return false;
  347. }
  348. foreach ($adminList as $admin) {
  349. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  350. if (empty($openId)) {
  351. continue;
  352. }
  353. $data = [
  354. "touser" => $openId,
  355. "template_id" => $tempId,
  356. "url" => Yii::$app->params['ghsDomain'],
  357. "data" => [
  358. "first" => ["value" => "{$name}结帐付款{$actPrice}元", "color" => "#173177"],
  359. "keyword1" => ["value" => $actPrice, "color" => "#173177"],
  360. "keyword2" => ["value" => '客户结帐', "color" => "#173177"],
  361. "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  362. "remark" => ["value" => "点击查看详情", "color" => "#173177"]
  363. ]
  364. ];
  365. $data['miniprogram']['appid'] = $wx['miniAppId'];
  366. $data['miniprogram']['pagepath'] = 'pagesArrears/details?id=' . $customId;
  367. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  368. }
  369. }
  370. //收款码收入通知 ssh 20210531
  371. public static function gatheringIncomeInform($shop, $order)
  372. {
  373. $ptStyle = $shop->ptStyle;
  374. $wxBase = WxOpenClass::getWxBase();
  375. $wx = $wxBase[$ptStyle] ?? [];
  376. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  377. $shortTempId = 'OPENTM207422813';//收入提醒
  378. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  379. if (empty($tempId)) {
  380. return false;
  381. }
  382. $actPrice = $order->actPrice;
  383. $orderId = $order->id;
  384. $adminList = ShopAdminClass::getRemainAdmin($shop);
  385. if (empty($adminList)) {
  386. return false;
  387. }
  388. foreach ($adminList as $admin) {
  389. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  390. if (empty($openId)) {
  391. continue;
  392. }
  393. $data = [
  394. "touser" => $openId,
  395. "template_id" => $tempId,
  396. "url" => Yii::$app->params['ghsDomain'],
  397. "data" => [
  398. "first" => ["value" => "您有新的收入。", "color" => "#173177"],
  399. "keyword1" => ["value" => $actPrice, "color" => "#173177"],
  400. "keyword2" => ["value" => '二维码收款', "color" => "#173177"],
  401. "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  402. "remark" => ["value" => "点击查看详情", "color" => "#173177"]
  403. ]
  404. ];
  405. $data['miniprogram']['appid'] = $wx['miniAppId'];
  406. $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  407. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  408. }
  409. }
  410. //提现成功通知 ssh 20210531
  411. public static function cashInform($shop, $cash)
  412. {
  413. $ptStyle = $shop->ptStyle;
  414. $wxBase = WxOpenClass::getWxBase();
  415. $wx = $wxBase[$ptStyle] ?? [];
  416. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  417. $shortTempId = 'OPENTM411207151';
  418. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  419. if (empty($tempId)) {
  420. return false;
  421. }
  422. $amount = $cash->amount;
  423. $adminList = ShopAdminClass::getRemainAdmin($shop);
  424. if (empty($adminList)) {
  425. return false;
  426. }
  427. $mainId = $shop->mainId ?? 0;
  428. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', 'adminId');
  429. foreach ($adminList as $admin) {
  430. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  431. if (empty($openId)) {
  432. continue;
  433. }
  434. $adminId = $admin['id'] ?? 0;
  435. $super = $staffList[$adminId]['super'] ?? 0;
  436. //提现管理员才通知
  437. if ($super == 0) {
  438. continue;
  439. }
  440. $data = [
  441. "touser" => $openId,
  442. "template_id" => $tempId,
  443. "url" => Yii::$app->params['ghsDomain'],
  444. "data" => [
  445. "first" => ["value" => "您的提现已经到帐。", "color" => "#173177"],
  446. "keyword1" => ["value" => $amount, "color" => "#173177"],
  447. "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  448. "remark" => ["value" => "感谢您的使用", "color" => "#173177"]
  449. ]
  450. ];
  451. $data['miniprogram']['appid'] = $wx['miniAppId'];
  452. $data['miniprogram']['pagepath'] = 'pagesStore/me/withdraw';
  453. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  454. }
  455. }
  456. //订单送达通知 ssh 20210607
  457. public static function reachInform($shop, $order)
  458. {
  459. $ptStyle = $shop->ptStyle;
  460. $wxBase = WxOpenClass::getWxBase();
  461. $wx = $wxBase[$ptStyle] ?? [];
  462. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  463. $shortTempId = 'OPENTM201205968';
  464. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  465. if (empty($tempId)) {
  466. return false;
  467. }
  468. $orderId = $order->id ?? '';
  469. $orderSn = (string)$order->orderSn ?? '';
  470. $customName = $order->customName ?? '';
  471. $adminList = ShopAdminClass::getRemainAdmin($shop);
  472. if (empty($adminList)) {
  473. return false;
  474. }
  475. foreach ($adminList as $admin) {
  476. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  477. if (empty($openId)) {
  478. continue;
  479. }
  480. $data = [
  481. "touser" => $openId,
  482. "template_id" => $tempId,
  483. "url" => Yii::$app->params['ghsDomain'],
  484. "data" => [
  485. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  486. "keyword1" => ["value" => $orderSn, "color" => "#173177"],
  487. "keyword2" => ["value" => $customName, "color" => "#173177"],
  488. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  489. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  490. ]
  491. ];
  492. $data['miniprogram']['appid'] = $wx['miniAppId'];
  493. $data['miniprogram']['pagepath'] = 'pagesOrder/detail?id=' . $orderId;
  494. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  495. }
  496. }
  497. //采购退款成功通知 ssh 20210730
  498. public static function cgRefundInform($shop, $cg, $amount)
  499. {
  500. $ptStyle = $shop->ptStyle;
  501. $wxBase = WxOpenClass::getWxBase();
  502. $wx = $wxBase[$ptStyle] ?? [];
  503. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  504. $shortTempId = 'OPENTM407280253';
  505. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  506. if (empty($tempId)) {
  507. return false;
  508. }
  509. $orderId = $cg->id ?? '';
  510. $orderSn = (string)$cg->orderSn ?? '';
  511. $adminList = ShopAdminClass::getRemainAdmin($shop);
  512. if (empty($adminList)) {
  513. return false;
  514. }
  515. foreach ($adminList as $admin) {
  516. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  517. if (empty($openId)) {
  518. continue;
  519. }
  520. $data = [
  521. "touser" => $openId,
  522. "template_id" => $tempId,
  523. "url" => Yii::$app->params['ghsDomain'],
  524. "data" => [
  525. "first" => ["value" => '采购单:' . $orderSn, "color" => "#173177"],
  526. "keyword1" => ["value" => "订单退款", "color" => "#173177"],
  527. "keyword2" => ["value" => $amount . "元", "color" => "#173177"],
  528. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  529. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  530. ]
  531. ];
  532. $data['miniprogram']['appid'] = $wx['miniAppId'];
  533. $data['miniprogram']['pagepath'] = 'pagesPurchase/purDetails?id=' . $orderId;
  534. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  535. }
  536. }
  537. //库存预警通知 ssh 20210909
  538. public static function stockWarningInform($shop, $productList)
  539. {
  540. if (empty($productList)) {
  541. return false;
  542. }
  543. $remark = '';
  544. foreach ($productList as $key => $product) {
  545. $stock = $product->stock ?? 0;
  546. $currentStock = floatval($stock);
  547. $name = $product->name ?? '';
  548. $remark .= $name . "({$currentStock}) ";
  549. }
  550. $ptStyle = $shop->ptStyle;
  551. $wxBase = WxOpenClass::getWxBase();
  552. $wx = $wxBase[$ptStyle] ?? [];
  553. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  554. $shortTempId = 'OPENTM206773265';
  555. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  556. if (empty($tempId)) {
  557. return false;
  558. }
  559. $shopName = $shop->shopName ?? '';
  560. $date = date("Y-m-d H:i:s");
  561. $adminList = ShopAdminClass::getRemainAdmin($shop);
  562. if (empty($adminList)) {
  563. return false;
  564. }
  565. foreach ($adminList as $admin) {
  566. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  567. if (empty($openId)) {
  568. continue;
  569. }
  570. $data = [
  571. "touser" => $openId,
  572. "template_id" => $tempId,
  573. "url" => Yii::$app->params['ghsDomain'],
  574. "data" => [
  575. "first" => ["value" => "", "color" => "#173177"],
  576. "keyword1" => ["value" => $shopName, "color" => "#173177"],
  577. "keyword2" => ["value" => "查看备注栏", "color" => "#173177"],
  578. "keyword3" => ["value" => "库存不足", "color" => "#D52B4D"],
  579. "keyword4" => ["value" => $date, "color" => "#173177"],
  580. "remark" => ["value" => $remark, "color" => "#D52B4D"]
  581. ]
  582. ];
  583. $data['miniprogram']['appid'] = $wx['miniAppId'];
  584. $data['miniprogram']['pagepath'] = 'pagesStorehouse/stockWarn/manage';
  585. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  586. }
  587. }
  588. //供货商客户领取了新人红包 ssh 20211027
  589. public static function ghsCustomGetNewGiftInform($shop, $custom)
  590. {
  591. $ptStyle = $shop->ptStyle ?? 0;
  592. $wxBase = WxOpenClass::getWxBase();
  593. $wx = $wxBase[$ptStyle] ?? [];
  594. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  595. $shortTempId = 'OPENTM408238177';
  596. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  597. if (empty($tempId)) {
  598. return false;
  599. }
  600. $customId = $custom['id'] ?? 0;
  601. $customName = $custom['name'] ?? '';
  602. $adminList = ShopAdminClass::getRemainAdmin($shop);
  603. if (empty($adminList)) {
  604. return false;
  605. }
  606. foreach ($adminList as $admin) {
  607. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  608. if (empty($openId)) {
  609. continue;
  610. }
  611. $data = [
  612. "touser" => $openId,
  613. "template_id" => $tempId,
  614. "url" => Yii::$app->params['ghsDomain'],
  615. "data" => [
  616. "first" => ["value" => $customName . " 领取了新客红包", "color" => "#173177"],
  617. "keyword1" => ["value" => "新客红包", "color" => "#173177"],
  618. "keyword2" => ["value" => "已领取", "color" => "#173177"],
  619. "remark" => ["value" => '点击查看客户', "color" => "#173177"]
  620. ]
  621. ];
  622. $data['miniprogram']['appid'] = $wx['miniAppId'];
  623. $data['miniprogram']['pagepath'] = 'pagesClient/member/detail?id=' . $customId;
  624. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  625. }
  626. }
  627. //供货商的客户介绍新客并且下单,获得红包通知商家 ssh 20211027
  628. public static function ghsCustomTjGetGiftInform($shop, $custom, $beTjCustom)
  629. {
  630. $ptStyle = $shop->ptStyle ?? 0;
  631. $wxBase = WxOpenClass::getWxBase();
  632. $wx = $wxBase[$ptStyle] ?? [];
  633. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  634. $shortTempId = 'OPENTM408238177';
  635. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  636. if (empty($tempId)) {
  637. return false;
  638. }
  639. $customId = $custom->id ?? 0;
  640. $customName = $custom->name ?? '';
  641. $beTjCustomName = $beTjCustom->name ?? '';
  642. $adminList = ShopAdminClass::getRemainAdmin($shop);
  643. if (empty($adminList)) {
  644. return false;
  645. }
  646. foreach ($adminList as $admin) {
  647. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  648. if (empty($openId)) {
  649. continue;
  650. }
  651. $data = [
  652. "touser" => $openId,
  653. "template_id" => $tempId,
  654. "url" => Yii::$app->params['ghsDomain'],
  655. "data" => [
  656. "first" => ["value" => "【{$beTjCustomName}】推荐的客户【{$customName}】已下单", "color" => "#173177"],
  657. "keyword1" => ["value" => "推荐新客红包", "color" => "#173177"],
  658. "keyword2" => ["value" => "已发放给【{$beTjCustomName}】", "color" => "#173177"],
  659. "remark" => ["value" => '点击查看客户', "color" => "#173177"]
  660. ]
  661. ];
  662. $data['miniprogram']['appid'] = $wx['miniAppId'];
  663. $data['miniprogram']['pagepath'] = 'pagesClient/member/detail?id=' . $customId;
  664. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  665. }
  666. }
  667. //花店推荐供货商客户获得红包 ssh 20211027
  668. public static function hdTjGhsCustomGetGiftInform($shop, $ghs, $beTjCustom)
  669. {
  670. $ptStyle = $shop->ptStyle ?? 0;
  671. $wxBase = WxOpenClass::getWxBase();
  672. $wx = $wxBase[$ptStyle] ?? [];
  673. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  674. $shortTempId = 'OPENTM408238177';
  675. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  676. if (empty($tempId)) {
  677. return false;
  678. }
  679. $beTjCustomName = $beTjCustom->name ?? '';
  680. $ghsName = $ghs->name ?? '';
  681. $adminList = ShopAdminClass::getRemainAdmin($shop);
  682. if (empty($adminList)) {
  683. return false;
  684. }
  685. foreach ($adminList as $admin) {
  686. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  687. if (empty($openId)) {
  688. continue;
  689. }
  690. $data = [
  691. "touser" => $openId,
  692. "template_id" => $tempId,
  693. "url" => Yii::$app->params['ghsDomain'],
  694. "data" => [
  695. "first" => ["value" => "您推荐的客户【{$beTjCustomName}】已在【{$ghsName}】下单", "color" => "#173177"],
  696. "keyword1" => ["value" => "推荐新客红包", "color" => "#173177"],
  697. "keyword2" => ["value" => "已获得", "color" => "#173177"],
  698. "remark" => ["value" => '点击查看红包', "color" => "#173177"]
  699. ]
  700. ];
  701. $data['miniprogram']['appid'] = $wx['miniAppId'];
  702. $data['miniprogram']['pagepath'] = 'admin/coupon/couponList';
  703. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  704. }
  705. }
  706. //供应商新客户通知 ssh 20210909
  707. public static function newGhsCustomInform($shop, $custom, $introduce)
  708. {
  709. $ptStyle = $shop['ptStyle'] ?? 0;
  710. $wxBase = WxOpenClass::getWxBase();
  711. $wx = $wxBase[$ptStyle] ?? [];
  712. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  713. $shortTempId = 'OPENTM203447669';
  714. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  715. if (empty($tempId)) {
  716. return false;
  717. }
  718. $customId = $custom['id'] ?? 0;
  719. $customName = $custom['name'] ?? '';
  720. $date = date("Y-m-d H:i:s");
  721. $adminList = ShopAdminClass::getRemainAdmin($shop);
  722. if (empty($adminList)) {
  723. return false;
  724. }
  725. $first = '';
  726. if (!empty($introduce)) {
  727. $introName = $introduce->name ?? '';
  728. $first = "此客户由【{$introName}】介绍";
  729. }
  730. foreach ($adminList as $admin) {
  731. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  732. if (empty($openId)) {
  733. continue;
  734. }
  735. $data = [
  736. "touser" => $openId,
  737. "template_id" => $tempId,
  738. "url" => Yii::$app->params['ghsDomain'],
  739. "data" => [
  740. "first" => ["value" => $first, "color" => "#173177"],
  741. "keyword1" => ["value" => $customId, "color" => "#173177"],
  742. "keyword2" => ["value" => $customName, "color" => "#D52B4D"],
  743. "keyword3" => ["value" => $date, "color" => "#173177"],
  744. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  745. ]
  746. ];
  747. $data['miniprogram']['appid'] = $wx['miniAppId'];
  748. $data['miniprogram']['pagepath'] = 'pagesClient/member/detail?id=' . $customId;
  749. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  750. }
  751. }
  752. //客户充值通知供应商 ssh 20211005
  753. public static function customRechargeInformGhs($recharge)
  754. {
  755. $amount = $recharge->amount ?? 0;
  756. $hbId = $recharge->hbId ?? 0;
  757. $ghsId = $recharge->ghsId ?? 0;
  758. if (empty($ghsId)) {
  759. return false;
  760. }
  761. if (empty($hbId)) {
  762. return false;
  763. }
  764. $ghsInfo = GhsClass::getById($ghsId, true);
  765. $shopId = $ghsInfo->shopId ?? 0;
  766. $customId = $ghsInfo->customId ?? 0;
  767. $customInfo = CustomClass::getById($customId, true);
  768. $customName = $customInfo->name ?? '';
  769. $shopInfo = ShopClass::getById($shopId, true);
  770. $ptStyle = $shopInfo->ptStyle ?? 0;
  771. $wxBase = WxOpenClass::getWxBase();
  772. $wx = $wxBase[$ptStyle] ?? [];
  773. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  774. $shortTempId = 'OPENTM411530050';
  775. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  776. if (empty($tempId)) {
  777. return false;
  778. }
  779. $adminList = ShopAdminClass::getRemainAdmin($shopInfo);
  780. if (empty($adminList)) {
  781. return false;
  782. }
  783. foreach ($adminList as $admin) {
  784. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  785. if (empty($openId)) {
  786. continue;
  787. }
  788. $data = [
  789. "touser" => $openId,
  790. "template_id" => $tempId,
  791. "url" => Yii::$app->params['ghsDomain'],
  792. "data" => [
  793. "first" => ["value" => "有新客户充值", "color" => "#173177"],
  794. "keyword1" => ["value" => $customName, "color" => "#173177"],
  795. "keyword2" => ["value" => $customId, "color" => "#D52B4D"],
  796. "keyword3" => ["value" => $amount, "color" => "#173177"],
  797. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  798. ]
  799. ];
  800. $data['miniprogram']['appid'] = $wx['miniAppId'];
  801. $data['miniprogram']['pagepath'] = 'admin/hb/rechargeList';
  802. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  803. }
  804. }
  805. }