Wlps.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = Db::name('wlps')->where('is_deal',0)->where('is_qx','N')->select();
  27. $lists = $lists?$lists:[];
  28. foreach ($lists as $k=>$v){
  29. (new \app\common\model\Wlps())->deal_wlps($v);
  30. }
  31. }
  32. // 药品运送取消,每分钟查询一次
  33. public function cancelypconvey(){
  34. // $lists=Db::connect('db_config_jili')
  35. // ->name('wlps')
  36. // ->alias('a')
  37. // ->join('orders as b','a.order_id = b.order_id')
  38. // ->field('b.*')
  39. // ->whereIn('b.order_mode',[1,5])
  40. // ->where('b.del_ref',0)
  41. // ->where('a.order_id', '>',0)
  42. // ->where('a.is_qx','<>','N')
  43. // ->select();
  44. $lists=Db::name('wlps')
  45. ->alias('a')
  46. ->join('orders as b','a.order_id = b.order_id')
  47. ->field('b.*')
  48. ->whereIn('b.order_mode',[1,5])
  49. ->where('b.del_ref',0)
  50. ->where('a.order_id', '>',0)
  51. ->where('a.is_qx','<>','N')
  52. ->select();
  53. $lists = $lists?$lists:[];
  54. foreach ($lists as $k=>$v){
  55. $this->startTrans();
  56. try{
  57. $ret = Db::name('orders')->where('order_id',$v['order_id'])->update(['order_mode'=>2,'cancel_time'=>date('Y-m-d H:i:s')]);
  58. if (!$ret) {
  59. exception('保存失败');
  60. }
  61. if($v['order_mode'] == 5){
  62. $res = Db::name('todo')->where('order_id',$v['order_id'])->whereIn('todo_mode',[1,2,3])->update(['todo_mode'=>6]);
  63. if (!$res) {
  64. exception('保存失败');
  65. }
  66. }
  67. $this->commit();
  68. }catch (\Exception $e){
  69. trace('error',$e->getMessage());
  70. $this->rollback();
  71. }
  72. }
  73. }
  74. }