WxMessageClass.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. foreach ($adminList as $admin) {
  428. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  429. if (empty($openId)) {
  430. continue;
  431. }
  432. $data = [
  433. "touser" => $openId,
  434. "template_id" => $tempId,
  435. "url" => Yii::$app->params['ghsDomain'],
  436. "data" => [
  437. "first" => ["value" => "您的提现已经到帐。", "color" => "#173177"],
  438. "keyword1" => ["value" => $amount, "color" => "#173177"],
  439. "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  440. "remark" => ["value" => "感谢您的使用", "color" => "#173177"]
  441. ]
  442. ];
  443. $data['miniprogram']['appid'] = $wx['miniAppId'];
  444. $data['miniprogram']['pagepath'] = 'pagesStore/me/withdraw';
  445. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  446. }
  447. }
  448. //订单送达通知 ssh 20210607
  449. public static function reachInform($shop, $order)
  450. {
  451. $ptStyle = $shop->ptStyle;
  452. $wxBase = WxOpenClass::getWxBase();
  453. $wx = $wxBase[$ptStyle] ?? [];
  454. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  455. $shortTempId = 'OPENTM201205968';
  456. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  457. if (empty($tempId)) {
  458. return false;
  459. }
  460. $orderId = $order->id ?? '';
  461. $orderSn = (string)$order->orderSn ?? '';
  462. $customName = $order->customName ?? '';
  463. $adminList = ShopAdminClass::getRemainAdmin($shop);
  464. if (empty($adminList)) {
  465. return false;
  466. }
  467. foreach ($adminList as $admin) {
  468. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  469. if (empty($openId)) {
  470. continue;
  471. }
  472. $data = [
  473. "touser" => $openId,
  474. "template_id" => $tempId,
  475. "url" => Yii::$app->params['ghsDomain'],
  476. "data" => [
  477. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  478. "keyword1" => ["value" => $orderSn, "color" => "#173177"],
  479. "keyword2" => ["value" => $customName, "color" => "#173177"],
  480. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  481. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  482. ]
  483. ];
  484. $data['miniprogram']['appid'] = $wx['miniAppId'];
  485. $data['miniprogram']['pagepath'] = 'pagesOrder/detail?id=' . $orderId;
  486. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  487. }
  488. }
  489. //采购退款成功通知 ssh 20210730
  490. public static function cgRefundInform($shop, $cg, $amount)
  491. {
  492. $ptStyle = $shop->ptStyle;
  493. $wxBase = WxOpenClass::getWxBase();
  494. $wx = $wxBase[$ptStyle] ?? [];
  495. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  496. $shortTempId = 'OPENTM407280253';
  497. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  498. if (empty($tempId)) {
  499. return false;
  500. }
  501. $orderId = $cg->id ?? '';
  502. $orderSn = (string)$cg->orderSn ?? '';
  503. $adminList = ShopAdminClass::getRemainAdmin($shop);
  504. if (empty($adminList)) {
  505. return false;
  506. }
  507. foreach ($adminList as $admin) {
  508. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  509. if (empty($openId)) {
  510. continue;
  511. }
  512. $data = [
  513. "touser" => $openId,
  514. "template_id" => $tempId,
  515. "url" => Yii::$app->params['ghsDomain'],
  516. "data" => [
  517. "first" => ["value" => '采购单:' . $orderSn, "color" => "#173177"],
  518. "keyword1" => ["value" => "订单退款", "color" => "#173177"],
  519. "keyword2" => ["value" => $amount . "元", "color" => "#173177"],
  520. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  521. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  522. ]
  523. ];
  524. $data['miniprogram']['appid'] = $wx['miniAppId'];
  525. $data['miniprogram']['pagepath'] = 'pagesPurchase/purDetails?id=' . $orderId;
  526. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  527. }
  528. }
  529. //库存预警通知 ssh 20210909
  530. public static function stockWarningInform($shop, $productList)
  531. {
  532. if (empty($productList)) {
  533. return false;
  534. }
  535. $remark = '';
  536. foreach ($productList as $key => $product) {
  537. $stock = $product->stock ?? 0;
  538. $currentStock = floatval($stock);
  539. $name = $product->name ?? '';
  540. $remark .= $name . "({$currentStock}) ";
  541. }
  542. $ptStyle = $shop->ptStyle;
  543. $wxBase = WxOpenClass::getWxBase();
  544. $wx = $wxBase[$ptStyle] ?? [];
  545. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  546. $shortTempId = 'OPENTM206773265';
  547. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  548. if (empty($tempId)) {
  549. return false;
  550. }
  551. $shopName = $shop->shopName ?? '';
  552. $date = date("Y-m-d H:i:s");
  553. $adminList = ShopAdminClass::getRemainAdmin($shop);
  554. if (empty($adminList)) {
  555. return false;
  556. }
  557. foreach ($adminList as $admin) {
  558. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  559. if (empty($openId)) {
  560. continue;
  561. }
  562. $data = [
  563. "touser" => $openId,
  564. "template_id" => $tempId,
  565. "url" => Yii::$app->params['ghsDomain'],
  566. "data" => [
  567. "first" => ["value" => "", "color" => "#173177"],
  568. "keyword1" => ["value" => $shopName, "color" => "#173177"],
  569. "keyword2" => ["value" => "查看备注栏", "color" => "#173177"],
  570. "keyword3" => ["value" => "库存不足", "color" => "#D52B4D"],
  571. "keyword4" => ["value" => $date, "color" => "#173177"],
  572. "remark" => ["value" => $remark, "color" => "#D52B4D"]
  573. ]
  574. ];
  575. $data['miniprogram']['appid'] = $wx['miniAppId'];
  576. $data['miniprogram']['pagepath'] = 'pagesStorehouse/stockWarn/manage';
  577. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  578. }
  579. }
  580. //供货商客户领取了新人红包 ssh 20211027
  581. public static function ghsCustomGetNewGiftInform($shop, $custom)
  582. {
  583. $ptStyle = $shop->ptStyle ?? 0;
  584. $wxBase = WxOpenClass::getWxBase();
  585. $wx = $wxBase[$ptStyle] ?? [];
  586. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  587. $shortTempId = 'OPENTM408238177';
  588. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  589. if (empty($tempId)) {
  590. return false;
  591. }
  592. $customId = $custom['id'] ?? 0;
  593. $customName = $custom['name'] ?? '';
  594. $adminList = ShopAdminClass::getRemainAdmin($shop);
  595. if (empty($adminList)) {
  596. return false;
  597. }
  598. foreach ($adminList as $admin) {
  599. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  600. if (empty($openId)) {
  601. continue;
  602. }
  603. $data = [
  604. "touser" => $openId,
  605. "template_id" => $tempId,
  606. "url" => Yii::$app->params['ghsDomain'],
  607. "data" => [
  608. "first" => ["value" => $customName . " 领取了新客红包", "color" => "#173177"],
  609. "keyword1" => ["value" => "新客红包", "color" => "#173177"],
  610. "keyword2" => ["value" => "已领取", "color" => "#173177"],
  611. "remark" => ["value" => '点击查看客户', "color" => "#173177"]
  612. ]
  613. ];
  614. $data['miniprogram']['appid'] = $wx['miniAppId'];
  615. $data['miniprogram']['pagepath'] = 'pagesClient/member/detail?id=' . $customId;
  616. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  617. }
  618. }
  619. //供货商的客户介绍新客并且下单,获得红包通知商家 ssh 20211027
  620. public static function ghsCustomTjGetGiftInform($shop, $custom, $beTjCustom)
  621. {
  622. $ptStyle = $shop->ptStyle ?? 0;
  623. $wxBase = WxOpenClass::getWxBase();
  624. $wx = $wxBase[$ptStyle] ?? [];
  625. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  626. $shortTempId = 'OPENTM408238177';
  627. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  628. if (empty($tempId)) {
  629. return false;
  630. }
  631. $customId = $custom->id ?? 0;
  632. $customName = $custom->name ?? '';
  633. $beTjCustomName = $beTjCustom->name ?? '';
  634. $adminList = ShopAdminClass::getRemainAdmin($shop);
  635. if (empty($adminList)) {
  636. return false;
  637. }
  638. foreach ($adminList as $admin) {
  639. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  640. if (empty($openId)) {
  641. continue;
  642. }
  643. $data = [
  644. "touser" => $openId,
  645. "template_id" => $tempId,
  646. "url" => Yii::$app->params['ghsDomain'],
  647. "data" => [
  648. "first" => ["value" => "【{$beTjCustomName}】推荐的客户【{$customName}】已下单", "color" => "#173177"],
  649. "keyword1" => ["value" => "推荐新客红包", "color" => "#173177"],
  650. "keyword2" => ["value" => "已发放给【{$beTjCustomName}】", "color" => "#173177"],
  651. "remark" => ["value" => '点击查看客户', "color" => "#173177"]
  652. ]
  653. ];
  654. $data['miniprogram']['appid'] = $wx['miniAppId'];
  655. $data['miniprogram']['pagepath'] = 'pagesClient/member/detail?id=' . $customId;
  656. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  657. }
  658. }
  659. //花店推荐供货商客户获得红包 ssh 20211027
  660. public static function hdTjGhsCustomGetGiftInform($shop, $ghs, $beTjCustom)
  661. {
  662. $ptStyle = $shop->ptStyle ?? 0;
  663. $wxBase = WxOpenClass::getWxBase();
  664. $wx = $wxBase[$ptStyle] ?? [];
  665. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  666. $shortTempId = 'OPENTM408238177';
  667. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  668. if (empty($tempId)) {
  669. return false;
  670. }
  671. $beTjCustomName = $beTjCustom->name ?? '';
  672. $ghsName = $ghs->name ?? '';
  673. $adminList = ShopAdminClass::getRemainAdmin($shop);
  674. if (empty($adminList)) {
  675. return false;
  676. }
  677. foreach ($adminList as $admin) {
  678. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  679. if (empty($openId)) {
  680. continue;
  681. }
  682. $data = [
  683. "touser" => $openId,
  684. "template_id" => $tempId,
  685. "url" => Yii::$app->params['ghsDomain'],
  686. "data" => [
  687. "first" => ["value" => "您推荐的客户【{$beTjCustomName}】已在【{$ghsName}】下单", "color" => "#173177"],
  688. "keyword1" => ["value" => "推荐新客红包", "color" => "#173177"],
  689. "keyword2" => ["value" => "已获得", "color" => "#173177"],
  690. "remark" => ["value" => '点击查看红包', "color" => "#173177"]
  691. ]
  692. ];
  693. $data['miniprogram']['appid'] = $wx['miniAppId'];
  694. $data['miniprogram']['pagepath'] = 'admin/coupon/couponList';
  695. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  696. }
  697. }
  698. //供应商新客户通知 ssh 20210909
  699. public static function newGhsCustomInform($shop, $custom, $introduce)
  700. {
  701. $ptStyle = $shop['ptStyle'] ?? 0;
  702. $wxBase = WxOpenClass::getWxBase();
  703. $wx = $wxBase[$ptStyle] ?? [];
  704. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  705. $shortTempId = 'OPENTM203447669';
  706. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  707. if (empty($tempId)) {
  708. return false;
  709. }
  710. $customId = $custom['id'] ?? 0;
  711. $customName = $custom['name'] ?? '';
  712. $date = date("Y-m-d H:i:s");
  713. $adminList = ShopAdminClass::getRemainAdmin($shop);
  714. if (empty($adminList)) {
  715. return false;
  716. }
  717. $first = '';
  718. if (!empty($introduce)) {
  719. $introName = $introduce->name ?? '';
  720. $first = "此客户由【{$introName}】介绍";
  721. }
  722. foreach ($adminList as $admin) {
  723. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  724. if (empty($openId)) {
  725. continue;
  726. }
  727. $data = [
  728. "touser" => $openId,
  729. "template_id" => $tempId,
  730. "url" => Yii::$app->params['ghsDomain'],
  731. "data" => [
  732. "first" => ["value" => $first, "color" => "#173177"],
  733. "keyword1" => ["value" => $customId, "color" => "#173177"],
  734. "keyword2" => ["value" => $customName, "color" => "#D52B4D"],
  735. "keyword3" => ["value" => $date, "color" => "#173177"],
  736. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  737. ]
  738. ];
  739. $data['miniprogram']['appid'] = $wx['miniAppId'];
  740. $data['miniprogram']['pagepath'] = 'pagesClient/member/detail?id=' . $customId;
  741. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  742. }
  743. }
  744. //客户充值通知供应商 ssh 20211005
  745. public static function customRechargeInformGhs($recharge)
  746. {
  747. $amount = $recharge->amount ?? 0;
  748. $hbId = $recharge->hbId ?? 0;
  749. $ghsId = $recharge->ghsId ?? 0;
  750. if (empty($ghsId)) {
  751. return false;
  752. }
  753. if (empty($hbId)) {
  754. return false;
  755. }
  756. $ghsInfo = GhsClass::getById($ghsId, true);
  757. $shopId = $ghsInfo->shopId ?? 0;
  758. $customId = $ghsInfo->customId ?? 0;
  759. $customInfo = CustomClass::getById($customId, true);
  760. $customName = $customInfo->name ?? '';
  761. $shopInfo = ShopClass::getById($shopId, true);
  762. $ptStyle = $shopInfo->ptStyle ?? 0;
  763. $wxBase = WxOpenClass::getWxBase();
  764. $wx = $wxBase[$ptStyle] ?? [];
  765. $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
  766. $shortTempId = 'OPENTM411530050';
  767. $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
  768. if (empty($tempId)) {
  769. return false;
  770. }
  771. $adminList = ShopAdminClass::getRemainAdmin($shopInfo);
  772. if (empty($adminList)) {
  773. return false;
  774. }
  775. foreach ($adminList as $admin) {
  776. $openId = isset($admin['openId']) ? $admin['openId'] : '';
  777. if (empty($openId)) {
  778. continue;
  779. }
  780. $data = [
  781. "touser" => $openId,
  782. "template_id" => $tempId,
  783. "url" => Yii::$app->params['ghsDomain'],
  784. "data" => [
  785. "first" => ["value" => "有新客户充值", "color" => "#173177"],
  786. "keyword1" => ["value" => $customName, "color" => "#173177"],
  787. "keyword2" => ["value" => $customId, "color" => "#D52B4D"],
  788. "keyword3" => ["value" => $amount, "color" => "#173177"],
  789. "remark" => ["value" => '点击查看详情', "color" => "#173177"]
  790. ]
  791. ];
  792. $data['miniprogram']['appid'] = $wx['miniAppId'];
  793. $data['miniprogram']['pagepath'] = 'admin/hb/rechargeList';
  794. wxUtil::sendTaskInform($data, $wx, $ptStyle);
  795. }
  796. }
  797. }