Inform.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 服务通知(微信公众号的模板消息)
  7. */
  8. namespace app\allwin\widget;
  9. use app\common\facade\WechatMp;
  10. use Exception;
  11. class Inform{
  12. /**
  13. * 买单通知
  14. * @param array $param
  15. * $param['uid'] = 用户ID;
  16. * $param['store_name'] = 好店名称;
  17. * $param['amount'] = 付款金额;
  18. * $param['order_no'] = 订单号;
  19. * $param['miniapp_id'] = 所属应用ID;
  20. * $param['tplmsg'] = 模板ID;
  21. * @return void
  22. */
  23. public static function order(array $param){
  24. $uid[] = $param['uid'];
  25. //给好店收银员发通知
  26. $worker = model('StoreWorker')->where(['store_id' => $param['store_id'],'is_cashier' => 1])->field('uid')->select()->toArray();
  27. if(!empty($worker)){
  28. $uid = array_merge(array_column($worker,'uid'),$uid);
  29. }
  30. $user = model('SystemUser')->where(['id' => $uid])->field('official_uid')->select();
  31. if(empty($user)){
  32. return;
  33. }
  34. //用户类别
  35. $wechat = WechatMp::isTypes($param['miniapp_id']);
  36. if(empty($wechat)){
  37. return;
  38. }
  39. try {
  40. $wechat = $wechat->template_message;
  41. foreach ($user as $value) {
  42. if(!empty($value['official_uid'])){
  43. $wechat->send([
  44. 'touser' => $value['official_uid'],
  45. 'template_id' => $param['tplmsg'],
  46. 'data' => [
  47. 'first' => '微信买单已到账',
  48. 'keyword1' => $param['order_no'], //订单编号
  49. 'keyword2' => ['value'=>'¥'.$param['amount'],'color' => '#FF0000'],
  50. 'keyword3' => $param['store_name'], //消费门店
  51. 'keyword4' => date('Y-m-d H:i:s'), //消费时间
  52. ],
  53. ]);
  54. }
  55. }
  56. }catch (Exception $e) {
  57. return;
  58. }
  59. }
  60. }