MessageMp.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. use app\samos\wechat\MiniProgram;
  5. class MessageMp extends Model
  6. {
  7. protected $connection = 'mysql';
  8. protected $pk = 'id';
  9. protected $name = 'message';
  10. public static function itional_pay($orderInfo)
  11. {
  12. $orderInfo['pay_time'] = time_format($orderInfo['pay_time']);
  13. $messagetpl = Config::getconfig('messagetpl');
  14. $param['template_id'] = $messagetpl['pay_tpl'];
  15. $param['uuid'] = OrderStaff::getuuid($orderInfo['id']);
  16. $param['uid'] = UuidRelation::getuid($param['uuid']);
  17. $param['title'] = '客户已支付尾款通知';
  18. $param['pages'] = '/pagesA/my/admintechnical/orderDetail';
  19. $param['query'] = 'id=' . $orderInfo['id'];
  20. $param['content'] = '客户已支付尾款通知';
  21. $param['data']['character_string1']['value'] = $orderInfo['order_num_alias'];
  22. $param['data']['thing3']['value'] = mb_substr($orderInfo['pay_subject'], 0, 20);
  23. $param['data']['time5']['value'] = $orderInfo['pay_time'];
  24. $param['data']['amount4']['value'] = $orderInfo['total'];
  25. if (self::send($param)) {
  26. self::sendmptplmessage($param);
  27. };
  28. }
  29. //派单
  30. public static function distribution($uuid, $orderInfo)
  31. {
  32. $orderInfo['pay_time'] = time_format($orderInfo['pay_time']);
  33. $messagetpl = Config::getconfig('messagetpl');
  34. $param['template_id'] = $messagetpl['technical_tpl'];
  35. $param['uuid'] = $uuid;
  36. $param['uid'] = UuidRelation::getuid($param['uuid']);
  37. $param['title'] = '平台派单通知';
  38. $param['content'] = '您有一个新的平台订单,请及时处理';
  39. $param['data']['character_string2']['value'] = $orderInfo['order_num_alias'];
  40. $param['data']['thing8']['value'] = mb_substr($orderInfo['pay_subject'], 0, 18);
  41. $param['data']['amount10']['value'] = $orderInfo['total'];
  42. $param['data']['thing16']['value'] = $orderInfo['shipping_name'];
  43. $param['data']['phone_number7']['value'] = encryptTel($orderInfo['shipping_tel']);
  44. $param['pages'] = '/pagesA/my/admintechnical/orderDetail';
  45. $param['query'] = 'id=' . $orderInfo['id'];
  46. if (self::send($param)) {
  47. self::sendmptplmessage($param);
  48. }
  49. }
  50. public static function storeOrderPay($sid, $orderInfo)
  51. {
  52. $orderInfo['pay_time'] = time_format($orderInfo['pay_time']);
  53. $messagetpl = Config::getconfig('messagetpl');
  54. $param['template_id'] = $messagetpl['pay_tpl'];
  55. $param['uuid'] = Store::getUuid($sid);
  56. $param['uid'] = UuidRelation::getuid($param['uuid']);
  57. $param['title'] = '店铺订单通知';
  58. $param['content'] = '您有一个新的订单,请及时处理';
  59. $param['pages'] = '/pagesA/my/adminstore/orderDetail';
  60. $param['query'] = 'id=' . $orderInfo['id'];
  61. $param['data']['character_string1']['value'] = $orderInfo['order_num_alias'];
  62. $param['data']['thing3']['value'] = mb_substr($orderInfo['pay_subject'], 0, 18);
  63. $param['data']['time5']['value'] = $orderInfo['pay_time'];
  64. $param['data']['amount4']['value'] = $orderInfo['total'];
  65. if (self::send($param)) {
  66. self::sendmptplmessage($param);
  67. }
  68. }
  69. public static function undertake($orderInfo)
  70. {
  71. $orderInfo['pay_time'] = time_format($orderInfo['pay_time']);
  72. $technicalConfig = Config::getconfig('technical');
  73. if ($technicalConfig['is_pickuporder'] == 1) {
  74. $messagetpl = Config::getconfig('messagetpl');
  75. $param['template_id'] = $messagetpl['undertake_tpl'];
  76. $Technical = Technical::gelist_bycitycate($orderInfo);
  77. if (!empty($Technical)) {
  78. foreach ($Technical as $vo) {
  79. $param['uid'] = $vo['uid'];
  80. if (empty($param['uid'])) {
  81. $param['uid'] = UuidRelation::getuid($vo['uuid']);
  82. }
  83. $param['uuid'] = $vo['uuid'];
  84. $param['title'] = '平台推荐单通知';
  85. $param['pages'] = '/pagesA/my/publicOrder/order';
  86. $param['content'] = '您有一个新的平台推荐订单,请及时处理';
  87. $param['data']['character_string2']['value'] = $orderInfo['order_num_alias'];
  88. $param['data']['thing4']['value'] = $orderInfo['shipping_name'];
  89. $param['data']['thing9']['value'] = mb_substr($orderInfo['pay_subject'], 0, 18);
  90. $param['data']['amount3']['value'] = $orderInfo['total'];
  91. $param['data']['time5']['value'] = $orderInfo['pay_time'];
  92. if (self::send($param)) {
  93. self::sendmptplmessage($param);
  94. }
  95. }
  96. }
  97. }
  98. }
  99. public static function orderPayNoticeAdmin($orderInfo)
  100. {
  101. $orderInfo['pay_time'] = time_format($orderInfo['pay_time']);
  102. $messagetpl = Config::getconfig('messagetpl');
  103. $param['template_id'] = $messagetpl['pay_tpl'];
  104. $where['weid'] = weid();
  105. $where['sid'] = 0;
  106. $query = Users::where($where);
  107. $query->where('role_id', 'in', UsersRoles::getadminids());
  108. $query->whereNotNull('uuid');
  109. $query->where('uuid', '<>', '');
  110. $adminlist = $query->select()->toArray();
  111. //var_dump($query->getLastsql());
  112. if (!empty($adminlist)) {
  113. foreach ($adminlist as $vo) {
  114. $param['uid'] = UuidRelation::getuid($vo['uuid']);
  115. $param['uuid'] = $vo['uuid'];
  116. $param['title'] = '订单支付成功';
  117. $param['content'] = '订单支付成功';
  118. $param['pages'] = '/pagesA/my/admin/orderDetail';
  119. $param['query'] = 'id=' . $orderInfo['id'];
  120. $param['data']['character_string1']['value'] = $orderInfo['order_num_alias'];
  121. $param['data']['thing3']['value'] = mb_substr($orderInfo['pay_subject'], 0, 20);
  122. $param['data']['time5']['value'] = $orderInfo['pay_time'];
  123. $param['data']['amount4']['value'] = $orderInfo['total'];
  124. if (self::send($param)) {
  125. self::sendmptplmessage($param);
  126. }
  127. }
  128. }
  129. }
  130. public static function orderRefundNoticeAdmin($orderInfo)
  131. {
  132. $orderInfo['pay_time'] = time_format($orderInfo['pay_time']);
  133. $messagetpl = Config::getconfig('messagetpl');
  134. $param['template_id'] = $messagetpl['refund_tpl'];
  135. $where['weid'] = weid();
  136. $where['sid'] = 0;
  137. $query = Users::where($where);
  138. $query->where('role_id', 'in', UsersRoles::getadminids());
  139. $query->whereNotNull('uuid');
  140. $query->where('uuid', '<>', '');
  141. $adminlist = $query->select()->toArray();
  142. //var_dump($query->getLastsql());
  143. if (!empty($adminlist)) {
  144. foreach ($adminlist as $vo) {
  145. $param['uid'] = UuidRelation::getuid($vo['uuid']);
  146. $param['uuid'] = $vo['uuid'];
  147. $param['title'] = '用户申请订单退款';
  148. $param['pages'] = '/pagesA/my/admin/orderDetail';
  149. $param['content'] = '订单支付成功';
  150. $param['query'] = 'id=' . $orderInfo['id'];
  151. $param['data']['number1']['value'] = $orderInfo['order_num_alias'];
  152. $param['data']['thing2']['value'] = mb_substr($orderInfo['pay_subject'], 0, 20);
  153. $param['data']['amount4']['value'] = $orderInfo['total'];
  154. if (self::send($param)) {
  155. self::sendmptplmessage($param);
  156. };
  157. }
  158. }
  159. }
  160. public static function send($param)
  161. {
  162. $data['weid'] = weid();
  163. $data['title'] = $param['title'];
  164. $data['content'] = $param['content'];
  165. $data['pages'] = $param['pages'] . '?' . $param['query'];
  166. $uid = $param['uid'];
  167. if (empty($uid)) {
  168. $uid = UuidRelation::getuid($param['uuid']);
  169. }
  170. if (!empty($uid)) {
  171. $res = self::create($data);
  172. if ($res) {
  173. MessageBroadcast::create([
  174. 'message_id' => $res->id,
  175. 'sender' => 0,
  176. 'receiver' => $uid,
  177. 'is_read' => 0
  178. ]);
  179. }
  180. }
  181. return $res;
  182. }
  183. public static function sendmptplmessage($param)
  184. {
  185. if (!empty($param['template_id'])) {
  186. $weid = weid();
  187. if (!empty($param['uid'])) {
  188. $Openid = Openid::getMpOpenidbyuid($param['uid']);
  189. }
  190. if (empty($Openid)) {
  191. $Openid = Openid::getMpOpenidbyuuid($param['uuid']);
  192. }
  193. if (!empty($Openid)) {
  194. $miniConfig = Config::getconfig('miniprogram');
  195. $app = \app\samos\wechat\Messagetpl::maketpl();
  196. $checkpages = $param['pages'];
  197. if ($param['query']) {
  198. $param['pages'] = $param['pages'] . '?' . $param['query'];
  199. }
  200. if (empty($param['data'])) {
  201. $param['data']['first'] = mb_substr($param['title'], 0, 10);
  202. $param['data']['remark'] = mb_substr($param['content'], 0, 20);
  203. }
  204. if (!empty($miniConfig['app_id']) && MiniProgram::ispagethereare($checkpages)) {
  205. $messagedata = [
  206. 'touser' => $Openid,
  207. 'template_id' => trim($param['template_id']),
  208. 'miniprogram' => [
  209. 'appid' => trim($miniConfig['app_id']),
  210. 'pagepath' => $param['pages'],
  211. ],
  212. 'data' => $param['data'],
  213. ];
  214. } else {
  215. $url = gethost() . scriptPath() . '/h5/?i=' . $weid . '#' . $param['pages'];
  216. $messagedata = [
  217. 'touser' => $Openid,
  218. 'template_id' => trim($param['template_id']),
  219. 'url' => $url,
  220. 'data' => $param['data'],
  221. ];
  222. }
  223. $res = @$app->send($messagedata);
  224. if ($res) {
  225. Test::create(['title' => $param['title'] . '发公众号模板消息', 'info' => serialize($res)]);
  226. }
  227. }
  228. }
  229. }
  230. }