| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | <?phpnamespace app\index\controller;use app\common\library\Wechat;use think\Controller;use think\Db;class Plantask extends Controller{    //当已付款的活动预约订单,还有一天就要开始的时候,给他发个消息,提醒他不要忘记了    public function auto_order_sendmsg(){        $todayend = strtotime(date('Y-m-d')) + 86399 ;        $where = [            'order.notice_status' => 0, //通知状态:0=未通知,1=已通知            'order.status' => 1,  //订单状态:-1=退货,0=取消订单,1=正常            'order.have_paid' => ['gt',0], //已支付            'order.have_received' => 0,  //未核销            'order.refund_status' => 0, //未退款            'product.activetime' => ['gt',$todayend],        ];        $list = Db::name('unishop_order')->alias('order')            ->field('order.id,product.title,product.info,product.activetime,user.wxmini_openid')            ->join('user','user.id = order.user_id','left')            ->join('unishop_order_product op','order.id = op.order_id','left')            ->join('unishop_product product','product.id = op.product_id','left')            ->where($where)->limit(10)->select();        if(empty($list)){            echo '没有需要处理的订单';            exit;        }        $order_ids = array_column($list,'id');        Db::name('unishop_order')->where('id','IN',$order_ids)->update(['notice_status' => 1]);        echo implode(',',$order_ids);        try {            foreach ($list as $k=>$v){                $config = config('wxMiniProgram');                $wechat = new Wechat($config['appid'],$config['secret']);                //活动明天开始                $template_id = $config['mini_msgid_order'];                $data = [                    'thing4' => ['value' => $v['title']],                    'thing6' => ['value' => $v['info']],                    'date5'  => ['value' => date('Y-m-d H:i',$v['activetime'])],                    'thing7' => ['value' => '活动明天开始,不要迟到哦'],                ];                //dump($data);                $rs = $wechat->send($template_id,$v['wxmini_openid'],$data);            }        }catch (Exception $e) {        }    }}
 |