RoutineTemplate.php 9.5 KB

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