RoutineTemplate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. namespace app\models\routine;
  3. use crmeb\traits\ModelTrait;
  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. use ModelTrait;
  26. /**
  27. * 确认收货
  28. * @param $order
  29. * @param $title
  30. * @return bool
  31. */
  32. public static function sendOrderTakeOver($order, $title)
  33. {
  34. return self::sendOut('OREDER_TAKEVER', $order['uid'], [
  35. 'thing1' => $order['order_id'],
  36. 'thing2' => $title,
  37. 'date5' => date('Y-m-d H:i:s', time()),
  38. ], '/pages/order_details/index?order_id=' . $order['order_id']);
  39. }
  40. /**
  41. * 送货和发货
  42. * @param $order
  43. * @param int $isGive 0 = 同城配送, 1 = 快递发货
  44. * @return bool
  45. */
  46. public static function sendOrderPostage($order, $isGive = 0)
  47. {
  48. if (is_string($order['cart_id']))
  49. $order['cart_id'] = json_decode($order['cart_id'], true);
  50. $storeTitle = StoreOrder::getProductTitle($order['cart_id']);
  51. $storeTitle = StoreOrder::getSubstrUTf8($storeTitle, 20, 'UTF-8', '');
  52. if ($isGive) {//快递发货
  53. return self::sendOut('ORDER_DELIVER_SUCCESS', $order['uid'], [
  54. 'character_string2' => $order['delivery_id'],
  55. 'thing1' => $order['delivery_name'],
  56. 'time3' => date('Y-m-d H:i:s', time()),
  57. 'thing5' => $storeTitle,
  58. ], '/pages/order_details/index?order_id=' . $order['order_id']);
  59. } else {//同城配送
  60. return self::sendOut('ORDER_POSTAGE_SUCCESS', $order['uid'], [
  61. 'thing8' => $storeTitle,
  62. 'character_string1' => $order['order_id'],
  63. 'name4' => $order['delivery_name'],
  64. 'phone_number10' => $order['delivery_id']
  65. ], '/pages/order_details/index?order_id=' . $order['order_id']);
  66. }
  67. }
  68. /**
  69. * 充值金额退款
  70. * @param $UserRecharge
  71. * @param $refund_price
  72. * @return bool
  73. */
  74. public static function sendRechargeSuccess($UserRecharge, $refund_price)
  75. {
  76. return self::sendOut('ORDER_REFUND', $UserRecharge['uid'], [
  77. 'thing1' => '亲,您充值的金额已退款,本次退款' . $refund_price . '金额',
  78. 'thing2' => '余额充值退款',
  79. 'amount3' => $UserRecharge['price'],
  80. 'character_string6' => $UserRecharge['order_id'],
  81. ], '/pages/user_bill/index?type=2');
  82. }
  83. /**
  84. * 订单退款成功发送消息
  85. * @param array $order
  86. * @return bool
  87. */
  88. public static function sendOrderRefundSuccess($order = array())
  89. {
  90. if (!$order) return false;
  91. if (is_string($order['cart_id']))
  92. $order['cart_id'] = json_decode($order['cart_id'], true);
  93. $storeTitle = StoreOrder::getProductTitle($order['cart_id']);
  94. $storeTitle = StoreOrder::getSubstrUTf8($storeTitle, 20, 'UTF-8', '');
  95. return self::sendOut('ORDER_REFUND', $order['uid'], [
  96. 'thing1' => '已成功退款',
  97. 'thing2' => $storeTitle,
  98. 'amount3' => $order['pay_price'],
  99. 'character_string6' => $order['order_id']
  100. ], '/pages/order_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
  101. }
  102. /**
  103. * 订单退款失败
  104. * @param $order
  105. * @return bool
  106. */
  107. public static function sendOrderRefundFail($order, $storeTitle)
  108. {
  109. return self::sendOut('ORDER_REFUND', $order['uid'], [
  110. 'thing1' => '退款失败',
  111. 'thing2' => $storeTitle,
  112. 'amount3' => $order['pay_price'],
  113. 'character_string6' => $order['order_id']
  114. ], '/pages/order_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
  115. }
  116. /**
  117. * 用户申请退款给管理员发送消息
  118. * @param array $order
  119. * @param string $refundReasonWap
  120. * @param array $adminList
  121. */
  122. public static function sendOrderRefundStatus($order)
  123. {
  124. $data['character_string4'] = $order['order_id'];
  125. $data['date5'] = date('Y-m-d H:i:s', time());
  126. $data['amount2'] = $order['pay_price'];
  127. $data['phrase7'] = '申请退款中';
  128. $data['thing8'] = '请及时处理';
  129. $kefuIds = ServiceModel::where('notify', 1)->column('uid', 'uid');
  130. foreach ($kefuIds as $uid) {
  131. self::sendOut('ORDER_REFUND_STATUS', $uid, $data);
  132. }
  133. }
  134. /**
  135. * 砍价成功通知
  136. * @param array $bargain
  137. * @param array $bargainUser
  138. * @param int $bargainUserId
  139. * @return bool
  140. */
  141. public static function sendBargainSuccess($bargain = array(), $bargainUser = array(), $bargainUserId = 0)
  142. {
  143. $data['thing1'] = $bargain['title'];
  144. $data['amount2'] = $bargainUser['min_price'];
  145. $data['thing3'] = '恭喜您,已经砍到最低价了';
  146. return self::sendOut('BARGAIN_SUCCESS', $bargainUser['uid'], $data, '/pages/activity/user_goods_bargain_list/index');
  147. }
  148. /**
  149. * 订单支付成功发送模板消息
  150. * @param $uid
  151. * @param $pay_price
  152. * @param $orderId
  153. * @param $payTime
  154. * @return bool|void
  155. */
  156. public static function sendOrderSuccess($uid, $pay_price, $orderId)
  157. {
  158. if ($orderId == '') return;
  159. $data['character_string1'] = $orderId;
  160. $data['amount2'] = $pay_price . '元';
  161. $data['date3'] = date('Y-m-d H:i:s', time());
  162. return self::sendOut('ORDER_PAY_SUCCESS', $uid, $data, '/pages/order_details/index?order_id=' . $orderId);
  163. }
  164. /**
  165. *提现失败
  166. * @param $uid
  167. * @param $msg
  168. * @param $extract_number
  169. * @param $extract_type
  170. * @return bool
  171. */
  172. public static function sendExtractFail($uid, $msg, $extract_number, $nickname)
  173. {
  174. return self::sendOut('USER_EXTRACT', $uid, [
  175. 'thing1' => '提现失败:' . $msg,
  176. 'amount2' => $extract_number . '元',
  177. 'thing3' => $nickname,
  178. 'date4' => date('Y-m-d H:i:s', time())
  179. ], '/pages/user_spread_money/index?type=2');
  180. }
  181. /**
  182. * 提现成功
  183. * @param $uid
  184. * @param $extract_number
  185. * @param $nickname
  186. * @return bool
  187. */
  188. public static function sendExtractSuccess($uid, $extract_number, $nickname)
  189. {
  190. return self::sendOut('USER_EXTRACT', $uid, [
  191. 'thing1' => '提现成功',
  192. 'amount2' => $extract_number . '元',
  193. 'thing3' => $nickname,
  194. 'date4' => date('Y-m-d H:i:s', time())
  195. ], '/pages/user_spread_money/index?type=2');
  196. }
  197. /**
  198. * 拼团成功通知
  199. * @param $uid
  200. * @param $pinkTitle
  201. * @param $nickname
  202. * @param $pinkTime
  203. * @param $count
  204. * @return bool
  205. */
  206. public static function sendPinkSuccess($uid, $pinkTitle, $nickname, $pinkTime, $count, string $link = '')
  207. {
  208. return self::sendOut('PINK_TRUE', $uid, [
  209. 'thing1' => StoreOrder::getSubstrUTf8($pinkTitle, 20, 'UTF-8', ''),
  210. 'name3' => $nickname,
  211. 'date5' => date('Y-m-d H:i:s', $pinkTime),
  212. 'number2' => $count
  213. ], $link);
  214. }
  215. /**
  216. * 拼团状态通知
  217. * @param $uid
  218. * @param $pinkTitle
  219. * @param $count
  220. * @param $remarks
  221. * @return bool
  222. */
  223. public static function sendPinkFail($uid, $pinkTitle, $count, $remarks, $link)
  224. {
  225. return self::sendOut('PINK_STATUS', $uid, [
  226. 'thing2' => StoreOrder::getSubstrUTf8($pinkTitle, 20, 'UTF-8', ''),
  227. 'thing1' => $count,
  228. 'thing3' => $remarks
  229. ], $link);
  230. }
  231. /**
  232. * 助力成功通知
  233. * @param $uid
  234. * @param $assistanceTitle
  235. * @param $nickname
  236. * @param $assistanceTime
  237. * @param $count
  238. * @return bool
  239. */
  240. public static function sendAssistanceSuccess($uid, $assistanceTitle, $nickname, $assistanceTime, $count, string $link = '')
  241. {
  242. return self::sendOut('PINK_TRUE', $uid, [
  243. 'thing1' => StoreOrder::getSubstrUTf8($assistanceTitle, 20, 'UTF-8', ''),
  244. 'name3' => $nickname,
  245. 'date5' => date('Y-m-d H:i:s', $assistanceTime),
  246. 'number2' => $count
  247. ], $link);
  248. }
  249. /**
  250. * 助力状态通知
  251. * @param $uid
  252. * @param $assistanceTitle
  253. * @param $count
  254. * @param $remarks
  255. * @return bool
  256. */
  257. public static function sendAssistanceFail($uid, $assistanceTitle, $count, $remarks, $link)
  258. {
  259. return self::sendOut('PINK_STATUS', $uid, [
  260. 'thing2' => StoreOrder::getSubstrUTf8($assistanceTitle, 20, 'UTF-8', ''),
  261. 'thing1' => $count,
  262. 'thing3' => $remarks
  263. ], $link);
  264. }
  265. /**
  266. * 赠送积分消息提醒
  267. * @param $uid
  268. * @param $order
  269. * @param $gainIntegral
  270. * @param $integral
  271. * @return bool
  272. */
  273. public static function sendUserIntegral($uid, $order, $gainIntegral, $integral)
  274. {
  275. if (!$order) return false;
  276. if (is_string($order['cart_id']))
  277. $order['cart_id'] = json_decode($order['cart_id'], true);
  278. $storeTitle = StoreOrder::getProductTitle($order['cart_id']);
  279. $storeTitle = StoreOrder::getSubstrUTf8($storeTitle, 20);
  280. return self::sendOut('INTEGRAL_ACCOUT', $uid, [
  281. 'character_string2' => $order['order_id'],
  282. 'thing3' => $storeTitle,
  283. 'amount4' => $order['pay_price'],
  284. 'number5' => $gainIntegral,
  285. 'number6' => $integral
  286. ], '/pages/user_bill/index?type=2');
  287. }
  288. /**
  289. * 发送模板消息
  290. * @param string $TempCode 模板消息常量名称
  291. * @param int $uid 用户uid
  292. * @param array $data 模板内容
  293. * @param string $link 跳转链接
  294. * @return bool
  295. */
  296. public static function sendOut(string $tempCode, $uid, array $data, string $link = '')
  297. {
  298. try {
  299. $openid = WechatUser::uidToOpenid($uid);
  300. if (!$openid) return false;
  301. $template = new Template('subscribe');
  302. return $template->to($openid)->url($link)->send($tempCode, $data);
  303. } catch (\Exception $e) {
  304. return false;
  305. }
  306. }
  307. /**
  308. * 获取系统分页数据 分类
  309. * @param array $where
  310. * @return array
  311. */
  312. public static function systemPage($where = array())
  313. {
  314. $model = self::where('type', 0);
  315. if ($where['name'] !== '') $model = $model->where('name', 'LIKE', "%$where[name]%");
  316. if ($where['status'] !== '') $model = $model->where('status', $where['status']);
  317. $count = $model->count();
  318. $list = $model->page((int)$where['page'], (int)$where['limit'])
  319. ->select()
  320. ->each(function ($item) {
  321. if ($item['content']) $item['content'] = explode("\n", $item['content']);
  322. });
  323. return compact('count', 'list');
  324. }
  325. }