Skip to content
关注公众号,获取新课通知

客服回复


控制器 app/controller/admin/OrderItem.php

php
// 客服回复
    public function review(){
    	// 获取当前订单商品
        $orderItem = request()->Model;
        $order = $orderItem->order;
        // 判断是否已经评价过了
        if (!$orderItem->review_time) {
            ApiException('该订单还没有被评价过');
        }
        $param  = request()->param();
        // 更新orderItem
        if($orderItem->extra === null){
        	$arr = [];
        	$arr[] = [
        		'isuser'=>false,
        		'data'=>$param['data'],
        		'good_num'=>0	
        	];
        	$orderItem->extra = $arr;
        } else {
        	$arr = $orderItem->extra;
        	for ($i = 0; $i < count($arr); $i++) {
        		 if (!$arr[$i]['isuser']) {
        		 	$arr[$i]['data'] = $param['data'];
        		 }
        	}
        	$orderItem->extra = $arr;
        }
        return showSuccess($orderItem->save());
    }

验证器 app/validate/admin/OrderItem.php

php
// 验证规则
protected $rule = [
    ...
    'id'=>'require|integer|>:0|isExist:OrderItem',
    'data'=>'require|NotEmpty',
    ...
];
protected $scene = [
    // ...
    'review'=>['id','data'],
];

路由 router/admin.php

php
Route::post('goods_comment/review/:id','admin.OrderItem/review');