作者 李忠强

更新

... ... @@ -5,6 +5,7 @@ namespace app\api\controller;
use addons\epay\library\Service;
use app\api\model\GoodsComment;
use app\api\model\GoodsSpec;
use app\api\model\SpecValue;
use app\api\model\Third;
... ... @@ -537,40 +538,83 @@ class Order extends Api
}
/**
* @ApiTitle (评价订单)
* @ApiTitle (评价订单详情页)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="订单ID")
* @ApiParams (name="score", type="integer", required=true, description="评价分数")
* @ApiParams (name="comment", type="string", required=true, description="评价内容")
* @ApiParams (name="images", type="string", required=true, description="评价图片逗号隔开")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':
order_id:订单id
goods_name:商品名称
goods_id:商品id
goods_attr:规格描述
image_text:商品图片
})
*/
public function commentOrder()
public function commentOrderDetail()
{
$order_id = $this->request->post('id');
$score = $this->request->post('score');
$comment = $this->request->post('comment');
$images = $this->request->post('images');
if (!is_numeric($order_id)) $this->error('订单id参数不合法');
if (!is_numeric($score) || $score>5 || $score<1) $this->error('评价分数不合法');
if (!$comment) $this->error('请填写评价内容');
if (!$comment) $this->error('请填写评价内容');
if ($images){
$arr = explode(',',$images);
if (count($arr) > 3) $this->error('请上传最多3张评价图片');
$model = new \app\api\model\OrderGoods();
$list = $model
->where('order_id',$order_id)
->field('order_id,goods_name,goods_id,goods_attr,image')
->select();
$this->success('商品列表',$list);
}
/**
* @ApiTitle (评价订单)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="data_json", type="string", required=true, description="评价数据 json对象")
* @ApiParams (name="order_id", type="integer", required=false, description="订单ID 不传")
* @ApiParams (name="score", type="integer", required=false, description="评价分数 不传")
* @ApiParams (name="comment", type="string", required=false, description="评价内容 不传")
* @ApiParams (name="goods_id", type="string", required=false, description="商品id 不传")
* @ApiParams (name="images", type="string", required=false, description="评价图片逗号隔开 不传")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function commentOrder()
{
$data = $this->request->post('data_json');
if (!$data) $this->error('data_json参数缺失');
$data = json_decode($data,true);
$params = [];
$orderids = [];
foreach ($data as $key => $value){
if (!is_numeric($value['order_id'])) $this->error('订单id参数不合法');
if (!is_numeric($value['goods_id'])) $this->error('商品id参数不合法');
if (!is_numeric($value['score']) || $value['score']>5 || $value['score']<1) $this->error('评价分数不合法');
if (!$value['comment']) $this->error('请填写评价内容');
if ($value['images']){
$arr = explode(',',$value['images']);
if (count($arr) > 3) $this->error('请上传最多3张评价图片');
}
$params[] = [
'user_id' => $this->auth->id,
'order_id' => $value['order_id'],
'goods_id' => $value['goods_id'],
'comment' => $value['comment'],
'images' => $value['images'],
'score' => $value['score'],
];
$orderids[] = $value['order_id'];
}
$model = new \app\api\model\Order();
$model->where('id',$order_id)->isUpdate()->save(['order_status'=>'30']);
// $data = [
// 'user_id' => $this->auth->id,
// 'goods_id' => $
// ]
$this->success('取消成功');
$ordermodel = new \app\api\model\Order();
$ordermodel->whereIn('id',$orderids)->isUpdate()->save(['order_status'=>'30']);
$commentmodel = new GoodsComment();
$commentmodel->isUpdate(false)->saveAll($params);
$this->success('评价成功');
}
}
\ No newline at end of file
... ...