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
<?php
 
namespace app\api\model\plus\operations;
 
use app\api\model\user\User as UserModel;
use app\common\model\plus\operations\Apply as ApplyModel;
use app\common\model\plus\operations\Setting as OperationsSetting;
use app\common\model\plus\operations\Operations as OperationsModel;
/**
 * 运营中心申请模型
 */
class Apply extends ApplyModel
{
    /**
     * 购买指定商品成为运营中心
     * @param $userId
     * @param $productIds
     * @param $appId
     * @return bool
     */
    public function becomeOperationsUser($userId, $productIds, $appId)
    {
        // 验证是否设置购买商品成为运营中心
        $config = OperationsSetting::getItem('basic', $appId);
        if ($config['is_open']==0) {
            return false;
        }
        // 判断商品是否在设置范围内
        $intersect = array_intersect($productIds, $config['become__buy_product_ids']);
        if (empty($intersect)) {
            return false;
        }
 
        // 检查用户是否已有待审核的申请
        $existing = self::detail(['user_id' => $userId, 'apply_status' => 10]);
        log_write($existing);
        if ($existing) {
            return false;
        }
 
        log_write(OperationsModel::isregionUser($userId));
        // 检查用户是否已经是运营中心
        if (OperationsModel::isregionUser($userId)) {
            return false;
        }
 
        // 获取用户信息
        $user = UserModel::detail($userId);
        if (!$user) {
            return false;
        }
 
        // 生成运营中心入驻申请(管辖区域在审核时分配,默认为0)
        $data = [
            'user_id' => $userId,
            'real_name' => $user['nickName'] ?: $user['userName'],
            'mobile' => $user['mobile'] ?: '',
            'referee_id' => $user['referee_id'] ?: 0,
            'province_id' => 0,
            'city_id' => 0,
            'area_id' => 0,
            'region_level' => 1, // 默认为省级,审核时可调整
            'apply_type' => 10, // 需要后台审核
            'apply_status' => 10, // 待审核
            'apply_time' => time(),
            'audit_time' => 0,
            'reject_reason' => '',
            'app_id' => $appId,
        ];
 
        // 保存申请记录
        return $this->save($data) !== false;
    }
}