Plantask.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $start = strtotime(date('Y-m-d')) + 86400 ;
  11. $ended = $start + 86399 ;
  12. $where = [
  13. 'order.notice_status' => 0, //通知状态:0=未通知,1=已通知
  14. 'order.status' => 1, //订单状态:-1=退货,0=取消订单,1=正常
  15. 'order.have_paid' => ['gt',0], //已支付
  16. 'order.have_received' => 0, //未核销
  17. 'order.refund_status' => 0, //未退款
  18. 'product.activetime' => ['between',[$start,$ended]],
  19. ];
  20. $list = Db::name('unishop_order')->alias('order')
  21. ->field('order.id,product.title,product.info,product.activetime,user.wxmini_openid')
  22. ->join('user','user.id = order.user_id','left')
  23. ->join('unishop_order_product op','order.id = op.order_id','left')
  24. ->join('unishop_product product','product.id = op.product_id','left')
  25. ->where($where)->limit(10)->select();
  26. if(empty($list)){
  27. echo '没有需要处理的订单';
  28. exit;
  29. }
  30. $order_ids = array_column($list,'id');
  31. Db::name('unishop_order')->where('id','IN',$order_ids)->update(['notice_status' => 1]);
  32. echo implode(',',$order_ids);
  33. try {
  34. foreach ($list as $k=>$v){
  35. $config = config('wxMiniProgram');
  36. $wechat = new Wechat($config['appid'],$config['secret']);
  37. //活动明天开始
  38. $template_id = $config['mini_msgid_order'];
  39. $data = [
  40. 'thing4' => ['value' => $v['title']],
  41. 'thing6' => ['value' => $v['info']],
  42. 'date5' => ['value' => date('Y-m-d H:i',$v['activetime'])],
  43. 'thing7' => ['value' => '活动明天开始,不要迟到哦'],
  44. ];
  45. //dump($data);
  46. $rs = $wechat->send($template_id,$v['wxmini_openid'],$data);
  47. }
  48. }catch (Exception $e) {
  49. }
  50. }
  51. }