RoutineTemplateJob.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 app\jobs
  20. */
  21. class RoutineTemplateJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * 确认收货
  26. * @param $openid
  27. * @param $order
  28. * @param $title
  29. * @return bool
  30. */
  31. public function sendOrderTakeOver($openid, $order, $title)
  32. {
  33. return $this->sendTemplate('OREDER_TAKEVER', $openid, [
  34. 'thing1' => $order['order_id'],
  35. 'thing2' => $title,
  36. 'date5' => date('Y-m-d H:i:s', time()),
  37. ], '/pages/users/order_details/index?order_id=' . $order['order_id']);
  38. }
  39. /**
  40. * @param $openid
  41. * @param $order
  42. * @param $storeTitle
  43. * @param int $isGive 0 = 同城配送, 1 = 快递发货
  44. * @return bool
  45. */
  46. public function sendOrderPostage($openid, $order, $storeTitle, int $isGive = 0)
  47. {
  48. if ($isGive) {//快递发货
  49. return $this->sendTemplate('ORDER_DELIVER_SUCCESS', $openid, [
  50. 'character_string2' => $order['delivery_id'],
  51. 'thing1' => $order['delivery_name'],
  52. 'time3' => date('Y-m-d H:i:s', time()),
  53. 'thing5' => $storeTitle,
  54. ], '/pages/users/order_details/index?order_id=' . $order['order_id']);
  55. } else {//同城配送
  56. return $this->sendTemplate('ORDER_POSTAGE_SUCCESS', $openid, [
  57. 'thing8' => $storeTitle,
  58. 'character_string1' => $order['order_id'],
  59. 'name4' => $order['delivery_name'],
  60. 'phone_number10' => $order['delivery_id']
  61. ], '/pages/users/order_details/index?order_id=' . $order['order_id']);
  62. }
  63. }
  64. /**
  65. * 充值金额退款
  66. * @param $UserRecharge
  67. * @param $refund_price
  68. * @return bool
  69. */
  70. public function sendRechargeSuccess($openid, $UserRecharge, $now_money)
  71. {
  72. return $this->sendTemplate('RECHARGE_SUCCESS', $openid, [
  73. 'character_string1' => $UserRecharge['order_id'],
  74. 'amount3' => $UserRecharge['price'],
  75. 'amount4' => $now_money,
  76. 'date5' => date('Y-m-d H:i:s', time()),
  77. ], '/pages/user_bill/index?type=2');
  78. }
  79. /**
  80. * 订单退款成功发送消息
  81. * @param string $openid
  82. * @param array $order
  83. * @return bool
  84. */
  85. public function sendOrderRefundSuccess($openid, $order, $storeTitle)
  86. {
  87. return $this->sendTemplate('ORDER_REFUND', $openid, [
  88. 'thing1' => '已成功退款',
  89. 'thing2' => $storeTitle,
  90. 'amount3' => $order['pay_price'],
  91. 'character_string6' => $order['order_id']
  92. ], '/pages/users/order_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
  93. }
  94. /**
  95. * 订单退款失败
  96. * @param string $openid
  97. * @param $order
  98. * @return bool
  99. */
  100. public function sendOrderRefundFail($openid, $order, $storeTitle)
  101. {
  102. return $this->sendTemplate('ORDER_REFUND', $openid, [
  103. 'thing1' => '退款失败',
  104. 'thing2' => $storeTitle,
  105. 'amount3' => $order['pay_price'],
  106. 'character_string6' => $order['order_id']
  107. ], '/pages/users/order_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
  108. }
  109. /**
  110. * 用户申请退款给管理员发送消息
  111. * @param array $order
  112. * @param string $refundReasonWap
  113. * @param array $adminList
  114. */
  115. public function sendOrderRefundStatus($openid, $order)
  116. {
  117. $data['character_string4'] = $order['order_id'];
  118. $data['date5'] = date('Y-m-d H:i:s', time());
  119. $data['amount2'] = $order['pay_price'];
  120. $data['phrase7'] = '申请退款中';
  121. $data['thing8'] = '请及时处理';
  122. return $this->sendTemplate('ORDER_REFUND_STATUS', $openid, $data);
  123. }
  124. /**
  125. * 砍价成功通知
  126. * @param array $bargain
  127. * @param array $bargainUser
  128. * @param int $bargainUserId
  129. * @return bool
  130. */
  131. public function sendBargainSuccess($openid, $bargain = [], $bargainUser = [], $bargainUserId = 0)
  132. {
  133. $data['thing1'] = $bargain['title'];
  134. $data['amount2'] = $bargain['min_price'];
  135. $data['thing3'] = '恭喜您,已经砍到最低价了';
  136. return $this->sendTemplate('BARGAIN_SUCCESS', $openid, $data, '/pages/activity/user_goods_bargain_list/index?id=' . $bargain['id'] . '&bargain=' . $bargainUserId);
  137. }
  138. /**
  139. * 订单支付成功发送模板消息
  140. * @param $openidf
  141. * @param $pay_price
  142. * @param $orderId
  143. * @param $payTime
  144. * @return bool|void
  145. */
  146. public function sendOrderSuccess($openid, $pay_price, $orderId)
  147. {
  148. if ($orderId == '') return true;
  149. $data['character_string1'] = $orderId;
  150. $data['amount2'] = $pay_price . '元';
  151. $data['date3'] = date('Y-m-d H:i:s', time());
  152. return $this->sendTemplate('ORDER_PAY_SUCCESS', $openid, $data, '/pages/users/order_details/index?order_id=' . $orderId);
  153. }
  154. /**
  155. * 会员订单支付成功发送消息
  156. * @param $openid
  157. * @param $pay_price
  158. * @param $orderId
  159. * @return bool
  160. */
  161. public function sendMemberOrderSuccess($openid, $pay_price, $orderId)
  162. {
  163. if ($orderId == '') return true;
  164. $data['character_string1'] = $orderId;
  165. $data['amount2'] = $pay_price . '元';
  166. $data['date3'] = date('Y-m-d H:i:s', time());
  167. return $this->sendTemplate('ORDER_PAY_SUCCESS', $openid, $data, '/pages/annex/vip_paid/index');
  168. }
  169. /**
  170. * 提现失败
  171. * @param $openid
  172. * @param $msg
  173. * @param $extract_number
  174. * @param $extract_type
  175. * @return bool
  176. */
  177. public function sendExtractFail($openid, $msg, $extract_number, $nickname)
  178. {
  179. return $this->sendTemplate('USER_EXTRACT', $openid, [
  180. 'thing1' => '提现失败:' . $msg,
  181. 'amount2' => $extract_number . '元',
  182. 'thing3' => $nickname,
  183. 'date4' => date('Y-m-d H:i:s', time())
  184. ], '/pages/users/user_spread_money/index?type=2');
  185. }
  186. /**
  187. * 提现成功
  188. * @param $openid
  189. * @param $extract_number
  190. * @param $nickname
  191. * @return bool
  192. */
  193. public function sendExtractSuccess($openid, $extract_number, $nickname)
  194. {
  195. return $this->sendTemplate('USER_EXTRACT', $openid, [
  196. 'thing1' => '提现成功',
  197. 'amount2' => $extract_number . '元',
  198. 'thing3' => $nickname,
  199. 'date4' => date('Y-m-d H:i:s', time())
  200. ], '/pages/users/user_spread_money/index?type=2');
  201. }
  202. /**
  203. * 拼团成功通知
  204. * @param $uid
  205. * @param $pinkTitle
  206. * @param $nickname
  207. * @param $pinkTime
  208. * @param $count
  209. * @return bool
  210. */
  211. public function sendPinkSuccess($openid, $pinkTitle, $nickname, $pinkTime, $count, string $link = '')
  212. {
  213. return $this->sendTemplate('PINK_TRUE', $openid, [
  214. 'thing1' => $pinkTitle,
  215. 'name3' => $nickname,
  216. 'date5' => date('Y-m-d H:i:s', $pinkTime),
  217. 'number2' => $count
  218. ], $link);
  219. }
  220. /**
  221. * 拼团状态通知
  222. * @param $openid
  223. * @param $pinkTitle
  224. * @param $count
  225. * @param $remarks
  226. * @return bool
  227. */
  228. public function sendPinkFail($openid, $pinkTitle, $count, $remarks, $link)
  229. {
  230. return $this->sendTemplate('PINK_STATUS', $openid, [
  231. 'thing2' => $pinkTitle,
  232. 'thing1' => $count,
  233. 'thing3' => $remarks
  234. ], $link);
  235. }
  236. /**
  237. * 赠送积分消息提醒
  238. * @param $openid
  239. * @param $order
  240. * @param $storeTitle
  241. * @param $gainIntegral
  242. * @param $integral
  243. * @return bool
  244. */
  245. public function sendUserIntegral($openid, $order, $storeTitle, $gainIntegral, $integral)
  246. {
  247. if (!$order || !$openid) return true;
  248. if (is_string($order['cart_id']))
  249. $order['cart_id'] = json_decode($order['cart_id'], true);
  250. return $this->sendTemplate('INTEGRAL_ACCOUT', $openid, [
  251. 'character_string2' => $order['order_id'],
  252. 'thing3' => $storeTitle,
  253. 'amount4' => $order['pay_price'],
  254. 'number5' => $gainIntegral,
  255. 'number6' => $integral
  256. ], '/pages/users/user_integral/index');
  257. }
  258. /**
  259. * 发送模板消息
  260. * @param string $TempCode 模板消息常量名称
  261. * @param int $openid 用户openid
  262. * @param array $data 模板内容
  263. * @param string $link 跳转链接
  264. * @return bool
  265. */
  266. public function sendTemplate(string $tempCode, $openid, array $data, string $link = '')
  267. {
  268. try {
  269. if (!$openid) return true;
  270. $template = new Template('subscribe');
  271. $res = $template->to($openid)->url($link)->send($tempCode, $data);
  272. if (!$res) {
  273. Log::error('订阅消息发送失败,原因:' . $template->getError() . '----参数:' . json_encode(compact('tempCode', 'openid', 'data', 'link')));
  274. }
  275. return true;
  276. } catch (\Exception $e) {
  277. Log::error('订阅消息发送失败,原因:' . $e->getMessage() . '----参数:' . json_encode(compact('tempCode', 'openid', 'data', 'link')));
  278. return true;
  279. }
  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. }