Plantask.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Db;
  5. class Plantask extends Controller
  6. {
  7. //每辆车的价格日历里的今天价格 更新到 car 表里 pricetoday,如果价格日历里没有今天价格,就用 price 字段 放到 pricetoday 代替
  8. public function auto_car_pricejson_to_todayprice(){
  9. $todaydate = date('Y-m-d');
  10. $today = strtotime(date('Y-m-d'));
  11. $car_list = Db::name('car')->field('id,price,price_json')->where('pricedate','neq',$today)->order('id asc')->limit(50)->select();
  12. foreach($car_list as $key => $val){
  13. $update = ['pricedate'=>$today];
  14. if(!empty($val['price_json'])){
  15. $price_json = json_decode($val['price_json'],true);
  16. if(is_array($price_json) && isset($price_json[$todaydate])){
  17. $update['pricetoday'] = $price_json[$todaydate];
  18. }
  19. }
  20. $update['pricetoday'] = $val['price'];
  21. Db::name('car')->where('id',$val['id'])->update($update);
  22. }
  23. }
  24. }