WxMessageClass.php 40 KB

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