<?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;
|
}
|
}
|