|
@@ -7,7 +7,7 @@ use app\common\model\Order;
|
|
|
use app\common\model\OrderAftersales;
|
|
|
use app\common\model\OrderAction;
|
|
|
use think\Db;
|
|
|
-
|
|
|
+use app\common\Enum\OrderEnum;
|
|
|
/**
|
|
|
* 评论
|
|
|
*/
|
|
@@ -37,16 +37,14 @@ class Comment extends Base
|
|
|
public function add()
|
|
|
{
|
|
|
$pid = $this->request->post('pid/d', 0);
|
|
|
- $order_sn = $this->request->post('order_sn');
|
|
|
+ $order_id = $this->request->post('order_id/d');
|
|
|
$remark = $this->request->post('remark/a', '', 'trim,xss_clean');
|
|
|
if (empty($remark) || !is_array($remark)) {
|
|
|
$this->error('评论内容不能为空');
|
|
|
}
|
|
|
$order = Order::with(['OrderGoods'])
|
|
|
- ->where('order_sn', $order_sn)
|
|
|
- ->where('orderstate', 0)
|
|
|
- ->where('shippingstate', 2)
|
|
|
- ->where('paystate', 1)
|
|
|
+ ->where('id', $order_id)
|
|
|
+ ->where('order_status', OrderEnum::STATUS_CONFIRM)
|
|
|
->where('user_id', $this->auth->id)->find();
|
|
|
|
|
|
if (!$order) {
|
|
@@ -61,7 +59,7 @@ class Comment extends Base
|
|
|
$goods_ids = [];
|
|
|
//可以评价的商品
|
|
|
foreach ($order->order_goods as $item) {
|
|
|
- if (in_array($item['salestate'], [0, 6])) {
|
|
|
+ if (in_array($item['sale_status'], [0, 6])) {
|
|
|
$goods_ids[] = $item['goods_id'];
|
|
|
}
|
|
|
}
|
|
@@ -95,35 +93,36 @@ class Comment extends Base
|
|
|
];
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
- try {
|
|
|
+ // try {
|
|
|
(new CommentModel())->saveAll($data);
|
|
|
- $order->orderstate = 3;
|
|
|
+ $order->order_status = OrderEnum::STATUS_COMMENT;
|
|
|
$order->save();
|
|
|
foreach ($order->order_goods as $item) {
|
|
|
- $item->save(['commentstate' => 1]);
|
|
|
- }
|
|
|
- //是否有积分
|
|
|
- $config = get_addon_config('shop');
|
|
|
- if ($config['comment_score'] > 0) {
|
|
|
- \app\common\model\User::score($config['comment_score'], $this->auth->id, '评论订单赠送' . $config['comment_score'] . '积分');
|
|
|
- }
|
|
|
- //结束,订单完成,给积分
|
|
|
- if (isset($config['money_score']) && $config['money_score'] > 0 && $order->shippingstate == 2 && $order->paystate == 1) {
|
|
|
- //减去退款金额
|
|
|
- $refund = OrderAftersales::where('order_id', $order->id)->where('type', '<>', 3)->where('status', 2)->sum('refund');
|
|
|
- $money = bcsub($order['payamount'], $refund, 2);
|
|
|
- if ($money > 0) {
|
|
|
- $score = bcmul($money, $config['money_score']);
|
|
|
- \app\common\model\User::score($score, $this->auth->id, '完成订单奖励' . $score . '积分');
|
|
|
- }
|
|
|
+ $item->save(['comment_status' => 1]);
|
|
|
}
|
|
|
+ // //是否有积分
|
|
|
+ // $config = get_addon_config('shop');
|
|
|
+ // if ($config['comment_score'] > 0) {
|
|
|
+ // \app\common\model\User::score($config['comment_score'], $this->auth->id, '评论订单赠送' . $config['comment_score'] . '积分');
|
|
|
+ // }
|
|
|
+ // //结束,订单完成,给积分
|
|
|
+ // if (isset($config['money_score']) && $config['money_score'] > 0 && $order->shippingstate == 2 && $order->paystate == 1) {
|
|
|
+ // //减去退款金额
|
|
|
+ // $refund = OrderAftersales::where('order_id', $order->id)->where('type', '<>', 3)
|
|
|
+ // ->where('status', 2)->sum('refund');
|
|
|
+ // $money = bcsub($order['payamount'], $refund, 2);
|
|
|
+ // if ($money > 0) {
|
|
|
+ // $score = bcmul($money, $config['money_score']);
|
|
|
+ // \app\common\model\User::score($score, $this->auth->id, '完成订单奖励' . $score . '积分');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
- } catch (\Exception $e) {
|
|
|
- // 回滚事务
|
|
|
- Db::rollback();
|
|
|
- $this->error('添加评论失败');
|
|
|
- }
|
|
|
+ // } catch (\Exception $e) {
|
|
|
+ // // 回滚事务
|
|
|
+ // Db::rollback();
|
|
|
+ // $this->error('添加评论失败');
|
|
|
+ // }
|
|
|
OrderAction::push($order->order_sn, '系统', '订单已完成');
|
|
|
$this->success('添加评论成功,等待审核!');
|
|
|
}
|