<?php
|
|
namespace app\api\controller\plus\release;
|
|
use app\api\controller\Controller;
|
use app\api\model\plus\release\DemandApply as DemandApplyModel;
|
use app\api\model\plus\release\DemandUser as DemandUserModel;
|
use app\api\model\settings\Message as MessageModel;
|
use app\common\exception\BaseException;
|
use app\api\model\plus\release\Setting;
|
|
/**
|
* 首页
|
*/
|
class DemandIndex extends Controller
|
{
|
// 当前用户
|
private $user;
|
|
/**
|
* 构造方法
|
*/
|
public function initialize()
|
{
|
$this->user = $this->getUser(); // 用户信息
|
// 需求方信息
|
$this->release = DemandUserModel::detail($this->user['user_id']);
|
}
|
|
/**
|
* 信息
|
*/
|
public function index()
|
{
|
$is_release = $this->isReleaseUser();
|
//获取开通权限连盟币
|
$setting = Setting::getAll();
|
$setting = $setting['settlement']['values'];
|
|
return $this->renderSuccess('', [
|
'is_release' => $is_release,
|
// 当前是否在申请中
|
'is_applying' => DemandApplyModel::isApplying($this->user['user_id']),
|
// 当前用户信息
|
'user' => $this->user,
|
// 信息
|
'release' => $this->release,
|
'setting' => $setting,
|
// 背景图
|
'background' => '',
|
]);
|
|
}
|
|
/**
|
* 当前用户是否为
|
*/
|
private function isReleaseUser()
|
{
|
return !!$this->release && !$this->release['is_delete'];
|
}
|
|
/**
|
* 申请状态
|
*/
|
public function apply($platform= '')
|
{
|
$reason='';
|
$user = $this->user;
|
|
$applyData = (new DemandApplyModel())->getDatail($user['user_id']);
|
if(!empty($applyData) && $applyData["apply_status"]["value"]==30){
|
$reason = $applyData["reject_reason"];
|
}
|
|
return $this->renderSuccess('', [
|
// 当前是否为
|
'is_release' => $this->isReleaseUser(),
|
'reason' => $reason,//被驳回的原因
|
// 当前是否在申请中
|
'is_applying' => DemandApplyModel::isApplying($user['user_id']),
|
// 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
|
'template_arr' => MessageModel::getMessageByNameArr($platform, ['demand_apply_user']),
|
]);
|
|
}
|
|
/**
|
* 提交申请
|
*/
|
public function submit()
|
{
|
$data = $this->postData();
|
if (empty($data['name']) || empty($data['mobile'])) {
|
throw new BaseException(['msg' => '姓名或者手机号不能为空']);
|
}
|
$model = new DemandApplyModel;
|
if ($model->submit($this->user, $data)) {
|
return $this->renderSuccess('成功');
|
}
|
return $this->renderError($model->getError() ?: '提交失败');
|
}
|
|
public function topay()
|
{
|
$data = $this->postData();
|
//获取支付连盟币
|
$setting = Setting::getAll();
|
$setting = $setting['settlement']['values'];
|
$user = $this->user;
|
$pay_price = empty($setting['check_price']) ? 0 : $setting['check_price'];
|
$point = $user['points'];
|
if($pay_price > $point){
|
return $this->renderError('连盟币不足');
|
}
|
$release= $this->release;
|
if($release['is_check'] == 1){
|
return $this->renderError('权限已开通,请勿重复开通');
|
}
|
$model = new DemandUserModel;
|
if ($model->topay($user, $pay_price)) {
|
return $this->renderSuccess('开通成功');
|
}
|
return $this->renderError($model->getError() ?: '提交失败');
|
}
|
}
|