| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?phpnamespace app\cron;use think\Db;use yunwuxin\cron\Task;class Wlps extends Task{    public function configure()    {        $this->everyMinute(); //每分钟执行一次    }    /**     * 执行任务     * @return mixed     */    protected function execute()    {        try{            $this->ypconvey();            $this->cancelypconvey();        }catch (\Exception $e){            trace($e->getMessage());        }    }        public function ypconvey(){         $lists = Db::connect('db_config_jili')->name('wlps')->where('is_deal',0)->where('is_qx','N')->select();        $lists = $lists?$lists:[];        foreach ($lists as $k=>$v){            (new \app\common\model\Wlps())->deal_wlps($v);        }    }    // 药品运送取消,每分钟查询一次    public function cancelypconvey(){         $lists=Db::connect('db_config_jili')             ->name('wlps')             ->alias('a')             ->join('orders as b','a.order_id = b.order_id')             ->field('b.*')             ->whereIn('b.order_mode',[1,5])             ->where('b.del_ref',0)             ->where('a.order_id', '>',0)             ->where('a.is_qx','<>','N')             ->select();        $lists = $lists?$lists:[];        foreach ($lists as $k=>$v){             $this->startTrans();            try{                $ret = Db::name('orders')->where('order_id',$v['order_id'])->update(['order_mode'=>2,'cancel_time'=>date('Y-m-d H:i:s')]);                if (!$ret) {                     exception('保存失败');                }                if($v['order_mode'] == 5){                    $res = Db::name('todo')->where('order_id',$v['order_id'])->whereIn('todo_mode',[1,2,3])->update(['todo_mode'=>6]);                    if (!$res) {                        exception('保存失败');                    }                }                $this->commit();            }catch (\Exception $e){            trace('error',$e->getMessage());            $this->rollback();            }        }    }}
 |