Timetask.php 1.0 KB
<?php


namespace app\api\controller;


use app\common\controller\Api;

/**
 * @ApiInternal
 */
class Timetask extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 取消订单
     */
    public function orderCancel()
    {
        $model = new \app\api\model\Order();
        $list = $model->where('order_status','10')->where('pay_status','10')->select();
        $goodsmodel = new \app\api\model\OrderGoods();
        $skumodel = new \app\api\model\GoodsSpec();
        foreach ($list as $key => $value){
            // 增加库存
            $goods = $goodsmodel->where('order_id',$value['id'])->select();
            foreach ($goods as $k => $val){
                if ($value['deduct_stock_type'] == 10){
                    $skumodel->where('goods_spec_id',$val['goods_spec_id'])->setInc('stock_num',$val['total_num']);
                }
            }
        }
        $model->where('order_status','10')->where('pay_status','10')->isUpdate()->save(['order_status'=>'20']);
    }
}