Plantask.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\library\Wechat;
  4. use think\Controller;
  5. use think\Db;
  6. class Plantask extends Controller
  7. {
  8. //当已付款的活动预约订单,还有一天就要开始的时候,给他发个消息,提醒他不要忘记了
  9. public function auto_order_sendmsg(){
  10. $todayend = strtotime(date('Y-m-d')) + 86399 ;
  11. $where = [
  12. 'order.notice_status' => 0, //通知状态:0=未通知,1=已通知
  13. 'order.status' => 1, //订单状态:-1=退货,0=取消订单,1=正常
  14. 'order.have_paid' => ['gt',0], //已支付
  15. 'order.have_received' => 0, //未核销
  16. 'order.refund_status' => 0, //未退款
  17. 'product.activetime' => ['gt',$todayend],
  18. ];
  19. $list = Db::name('unishop_order')->alias('order')
  20. ->field('order.id,product.title,product.info,product.activetime,user.wxmini_openid')
  21. ->join('user','user.id = order.user_id','left')
  22. ->join('unishop_order_product op','order.id = op.order_id','left')
  23. ->join('unishop_product product','product.id = op.product_id','left')
  24. ->where($where)->limit(10)->select();
  25. if(empty($list)){
  26. echo '没有需要处理的订单';
  27. exit;
  28. }
  29. $order_ids = array_column($list,'id');
  30. Db::name('unishop_order')->where('id','IN',$order_ids)->update(['notice_status' => 1]);
  31. echo implode(',',$order_ids);
  32. try {
  33. foreach ($list as $k=>$v){
  34. $config = config('wxMiniProgram');
  35. $wechat = new Wechat($config['appid'],$config['secret']);
  36. //活动明天开始
  37. $template_id = $config['mini_msgid_order'];
  38. $data = [
  39. 'thing4' => ['value' => $v['title']],
  40. 'thing6' => ['value' => $v['info']],
  41. 'date5' => ['value' => date('Y-m-d H:i',$v['activetime'])],
  42. 'thing7' => ['value' => '活动明天开始,不要迟到哦'],
  43. ];
  44. //dump($data);
  45. $rs = $wechat->send($template_id,$v['wxmini_openid'],$data);
  46. }
  47. }catch (Exception $e) {
  48. }
  49. }
  50. }