作者 李忠强

更新

@@ -5,6 +5,7 @@ namespace app\api\controller; @@ -5,6 +5,7 @@ namespace app\api\controller;
5 5
6 6
7 use addons\epay\library\Service; 7 use addons\epay\library\Service;
  8 +use app\api\model\GoodsComment;
8 use app\api\model\GoodsSpec; 9 use app\api\model\GoodsSpec;
9 use app\api\model\SpecValue; 10 use app\api\model\SpecValue;
10 use app\api\model\Third; 11 use app\api\model\Third;
@@ -537,40 +538,83 @@ class Order extends Api @@ -537,40 +538,83 @@ class Order extends Api
537 } 538 }
538 539
539 /** 540 /**
540 - * @ApiTitle (评价订单) 541 + * @ApiTitle (评价订单详情页)
541 * @ApiMethod (POST) 542 * @ApiMethod (POST)
542 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 543 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
543 * @ApiParams (name="id", type="integer", required=true, description="订单ID") 544 * @ApiParams (name="id", type="integer", required=true, description="订单ID")
544 - * @ApiParams (name="score", type="integer", required=true, description="评价分数")  
545 - * @ApiParams (name="comment", type="string", required=true, description="评价内容")  
546 - * @ApiParams (name="images", type="string", required=true, description="评价图片逗号隔开")  
547 * @ApiReturn ({ 545 * @ApiReturn ({
548 'code':'1', 546 'code':'1',
549 'msg':'返回成功' 547 'msg':'返回成功'
  548 + 'data':
  549 + order_id:订单id
  550 + goods_name:商品名称
  551 + goods_id:商品id
  552 + goods_attr:规格描述
  553 + image_text:商品图片
550 }) 554 })
551 */ 555 */
552 - public function commentOrder() 556 + public function commentOrderDetail()
553 { 557 {
554 $order_id = $this->request->post('id'); 558 $order_id = $this->request->post('id');
555 - $score = $this->request->post('score');  
556 - $comment = $this->request->post('comment');  
557 - $images = $this->request->post('images');  
558 if (!is_numeric($order_id)) $this->error('订单id参数不合法'); 559 if (!is_numeric($order_id)) $this->error('订单id参数不合法');
559 - if (!is_numeric($score) || $score>5 || $score<1) $this->error('评价分数不合法');  
560 - if (!$comment) $this->error('请填写评价内容');  
561 - if (!$comment) $this->error('请填写评价内容');  
562 - if ($images){  
563 - $arr = explode(',',$images);  
564 - if (count($arr) > 3) $this->error('请上传最多3张评价图片'); 560 +
  561 + $model = new \app\api\model\OrderGoods();
  562 + $list = $model
  563 + ->where('order_id',$order_id)
  564 + ->field('order_id,goods_name,goods_id,goods_attr,image')
  565 + ->select();
  566 +
  567 + $this->success('商品列表',$list);
  568 + }
  569 +
  570 + /**
  571 + * @ApiTitle (评价订单)
  572 + * @ApiMethod (POST)
  573 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  574 + * @ApiParams (name="data_json", type="string", required=true, description="评价数据 json对象")
  575 + * @ApiParams (name="order_id", type="integer", required=false, description="订单ID 不传")
  576 + * @ApiParams (name="score", type="integer", required=false, description="评价分数 不传")
  577 + * @ApiParams (name="comment", type="string", required=false, description="评价内容 不传")
  578 + * @ApiParams (name="goods_id", type="string", required=false, description="商品id 不传")
  579 + * @ApiParams (name="images", type="string", required=false, description="评价图片逗号隔开 不传")
  580 + * @ApiReturn ({
  581 + 'code':'1',
  582 + 'msg':'返回成功'
  583 + })
  584 + */
  585 + public function commentOrder()
  586 + {
  587 + $data = $this->request->post('data_json');
  588 + if (!$data) $this->error('data_json参数缺失');
  589 +
  590 + $data = json_decode($data,true);
  591 + $params = [];
  592 + $orderids = [];
  593 + foreach ($data as $key => $value){
  594 + if (!is_numeric($value['order_id'])) $this->error('订单id参数不合法');
  595 + if (!is_numeric($value['goods_id'])) $this->error('商品id参数不合法');
  596 + if (!is_numeric($value['score']) || $value['score']>5 || $value['score']<1) $this->error('评价分数不合法');
  597 + if (!$value['comment']) $this->error('请填写评价内容');
  598 + if ($value['images']){
  599 + $arr = explode(',',$value['images']);
  600 + if (count($arr) > 3) $this->error('请上传最多3张评价图片');
  601 + }
  602 + $params[] = [
  603 + 'user_id' => $this->auth->id,
  604 + 'order_id' => $value['order_id'],
  605 + 'goods_id' => $value['goods_id'],
  606 + 'comment' => $value['comment'],
  607 + 'images' => $value['images'],
  608 + 'score' => $value['score'],
  609 + ];
  610 + $orderids[] = $value['order_id'];
565 } 611 }
566 612
567 - $model = new \app\api\model\Order();  
568 - $model->where('id',$order_id)->isUpdate()->save(['order_status'=>'30']);  
569 -// $data = [  
570 -// 'user_id' => $this->auth->id,  
571 -// 'goods_id' => $  
572 -// ]  
573 - $this->success('取消成功'); 613 + $ordermodel = new \app\api\model\Order();
  614 + $ordermodel->whereIn('id',$orderids)->isUpdate()->save(['order_status'=>'30']);
  615 + $commentmodel = new GoodsComment();
  616 + $commentmodel->isUpdate(false)->saveAll($params);
  617 + $this->success('评价成功');
574 } 618 }
575 619
576 } 620 }