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
<?php
 
namespace app\api\controller\plus\operations;
 
use app\api\controller\Controller;
use app\api\model\plus\agent\User as AgentUserModel;
use app\api\model\plus\operations\Setting;
use app\api\model\plus\operations\Operations as OperationsUserModel;
use app\api\model\plus\team\Order as TeamOrder;
use app\api\model\settings\Message as MessageModel;
use app\common\model\product\Product as ProductModel;
 
/**
 * 运营中心
 */
class Operations extends Controller
{
    // 用户
    private $user;
    // 运营中心用户
    private $operations;
    // 运营中心设置
    private $setting;
    /**
     * 构造方法
     */
    public function initialize()
    {
        // 用户信息
        $this->user = $this->getUser();
        // 运营中心用户信息
        $this->operations = OperationsUserModel::detail($this->user['user_id']);
        // 运营中心设置
        $this->setting = Setting::getAll();
    }
 
    /**
     * 运营中心
     */
    public function center()
    {
        // 是否为运营中心用户
        $is_operations = $this->isOperationsUser();
        if ($is_operations) {
            event('OperationsUserGrade', $this->user['user_id']);
            $this->operations = OperationsUserModel::detail($this->user['user_id']);
        }
        $setting = $this->setting['basic']['values'];
        // 购买商品
        $productList = [];
        if ($setting['become'] == '100'|| $setting['become'] == '110') {
            if ($setting['become__buy_product_ids']) {
                $productList = (new ProductModel)->getListByIds($setting['become__buy_product_ids']);
            }
        }
        return $this->renderSuccess('', [
            // 当前是否为运营中心用户
            'is_operations' => $is_operations,
            // 当前用户信息
            'user' => $this->user,
            // 运营中心用户信息
            'operations' => $this->operations,
            // 背景图
            'background' => $this->setting['background']['values']['index'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            'setting' => $setting,
            'productList' => $productList,
        ]);
    }
 
    /**
     * 运营中心提现信息
     */
    public function cash($platform = '')
    {
        // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
        $template_arr = MessageModel::getMessageByNameArr($platform, ['operations_cash_user']);
        return $this->renderSuccess('', [
            // 运营中心用户信息
            'operations' => $this->operations,
            // 结算设置
            'settlement' => $this->setting['settlement']['values'],
            // 背景图
            'background' => $this->setting['background']['values']['cash_apply'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            // 小程序消息
            'template_arr' => $template_arr
        ]);
    }
 
    /**
     * 是否为运营中心用户
     * @return bool
     */
    private function isOperationsUser()
    {
        return !!$this->operations && !$this->operations['is_delete'];
    }
 
}