Wlps.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\cron;
  3. use think\Db;
  4. use yunwuxin\cron\Task;
  5. class Wlps extends Task
  6. {
  7. public function configure()
  8. {
  9. $this->everyMinute(); //每分钟执行一次
  10. }
  11. /**
  12. * 执行任务
  13. * @return mixed
  14. */
  15. protected function execute()
  16. {
  17. try{
  18. $this->ypconvey();
  19. $this->cancelypconvey();
  20. }catch (\Exception $e){
  21. trace($e->getMessage());
  22. }
  23. }
  24. public function ypconvey(){
  25. $lists = Db::connect('db_config_jili')->name('wlps')->where('is_deal',0)->where('is_qx','N')->select();
  26. $lists = $lists?$lists:[];
  27. foreach ($lists as $k=>$v){
  28. (new \app\common\model\Wlps())->deal_wlps($v);
  29. }
  30. }
  31. // 药品运送取消,每分钟查询一次
  32. public function cancelypconvey(){
  33. $lists=Db::connect('db_config_jili')
  34. ->name('wlps')
  35. ->alias('a')
  36. ->join('orders as b','a.order_id = b.order_id')
  37. ->field('b.*')
  38. ->whereIn('b.order_mode',[1,5])
  39. ->where('b.del_ref',0)
  40. ->where('a.order_id', '>',0)
  41. ->where('a.is_qx','<>','N')
  42. ->select();
  43. $lists = $lists?$lists:[];
  44. foreach ($lists as $k=>$v){
  45. $this->startTrans();
  46. try{
  47. $ret = Db::name('orders')->where('order_id',$v['order_id'])->update(['order_mode'=>2,'cancel_time'=>date('Y-m-d H:i:s')]);
  48. if (!$ret) {
  49. exception('保存失败');
  50. }
  51. if($v['order_mode'] == 5){
  52. $res = Db::name('todo')->where('order_id',$v['order_id'])->whereIn('todo_mode',[1,2,3])->update(['todo_mode'=>6]);
  53. if (!$res) {
  54. exception('保存失败');
  55. }
  56. }
  57. $this->commit();
  58. }catch (\Exception $e){
  59. trace('error',$e->getMessage());
  60. $this->rollback();
  61. }
  62. }
  63. }
  64. }