admin/addon/fenxiao/api/controller/Apply.php

137 lines
4.7 KiB
PHP

<?php
/**
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.cdcloudshop.com
* =========================================================
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config;
use addon\fenxiao\model\FenxiaoApply;
use addon\fenxiao\model\Fenxiao;
use app\api\controller\BaseApi;
/**
* 申请分销商
*/
class Apply extends BaseApi
{
/**
* 判断分销商名称是否存在
*/
public function existFenxiaoName()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$fenxiao_name = isset($this->params['fenxiao_name']) ? $this->params['fenxiao_name'] : '';//分销商名称
if (empty($fenxiao_name)) {
return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
}
$apply_model = new FenxiaoApply();
$res = $apply_model->existFenxiaoName($fenxiao_name, $this->site_id);
return $this->response($res);
}
/**
* 申请成为分销商
*/
public function applyFenxiao()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$fenxiao_name = isset($this->params['fenxiao_name']) ? $this->params['fenxiao_name'] : '';//分销商名称
$mobile = isset($this->params['mobile']) ? $this->params['mobile'] : '';//联系电话
$fenxiao_condition = isset($this->params['fenxiao_condition']) ? $this->params['fenxiao_condition'] : 0;//申请是否无条件
$config = new Config();
$basics_config = $config->getFenxiaoBasicsConfig($this->site_id)['data']['value'];
if (!$basics_config['level']) return $this->response($this->error('', '未开启分销功能'));
if($basics_config['is_apply'] == 1){
if (empty($fenxiao_name)) {
return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
}
if (empty($mobile)) {
return $this->response($this->error('', 'REQUEST_MOBILE'));
}
$apply_model = new FenxiaoApply();
$res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile);
} else if ($basics_config['is_apply'] == 0) {
$apply_model = new Fenxiao();
$res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id);
} else {
return $this->response($this->error('', '未开启分销商申请'));
}
return $this->response($res);
}
public function info()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$apply_model = new Fenxiao();
$apply_model->getFenxiaoInfo([['member_id', '=', $this->member_id]], 'apply_id,fenxiao_name,parent,member_id,mobile,nickname,headimg,level_id,level_name,status');
}
/**
* 获取申请分销商状态
* @return false|string
*/
public function status()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$apply_model = new FenxiaoApply();
$res = $apply_model->getFenxiaoApplyInfo([['member_id', '=', $this->member_id]], 'status');
return $this->response($res);
}
/**
* Common: 用户代理申请基本信息获取
* Author: wu-hui
* Time: 2023/02/27 10:35
* @return false|string
*/
public function upgradeBase(){
// 用户登录
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
// 获取设置信息
$config = (new Config())->getFenxiaoBasicsConfig($this->site_id)['data'];
$data['upgrade_agree'] = $config['value']['upgrade_agree'] ?? '';
// 获取申请信息
$field = "username,phone,id_card,id_card_front,id_card_reverse,status,reject_cause";
$data['info'] = (new FenxiaoApply())->getFenXiaoUpgradeApplyInfo([['member_id','=',$this->member_id]],$field)['data'];
return $this->response($this->success($data));
}
/**
* Common: 代理申请信息
* Author: wu-hui
* Time: 2023/02/27 10:31
* @return false|string
*/
public function upgradeApply(){
// 用户登录
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$this->params['member_id'] = $token['data']['member_id'];
return $this->response((new FenxiaoApply())->upgradeApply($this->params));
}
}