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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
 
namespace app\api\controller\plus\release;
 
use app\api\controller\Controller;
use app\api\model\plus\release\SupplyApply as SupplyApplyModel;
use app\api\model\plus\release\SupplyUser as SupplyUserModel;
use app\api\model\settings\Message as MessageModel;
use app\common\exception\BaseException;
use app\api\model\plus\release\Setting;
 
/**
 * 首页
 */
class SupplyIndex extends Controller
{
    // 当前用户
    private $user;
 
    /**
     * 构造方法
     */
    public function initialize()
    {
        $this->user = $this->getUser();   // 用户信息
        // 信息
        $this->release = SupplyUserModel::detail($this->user['user_id']);
    }
 
    /**
     * 信息
     */
    public function index()
    {
        $is_release = $this->isReleaseUser();
 
        //获取开通权限连盟币
         $setting = Setting::getAll();
         $setting = $setting['settlement']['values'];
 
        return $this->renderSuccess('', [
            // 当前是否
            'is_release' => $is_release,
            // 当前是否在申请中
            'is_applying' => SupplyApplyModel::isApplying($this->user['user_id']),
            // 当前用户信息
            'user' => $this->user,
            // 信息
            'release' => $this->release,
            'setting' => $setting,
            // 背景图
            'background' => '',
        ]);
 
    }
 
    /**
     * 当前用户是否为
     */
    private function isReleaseUser()
    {
        return !!$this->release && !$this->release['is_delete'];
    }
 
    /**
     * 申请状态
     */
    public function apply($platform= '')
    {
        $reason='';
        $user = $this->user;
 
        $applyData = (new SupplyApplyModel())->getDatail($user['user_id']);
        if(!empty($applyData) && $applyData["apply_status"]["value"]==30){
            $reason = $applyData["reject_reason"];
        }
 
        return $this->renderSuccess('', [
            // 当前是否为
            'is_release' => $this->isReleaseUser(),
            'reason' => $reason,//被驳回的原因
            // 当前是否在申请中
            'is_applying' => SupplyApplyModel::isApplying($user['user_id']),
            // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
            'template_arr' => MessageModel::getMessageByNameArr($platform, ['supply_apply_user']),
        ]);
 
    }
 
    /**
     * 提交申请
     */
    public function submit()
    {
        $data = $this->postData();
        if (empty($data['name']) || empty($data['mobile'])) {
            throw new BaseException(['msg' => '姓名或者手机号不能为空']);
        }
        $model = new SupplyApplyModel;
        if ($model->submit($this->user, $data)) {
            return $this->renderSuccess('成功');
        }
        return $this->renderError($model->getError() ?: '提交失败');
    }
 
     public function topay()
    {
        $data = $this->postData();
        //获取支付连盟币
         $setting = Setting::getAll();
         $setting = $setting['settlement']['values'];
         $user = $this->user;
         $pay_price = empty($setting['check_price']) ? 0 : $setting['check_price'];
         $point = $user['points'];
         if($pay_price > $point){
             return $this->renderError('连盟币不足');
         }
         $release= $this->release;
         if($release['is_check'] == 1){
             return $this->renderError('权限已开通,请勿重复开通');
         }
        $model = new SupplyUserModel;
        if ($model->topay($user, $pay_price)) {
            return $this->renderSuccess('开通成功');
        }
        return $this->renderError($model->getError() ?: '提交失败');
    }
}