1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- use think\Db;
- class Plantask extends Controller
- {
- //每辆车的价格日历里的今天价格 更新到 car 表里 pricetoday,如果价格日历里没有今天价格,就用 price 字段 放到 pricetoday 代替
- public function auto_car_pricejson_to_todayprice(){
- $todaydate = date('Y-m-d');
- $today = strtotime(date('Y-m-d'));
- $car_list = Db::name('car')->field('id,price,price_json')->where('pricedate','neq',$today)->order('id asc')->limit(50)->select();
- foreach($car_list as $key => $val){
- $update = ['pricedate'=>$today];
- if(!empty($val['price_json'])){
- $price_json = json_decode($val['price_json'],true);
- if(is_array($price_json) && isset($price_json[$todaydate])){
- $update['pricetoday'] = $price_json[$todaydate];
- }
- }
- $update['pricetoday'] = $val['price'];
- Db::name('car')->where('id',$val['id'])->update($update);
- }
- }
- }
|