user = $this->getUser(); // 用户信息 // 代理设置 $this->setting = Setting::getAll(); // 分销商用户信息 $this->agent = AgentUserModel::detail($this->user['user_id']); } /** * 验证是否可以申请 */ public function check() { $data = $this->postData(); if (empty($data['region_level']) || empty($data['province_id'])) { throw new BaseException(['msg' => '代理数据不完整']); } if ($data['region_level'] == 2 && empty($data['city_id'])) { throw new BaseException(['msg' => '代理数据不完整']); } if ($data['region_level'] == 3 && empty($data['area_id'])) { throw new BaseException(['msg' => '代理数据不完整']); } if (empty($data['name']) || empty($data['mobile'])) { throw new BaseException(['msg' => '用户名或者手机号为空']); } $setting = $this->setting['basic']['values']; $levels = [ '1' => $setting['province_condition'], '2' => $setting['city_condition'], '3' => $setting['area_condition'] ]; $level_condition = $levels[$data['region_level']]; $agent_total = $agent_money = $team_money = 0; $is_pass = false; $checkData = []; $checkData = [ 'region_level' => intval($data['region_level']), 'become' => $setting['become'], 'target' => $level_condition ]; if ($setting['become'] == 10) { $is_pass = true; } //统计下级分销商总数 if ($setting['become'] == '40' && $this->agent) { $agent_total = $this->agent['first_num'] + $this->agent['second_num']+ $this->agent['third_num']; $is_pass = $agent_total >= $level_condition; $checkData['now_target'] = $agent_total; $checkData['text'] = '下级分销商人数'; $checkData['unit'] = '人'; } // 累计佣金 if ($setting['become'] == '50' && $this->agent) { $agent_money = $this->agent['total_money']; $is_pass = $agent_money >= $level_condition; $checkData['now_target'] = $agent_money; $checkData['text'] = '累计分销佣金'; $checkData['unit'] = '元'; } // 累计团队业绩 if ($setting['become'] == '70') { $team_money = TeamOrder::getOrderAllPrice($this->user['user_id']); $is_pass = $team_money >= $level_condition; $checkData['now_target'] = $team_money; $checkData['text'] = '累计团队业绩'; $checkData['unit'] = '元'; } // 单次消费 if ($setting['become'] == '90') { $maxMoney = (new OrderModel)->where('user_id', '=', $this->user['user_id']) ->where('order_status', '=', 30) ->max('total_price'); $is_pass = $maxMoney >= $level_condition; $checkData['now_target'] = $maxMoney; $checkData['text'] = '单次最大消费'; $checkData['unit'] = '元'; } // 购买商品 // $productList = []; // if ($setting['become'] == '100') { // if ($setting['become__buy_product_ids']) { // $productList = (new ProductModel)->getListByIds($setting['become__buy_product_ids']); // $userBuyCount = (new OrderProductModel)->where('product_id', 'IN', $setting['become__buy_product_ids']) // ->where('user_id', '=', $this->user['user_id']) // ->count(); // $is_pass = $userBuyCount > 0; // } // } return $this->renderSuccess('', [ 'is_pass' => $is_pass, 'checkData' => $checkData ]); } /** * 提交队长申请 */ public function submit() { $data = $this->postData(); $model = new regionApplyModel; if ($model->submit($this->user, $data)) { return $this->renderSuccess('成功'); } return $this->renderError($model->getError() ?: '提交失败'); } /* *获取队长协议 */ public function getAgreement() { $model = new Setting(); $data = $model->getItem('license'); return $this->renderSuccess('', compact('data')); } }