初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\order;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use app\common\model\order\Evaluate as EvaluateModel;
|
||||
use app\common\model\order\Item as OrderItemModel;
|
||||
use app\common\model\order\Order;
|
||||
/**
|
||||
* 订单评价
|
||||
*/
|
||||
class Evaluate extends Api
|
||||
{
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
protected $noNeedLogin = ['getCourseRecommendList','getList'];
|
||||
|
||||
|
||||
protected $model = null;
|
||||
protected $OrderItemModel = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new EvaluateModel();
|
||||
$this->orderModel = new Order();
|
||||
$this->OrderItemModel = new OrderItemModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评价列表
|
||||
* @return void
|
||||
*/
|
||||
public function getList(){
|
||||
$itemId = $this->request->post('item_id','');
|
||||
$limit = input('limit',10);
|
||||
$page = input('page',1);
|
||||
$status = input('status','');
|
||||
|
||||
if(empty($itemId)){
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$list = $this->model->getList(0,[
|
||||
'limit'=>$limit,
|
||||
'page'=>$page,
|
||||
'status'=>$status,
|
||||
'item_id'=>$itemId
|
||||
]);
|
||||
|
||||
$this->success('获取成功', $list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取课程推荐的评价
|
||||
* @return void
|
||||
*/
|
||||
public function getCourseRecommendList(){
|
||||
$id = input('id',0);
|
||||
|
||||
$data = $this->model->getRecommendList($id);
|
||||
|
||||
$this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取待评价的商品
|
||||
* @return void
|
||||
*/
|
||||
public function getBeItems(){
|
||||
$orderNo = input('order_no','');
|
||||
|
||||
$list = $this->OrderItemModel->where([
|
||||
'evaluate'=>0,
|
||||
'order_no'=>$orderNo
|
||||
])->select();
|
||||
|
||||
if($list){
|
||||
foreach ($list as &$item){
|
||||
$item['snapshoot'] = json_decode($item['snapshoot'],true);
|
||||
}
|
||||
}
|
||||
$this->success("获取成功",$list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取被评价的商品信息
|
||||
* @return void
|
||||
*/
|
||||
public function getToItemInfo(){
|
||||
$orderNo = input('order_no','');
|
||||
$itemId = input('item_id','');
|
||||
|
||||
if(!$this->orderModel->checkOrderBindUser($orderNo,$this->auth->id)){
|
||||
$this->error('获取订单信息失败');
|
||||
}
|
||||
|
||||
$data = $this->model->getToItemInfo($orderNo,$itemId);
|
||||
if(!$data){
|
||||
$this->error("暂无需要评价内容");
|
||||
}
|
||||
|
||||
$this->success("获取成功",$data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提交评价
|
||||
* @return void
|
||||
*/
|
||||
public function submit(){
|
||||
$orderNo = input('order_no','');
|
||||
$itemId = input('item_id','');
|
||||
$rows = input('rows/a');
|
||||
|
||||
if(!$this->orderModel->checkOrderBindUser($orderNo,$this->auth->id)){
|
||||
$this->error('获取订单信息失败');
|
||||
}
|
||||
|
||||
$discussConfig = \app\common\model\config\System::getConfig('discuss');
|
||||
|
||||
if($discussConfig['evaluate_status'] == 'close'){
|
||||
$this->error("评价功能暂时关闭");
|
||||
}
|
||||
|
||||
$data = $this->model->getToItemInfo($orderNo,$itemId);
|
||||
if(!$data){
|
||||
$this->error("暂无需要评价内容");
|
||||
}
|
||||
|
||||
$rows['user_id'] = $this->auth->id;
|
||||
$rows['order_no'] = $orderNo;
|
||||
$rows['item_id'] = $itemId;
|
||||
$rows['uniacid'] = UNIACID;
|
||||
$rows['createtime'] = time();
|
||||
|
||||
$successTip = '评价成功';
|
||||
|
||||
if($discussConfig['evaluate_audit'] == 'open'){
|
||||
$rows['status'] = 0;
|
||||
$successTip = '提交成功,评价将在审核通过后显示';
|
||||
}
|
||||
|
||||
|
||||
|
||||
$rows['imgs'] = implode(",",$rows['imgs']);
|
||||
|
||||
$this->model->insert($rows);
|
||||
|
||||
|
||||
|
||||
$this->OrderItemModel->where([
|
||||
'order_no'=>$orderNo,
|
||||
'item_id'=>$itemId
|
||||
])->update([
|
||||
'evaluate'=>1
|
||||
]);
|
||||
|
||||
//判断是否全部评价完毕
|
||||
|
||||
$isAllEvaluate = $this->OrderItemModel->where([
|
||||
'order_no'=>$orderNo,
|
||||
'evaluate'=>0
|
||||
])->find();
|
||||
|
||||
if(!$isAllEvaluate){
|
||||
Order::where([
|
||||
'order_no'=>$orderNo
|
||||
])->update([
|
||||
'evaluate'=>1
|
||||
]);
|
||||
}
|
||||
$this->success($successTip);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user