RoutineTemplateJob.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs;
  12. use crmeb\basic\BaseJobs;
  13. use crmeb\services\template\Template;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. /**
  17. * 小程序模板消息消息队列
  18. * Class RoutineTemplateJob
  19. * @package crmeb\jobs
  20. */
  21. class RoutineTemplateJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * 发送模板消息
  26. * @param string $TempCode 模板消息常量名称
  27. * @param int $openid 用户openid
  28. * @param array $data 模板内容
  29. * @param string $link 跳转链接
  30. * @return bool
  31. */
  32. public function sendTemplate(string $tempCode, $openid, array $data, string $link = '')
  33. {
  34. try {
  35. if (!$openid) return true;
  36. $template = new Template('subscribe');
  37. $res = $template->to($openid)->url($link)->send($tempCode, $data);
  38. if (!$res) {
  39. Log::error('订阅消息发送失败,原因:' . $template->getError() . '----参数:' . json_encode(compact('tempCode', 'openid', 'data', 'link')));
  40. }
  41. return true;
  42. } catch (\Exception $e) {
  43. Log::error('订阅消息发送失败,原因:' . $e->getMessage() . '----参数:' . json_encode(compact('tempCode', 'openid', 'data', 'link')));
  44. return true;
  45. }
  46. }
  47. /**
  48. * 确认收货
  49. * @param $openid
  50. * @param $order
  51. * @param $title
  52. * @return bool
  53. */
  54. public function sendOrderTakeOver($openid, $order, $title)
  55. {
  56. return $this->sendTemplate('ORDER_TAKE', $openid, [
  57. 'thing1' => $order['order_id'],
  58. 'thing2' => $title,
  59. 'date5' => date('Y-m-d H:i:s', time()),
  60. ], '/pages/users/order_details/index?order_id=' . $order['order_id']);
  61. }
  62. /**
  63. * @param $openid
  64. * @param $order
  65. * @param $storeTitle
  66. * @param int $isGive 0 = 同城配送, 1 = 快递发货
  67. * @return bool
  68. */
  69. public function sendOrderPostage($openid, $order, $storeTitle, int $isGive = 0)
  70. {
  71. if ($isGive) {//快递发货
  72. return $this->sendTemplate('ORDER_DELIVER_SUCCESS', $openid, [
  73. 'character_string2' => $order['delivery_id'],
  74. 'thing1' => $order['delivery_name'],
  75. 'time3' => date('Y-m-d H:i:s', time()),
  76. 'thing5' => $storeTitle,
  77. ], '/pages/users/order_details/index?order_id=' . $order['order_id']);
  78. } else {//同城配送
  79. return $this->sendTemplate('ORDER_POSTAGE_SUCCESS', $openid, [
  80. 'thing8' => $storeTitle,
  81. 'character_string1' => $order['order_id'],
  82. 'name4' => $order['delivery_name'],
  83. 'phone_number10' => $order['delivery_id']
  84. ], '/pages/users/order_details/index?order_id=' . $order['order_id']);
  85. }
  86. }
  87. /**
  88. * 充值金额退款
  89. * @param $UserRecharge
  90. * @param $refund_price
  91. * @return bool
  92. */
  93. public function sendRechargeSuccess($openid, $UserRecharge, $now_money)
  94. {
  95. return $this->sendTemplate('RECHARGE_SUCCESS', $openid, [
  96. 'character_string1' => $UserRecharge['order_id'],
  97. 'amount3' => $UserRecharge['price'],
  98. 'amount4' => $now_money,
  99. 'date5' => date('Y-m-d H:i:s', time()),
  100. ], '/pages/user_bill/index?type=2');
  101. }
  102. /**
  103. * 订单退款成功发送消息
  104. * @param string $openid
  105. * @param array $order
  106. * @return bool
  107. */
  108. public function sendOrderRefundSuccess($openid, $order, $storeTitle)
  109. {
  110. return $this->sendTemplate('ORDER_REFUND', $openid, [
  111. 'thing1' => '已成功退款',
  112. 'thing2' => $storeTitle,
  113. 'amount3' => $order['pay_price'],
  114. 'character_string6' => $order['order_id']
  115. ], '/pages/users/order_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
  116. }
  117. /**
  118. * 订单退款失败
  119. * @param string $openid
  120. * @param $order
  121. * @return bool
  122. */
  123. public function sendOrderRefundFail($openid, $order, $storeTitle)
  124. {
  125. return $this->sendTemplate('ORDER_REFUND', $openid, [
  126. 'thing1' => '退款失败',
  127. 'thing2' => $storeTitle,
  128. 'amount3' => $order['pay_price'],
  129. 'character_string6' => $order['order_id']
  130. ], '/pages/users/order_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
  131. }
  132. /**
  133. * 用户申请退款给管理员发送消息
  134. * @param array $order
  135. * @param string $refundReasonWap
  136. * @param array $adminList
  137. */
  138. public function sendOrderRefundStatus($openid, $order)
  139. {
  140. $data['character_string4'] = $order['order_id'];
  141. $data['date5'] = date('Y-m-d H:i:s', time());
  142. $data['amount2'] = $order['pay_price'];
  143. $data['phrase7'] = '申请退款中';
  144. $data['thing8'] = '请及时处理';
  145. return $this->sendTemplate('ORDER_REFUND_STATUS', $openid, $data);
  146. }
  147. /**
  148. * 砍价成功通知
  149. * @param array $bargain
  150. * @param array $bargainUser
  151. * @param int $bargainUserId
  152. * @return bool
  153. */
  154. public function sendBargainSuccess($openid, $bargain = [], $bargainUser = [], $bargainUserId = 0)
  155. {
  156. $data['thing1'] = $bargain['title'];
  157. $data['amount2'] = $bargain['min_price'];
  158. $data['thing3'] = '恭喜您,已经砍到最低价了';
  159. return $this->sendTemplate('BARGAIN_SUCCESS', $openid, $data, '/pages/activity/user_goods_bargain_list/index?id=' . $bargain['id'] . '&bargain=' . $bargainUserId);
  160. }
  161. /**
  162. * 订单支付成功发送模板消息
  163. * @param $openidf
  164. * @param $pay_price
  165. * @param $orderId
  166. * @param $payTime
  167. * @return bool|void
  168. */
  169. public function sendOrderSuccess($openid, $pay_price, $orderId)
  170. {
  171. if ($orderId == '') return true;
  172. $data['character_string1'] = $orderId;
  173. $data['amount2'] = $pay_price . '元';
  174. $data['date3'] = date('Y-m-d H:i:s', time());
  175. return $this->sendTemplate('ORDER_PAY_SUCCESS', $openid, $data, '/pages/users/order_details/index?order_id=' . $orderId);
  176. }
  177. /**
  178. * 会员订单支付成功发送消息
  179. * @param $openid
  180. * @param $pay_price
  181. * @param $orderId
  182. * @return bool
  183. */
  184. public function sendMemberOrderSuccess($openid, $pay_price, $orderId)
  185. {
  186. if ($orderId == '') return true;
  187. $data['character_string1'] = $orderId;
  188. $data['amount2'] = $pay_price . '元';
  189. $data['date3'] = date('Y-m-d H:i:s', time());
  190. return $this->sendTemplate('ORDER_PAY_SUCCESS', $openid, $data, '/pages/annex/vip_paid/index');
  191. }
  192. /**
  193. * 提现失败
  194. * @param $openid
  195. * @param $msg
  196. * @param $extract_number
  197. * @param $extract_type
  198. * @return bool
  199. */
  200. public function sendExtractFail($openid, $msg, $extract_number, $nickname)
  201. {
  202. return $this->sendTemplate('USER_EXTRACT', $openid, [
  203. 'thing1' => '提现失败:' . $msg,
  204. 'amount2' => $extract_number . '元',
  205. 'thing3' => $nickname,
  206. 'date4' => date('Y-m-d H:i:s', time())
  207. ], '/pages/users/user_spread_money/index?type=2');
  208. }
  209. /**
  210. * 提现成功
  211. * @param $openid
  212. * @param $extract_number
  213. * @param $nickname
  214. * @return bool
  215. */
  216. public function sendExtractSuccess($openid, $extract_number, $nickname)
  217. {
  218. return $this->sendTemplate('USER_EXTRACT', $openid, [
  219. 'thing1' => '提现成功',
  220. 'amount2' => $extract_number . '元',
  221. 'thing3' => $nickname,
  222. 'date4' => date('Y-m-d H:i:s', time())
  223. ], '/pages/users/user_spread_money/index?type=2');
  224. }
  225. /**
  226. * 拼团成功通知
  227. * @param $uid
  228. * @param $pinkTitle
  229. * @param $nickname
  230. * @param $pinkTime
  231. * @param $count
  232. * @return bool
  233. */
  234. public function sendPinkSuccess($openid, $pinkTitle, $nickname, $pinkTime, $count, string $link = '')
  235. {
  236. return $this->sendTemplate('PINK_TRUE', $openid, [
  237. 'thing1' => $pinkTitle,
  238. 'name3' => $nickname,
  239. 'date5' => date('Y-m-d H:i:s', $pinkTime),
  240. 'number2' => $count
  241. ], $link);
  242. }
  243. /**
  244. * 拼团状态通知
  245. * @param $openid
  246. * @param $pinkTitle
  247. * @param $count
  248. * @param $remarks
  249. * @return bool
  250. */
  251. public function sendPinkFail($openid, $pinkTitle, $count, $remarks, $link)
  252. {
  253. return $this->sendTemplate('PINK_STATUS', $openid, [
  254. 'thing2' => $pinkTitle,
  255. 'thing1' => $count,
  256. 'thing3' => $remarks
  257. ], $link);
  258. }
  259. /**
  260. * 赠送积分消息提醒
  261. * @param $openid
  262. * @param $order
  263. * @param $storeTitle
  264. * @param $gainIntegral
  265. * @param $integral
  266. * @return bool
  267. */
  268. public function sendUserIntegral($openid, $order, $storeTitle, $gainIntegral, $integral)
  269. {
  270. if (!$order || !$openid) return true;
  271. if (is_string($order['cart_id']))
  272. $order['cart_id'] = json_decode($order['cart_id'], true);
  273. return $this->sendTemplate('INTEGRAL_ACCOUT', $openid, [
  274. 'character_string2' => $order['order_id'],
  275. 'thing3' => $storeTitle,
  276. 'amount4' => $order['pay_price'],
  277. 'number5' => $gainIntegral,
  278. 'number6' => $integral
  279. ], '/pages/users/user_integral/index');
  280. }
  281. /**
  282. * 获得推广佣金发送提醒
  283. * @param string $openid
  284. * @param string $brokeragePrice
  285. * @param string $goods_name
  286. * @return bool
  287. */
  288. public function sendOrderBrokerageSuccess(string $openid, string $brokeragePrice, string $goods_name)
  289. {
  290. return $this->sendTemplate('ORDER_BROKERAGE', $openid, [
  291. 'thing2' => $goods_name,
  292. 'amount4' => $brokeragePrice . '元',
  293. 'time1' => date('Y-m-d H:i:s', time())
  294. ], '/pages/users/user_spread_user/index');
  295. }
  296. /**
  297. * 绑定推广关系发送消息提醒
  298. * @param string $openid
  299. * @param string $userName
  300. * @return bool|mixed
  301. */
  302. public function sendBindSpreadUidSuccess(string $openid, string $userName)
  303. {
  304. return $this->sendTemplate('BIND_SPREAD_UID', $openid, [
  305. 'name3' => $userName . "加入您的团队",
  306. 'date4' => date('Y-m-d H:i:s', time())
  307. ], '/pages/users/user_spread_user/index');
  308. }
  309. }