RoutineTemplateListService.php 11 KB

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