WeixinPushOrder.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\command;
  3. // +----------------------------------------------------------------------
  4. // | [ WE CAN DO IT MORE SIMPLE ]
  5. // +----------------------------------------------------------------------
  6. // | Copyright (c) 2018-2020 rights reserved.
  7. // +----------------------------------------------------------------------
  8. // | Author: TABLE ME
  9. // +----------------------------------------------------------------------
  10. // | Date: 2020-09-08 16:19
  11. // +----------------------------------------------------------------------
  12. use app\model\api\SiteDetail;
  13. use app\model\system\Member;
  14. use app\model\system\OrderInfo;
  15. use app\model\system\Product;
  16. use app\model\system\Recharge;
  17. use app\model\system\Site;
  18. use library\lib\weixinjs;
  19. use library\utils\Qiniu;
  20. use think\console\Command;
  21. use think\console\Input;
  22. use think\console\Output;
  23. use think\facade\Cache;
  24. use think\facade\Db;
  25. /**
  26. * 订单发货提醒
  27. * @author huangjianfeng
  28. */
  29. class WeixinPushOrder extends Command
  30. {
  31. protected function configure()
  32. {
  33. $this
  34. ->setName('WeixinPushOrder')
  35. ->setDescription('微信推送订单push数据')
  36. ->addArgument('action', null, "");
  37. }
  38. protected function execute(Input $input, Output $output)
  39. {
  40. $weixin = new weixinjs();
  41. $time = strtotime('-5 minute');
  42. $orderPush = Db::name("weixin_order_push")
  43. ->where('push_time',"<=",$time)
  44. ->where('status',0)
  45. ->select();
  46. foreach ($orderPush as $v) {
  47. //推送订单
  48. $wxUser = Db::name("weixin_push_user")
  49. ->where('uid',$v['uid'])
  50. ->find();
  51. if(!empty($wxUser)) {
  52. $dataAr = unserialize($v['data']);
  53. $vStr = "\n\t";
  54. $oId = [];
  55. foreach ($dataAr as $kk=>$vv) {
  56. $order = Db::name('order')->where('id',$kk)->find();
  57. $Fcount = Db::name('orderInfo')
  58. ->where('status',2)
  59. ->where('o_id',$kk)
  60. ->count();
  61. $count = Db::name('orderInfo')->where('o_id',$kk)->count();
  62. $oId[] = $kk;
  63. $vStr .= $order['order_id'].' 共:' . $count . " 已发:" . $Fcount . "\n\t";
  64. }
  65. $templateAr = [
  66. 'first' => [
  67. 'value' => '您有新的订单打单发货',
  68. "color" => "#000000"
  69. ],
  70. 'keyword1' => [
  71. 'value' => $vStr,
  72. "color" => "#409EFF"
  73. ],
  74. 'keyword2' => [
  75. 'value' => '点击查看',
  76. "color" => "#409EFF"
  77. ],
  78. 'remark' => [
  79. 'value' => "点击查看详情"
  80. ],
  81. ];
  82. $token = base64_encode(crypto_encrypt(serialize(['oids'=>$oId]), 'weixin_push'));
  83. $url = config('app')['API_URL'] . '/api/wexinPush/order?token=' . $token;
  84. $a = $weixin->template('FTd4Nf_ov3N01AlONhO2h8TWNDS5bc7phArcZJn_vC0', $wxUser['openid'], $templateAr, $url);
  85. echo $wxUser['nickname'] . '订单推送,' . $vStr . PHP_EOL;
  86. Db::name("weixin_order_push")->where('id',$v['id'])->update(['status'=>1,'send_time'=>time()]);
  87. }
  88. }
  89. }
  90. }