PhBalanceWarning.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\cron;
  3. use think\Db;
  4. use yunwuxin\cron\Task;
  5. class PhBalanceWarning extends Task
  6. {
  7. public function configure()
  8. {
  9. $this->dailyAt('00:00'); //每天执行一次
  10. }
  11. /**
  12. * 执行任务
  13. * @return mixed
  14. */
  15. protected function execute()
  16. {
  17. try{
  18. $this->record();
  19. }catch (\Exception $e){
  20. trace($e->getMessage());
  21. }
  22. }
  23. //生成预警记录
  24. public function record(){
  25. $list = Db::name('ph_orders')
  26. ->where('status',1)
  27. ->field('org_id,sn,start,price,pre_money,contact,phone')
  28. ->order('id desc')
  29. ->select();
  30. foreach ($list as $k=>$v){
  31. $time = strtotime(date('Y-m-d 00:00:00')) - strtotime($v['start']);
  32. $day = round($time/(60*60*24),1);
  33. $costMoney = round($v['price'] * $day,2);
  34. $list[$k]['cost_money'] = $costMoney;
  35. $list[$k]['end'] = date('Y-m-d 00:00:00');
  36. unset($list[$k]['price']);
  37. }
  38. foreach ($list as $k=>$v){
  39. if ($v['cost_money'] > $v['pre_money']){
  40. $data[] = $v;
  41. }
  42. }
  43. if (!empty($data)){
  44. Db::name('ph_balance_warning')->insertAll($data);
  45. }
  46. }
  47. }