'微信', 20 => '支付宝', 30 => '银行卡', ]; /** * 申请状态 * @var array */ public $applyStatus = [ 10 => '待审核', 20 => '审核通过', 30 => '驳回', ]; /** * 关联用户表 * @return \think\model\relation\BelongsTo */ public function user() { return $this->belongsTo('app\common\model\user\User'); } /** * 关联VIP专区用户表 * @return \think\model\relation\BelongsTo */ public function vipUser() { return $this->belongsTo('User'); } /** * 获取详情 */ public static function detail($apply_id) { return (new static())->find($apply_id); } /** * 购买指定商品成为VIP用户 * @param $userId * @param $productIds * @param $appId * @param $order * @return bool */ public function becomeVipUser($userId, $productIds, $appId, $order) { // 验证是否设置 $config = Setting::getItem('basic', $appId); if (empty($config['become__buy_product_ids'])) { return false; } // 判断商品是否在设置范围内 $intersect = array_intersect($productIds, $config['become__buy_product_ids']); $purchase_count=0; foreach ($order['product'] as $product) { // 检查商品是否是指定的分红商品 if (in_array($product['product_id'], $config['become__buy_product_ids'])||$product['is_vip']==1) { // 获取商品数量 $quantity = $product['total_num']; $purchase_count+=$quantity; } } if ($purchase_count<=0){ return false; } // 检查用户是否已经是VIP用户 if(User::isVipUser($userId)) { return false; } //同时成为分销商 $referee_id = agentReferee::getRefereeUserId($userId, 1); agentUser::add($userId, [ 'referee_id' => $referee_id, 'app_id' => $appId, ]); // 新增VIP用户 User::add($userId, [ 'referee_id' => AgentRefereeModel::getRefereeUserId($userId, 1), 'app_id' => $appId, ]); return true; } /** * 审核状态 * @param $value * @return array */ public function getApplyStatusAttr($value) { $method = [10 => '待审核', 20 => '审核通过', 30 => '驳回']; return ['text' => $method[$value], 'value' => $value]; } /** * 打款方式 * @param $value * @return array */ public function getPayTypeAttr($value) { $method = [10 => '微信', 20 => '支付宝', 30 => '银行卡']; return ['text' => $method[$value], 'value' => $value]; } /** * 获取申请列表 */ public function getList($search) { $model = $this->with(['user', 'vipUser']) ->order(['create_time' => 'desc']); if (!empty($search['nick_name'])) { $model = $model->where('user.nickName', 'like', '%' . $search['nick_name'] . '%'); } if (isset($search['apply_status']) && $search['apply_status'] > -1) { $model = $model->where('apply_status', '=', $search['apply_status']); } return $model->paginate($search['list_rows']); } }