quanwei
2026-01-17 e1e2fe5710a5b5cd9c19bd3aa99c998a1a613ca8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
 
namespace app\api\controller\store;
 
use app\api\controller\Controller;
use app\api\model\settings\Setting as SettingModel;
use app\api\model\store\Clerk as ClerkModel;
use app\api\model\plus\coupon\UserCoupon as UserCouponModel;
use app\api\model\store\Coupon as StoreCouponModel;
 
/**
 * 兑换券核销
 */
class Coupon extends Controller
{
    private $user;
 
    /**
     * 构造方法
     */
    public function initialize()
    {
        parent::initialize();
        $this->user = $this->getUser();   // 用户信息
    }
 
    /**
     * 兑换券详情
     */
    public function detail($user_coupon_id)
    {
        // 兑换券详情
        $model = UserCouponModel::getDetail($user_coupon_id);
        // 验证是否为该门店的核销员
        $clerkModel = ClerkModel::detail(['user_id' => $this->user['user_id']]);
        
        if (!$clerkModel->checkUser($clerkModel['store_id'])) {
            return $this->renderError($clerkModel->getError());
        }
        //平台券可以核销
        if (!empty($model['shop_supplier_id']) && $clerkModel['shop_supplier_id'] != $model['shop_supplier_id']) {
            return $this->renderError('很抱歉!你没有核销权限');
        }
        if (!empty($model['use_permission']) && $model['use_permission'] ==1) {
            return $this->renderError('很抱歉!该券仅能线上使用');
        }
        if ($model['is_use']) {
            return $this->renderError('该券可用次数已用完');
        }
        if ($model['is_expire']) {
            return $this->renderError('该券已过期');
        }
        return $this->renderSuccess('', [
            'coupon' => $model,  // 兑换券详情
            'clerkModel' => $clerkModel,
            'setting' => [
                // 积分名称
                'points_name' => SettingModel::getPointsName(),
            ],
        ]);
    }
 
    /**
     * 确认核销
     */
    public function extract($user_coupon_id, $project_id)
    {
        // 兑换券详情
        $model = UserCouponModel::detail($user_coupon_id);
        // 验证是否为该门店的核销员
        $clerkModel = ClerkModel::detail(['user_id' => $this->user['user_id']]);
        // if (!$ClerkModel->checkUser($order['extract_store_id'])) {
        //     return $this->renderError($ClerkModel->getError());
        // }
        //平台券可以核销
        if (!empty($model['shop_supplier_id']) && $clerkModel['shop_supplier_id'] != $model['shop_supplier_id']) {
            return $this->renderError('很抱歉!你没有核销权限');
        }
        if (!empty($model['use_permission']) && $model['use_permission'] ==1) {
            return $this->renderError('很抱歉!该券仅能线上使用');
        }
        $model['extract_store_id'] = $clerkModel['store_id'];
        // 确认核销
        if ($model->verificationOrder($clerkModel['clerk_id'], $project_id,$clerkModel['shop_supplier_id'])) {
            return $this->renderSuccess('优惠券核销成功', []);
        }
        return $this->renderError($model->getError() ?:'核销失败');
    }
 
    /**
     * 优惠核销记录列表
     */
    public function extract_list($search = '')
    {
        $data = $this->postData();
        // 核销记录列表
        $store_id = $this->user["clerkUser"]["store_id"];
        $model = new StoreCouponModel;
        $list = $model->getList($store_id, $search, $data);
        return $this->renderSuccess('', compact('list'));
    }
 
}