You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
5.2 KiB
154 lines
5.2 KiB
10 months ago
|
<?php
|
||
|
|
||
|
namespace app\admin\controller\agent;
|
||
|
|
||
|
use app\admin\controller\AuthController;
|
||
|
use app\admin\model\questions\TestPaper;
|
||
|
use app\admin\model\user\User;
|
||
|
use app\admin\model\merchant\UserEnter;
|
||
|
use app\merchant\model\merchant\MerchantMenus;
|
||
|
use app\merchant\model\merchant\InstitutionMenus;
|
||
|
use service\HookService;
|
||
|
use service\JsonService;
|
||
|
use service\SystemConfigService;
|
||
|
use service\UploadService;
|
||
|
use think\Request;
|
||
|
use think\Url;
|
||
|
use app\admin\model\merchant\Merchant as MerchantModel;
|
||
|
use app\admin\model\special\AgentUser as AgentUserModel;
|
||
|
use app\agent\model\agent\AgentUser as AgentUserAdminModel;
|
||
|
use app\admin\model\special\Lecturer;
|
||
|
use app\admin\model\special\Special;
|
||
|
use app\admin\model\download\DataDownload as DownloadModel;
|
||
|
use app\admin\model\store\StoreProduct as ProductModel;
|
||
|
use app\admin\model\ump\EventRegistration as EventRegistrationModel;
|
||
|
use app\admin\model\merchant\UserEnter as UserEnterModel;
|
||
|
use think\Db;
|
||
|
|
||
|
/**
|
||
|
* Class Agent
|
||
|
* @package app\admin\controller\merchant
|
||
|
*/
|
||
|
class Agent extends AuthController
|
||
|
{
|
||
|
/**讲师后台列表
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
return $this->fetch();
|
||
|
}
|
||
|
/**
|
||
|
* 讲师列表获取
|
||
|
* @return
|
||
|
* */
|
||
|
public function lecturer_merchant_list()
|
||
|
{
|
||
|
$where = parent::getMore([
|
||
|
['page', 1],
|
||
|
['limit', 20],
|
||
|
['title', ''],
|
||
|
]);
|
||
|
return JsonService::successlayui(MerchantModel::getLecturerMerchantList($where));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除讲师后台
|
||
|
* @param int $id 修改的主键
|
||
|
* @return json
|
||
|
* */
|
||
|
public function delete($id = 0)
|
||
|
{
|
||
|
if (!$id) return JsonService::fail('缺少参数');
|
||
|
$merchant = MerchantModel::get($id);
|
||
|
if (!$merchant) return JsonService::fail('讲师后台不存在');
|
||
|
if (MerchantModel::delMerchant($id)) {
|
||
|
Lecturer::where('mer_id', $id)->update(['is_del' => 1]);
|
||
|
User::where('uid', $merchant['uid'])->update(['business' => 0]);
|
||
|
return JsonService::successful('删除成功');
|
||
|
} else
|
||
|
return JsonService::fail(UserEnterModel::getErrorInfo('删除失败'));
|
||
|
}
|
||
|
|
||
|
/**编辑讲师信息
|
||
|
* @param $id
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function edit($id)
|
||
|
{
|
||
|
$role = MerchantModel::get($id);
|
||
|
$merchant = Db::name('lecturer')->where('mer_id',$id)->value('entry_type');
|
||
|
if($merchant == 1){
|
||
|
$menus = json(MerchantMenus::ruleList())->getContent();
|
||
|
}else{
|
||
|
$menus = json(InstitutionMenus::ruleList())->getContent();
|
||
|
}
|
||
|
$this->assign(['title' => '编辑讲师后台', 'roles' => $role->toJson(), 'menus' => $menus, 'action' => Url::build('update', array('id' => $id))]);
|
||
|
return $this->fetch('edit');
|
||
|
}
|
||
|
|
||
|
public function insedit($id)
|
||
|
{
|
||
|
$role = MerchantModel::get($id);
|
||
|
$merchant = Db::name('lecturer')->where('mer_id',$id)->value('entry_type');
|
||
|
if($merchant == 1){
|
||
|
$menus = json(MerchantMenus::ruleList())->getContent();
|
||
|
}else{
|
||
|
$menus = json(InstitutionMenus::ruleList())->getContent();
|
||
|
}
|
||
|
$this->assign(['title' => '编辑讲师后台', 'roles' => $role->toJson(), 'menus' => $menus, 'action' => Url::build('update', array('id' => $id))]);
|
||
|
return $this->fetch('insedit');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改状态
|
||
|
* @param $id
|
||
|
* @return \think\response\Json
|
||
|
*/
|
||
|
public function modify($id, $status)
|
||
|
{
|
||
|
if (!$id) return JsonService::fail('数据错误');
|
||
|
$merchantInfo = MerchantModel::where('id', $id)->where('is_del', 0)->find();
|
||
|
if (!$merchantInfo) return JsonService::fail('数据错误');
|
||
|
$data['status'] = $status;
|
||
|
if (!MerchantModel::edit($data, $id)) {
|
||
|
return JsonService::fail(MerchantModel::getErrorInfo('修改失败,请稍候再试!'));
|
||
|
} else {
|
||
|
$dat['is_show'] = $status;
|
||
|
Lecturer::edit($dat, $merchantInfo['lecturer_id'], 'id');
|
||
|
return JsonService::successful('修改成功!');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**登录
|
||
|
* @param $id
|
||
|
* @throws \think\Exception
|
||
|
* @throws \think\db\exception\DataNotFoundException
|
||
|
* @throws \think\db\exception\ModelNotFoundException
|
||
|
* @throws \think\exception\DbException
|
||
|
*/
|
||
|
public function login($id)
|
||
|
{
|
||
|
$agentInfo = AgentUserModel::where('id', $id)->where('is_del', 0)->find();
|
||
|
if (!$agentInfo) return $this->failed('登陆的机构后台不存在!');
|
||
|
AgentUserAdminModel::setLoginInfo($agentInfo->toArray());
|
||
|
AgentUserAdminModel::setMerchantInfo($agentInfo->toArray());
|
||
|
return $this->redirect(Url::build('/agent/index/index'));
|
||
|
}
|
||
|
/**重置密码
|
||
|
* @param $id
|
||
|
*/
|
||
|
public function reset_pwd($id)
|
||
|
{
|
||
|
if (!$id) return JsonService::fail('参数错误失败!');
|
||
|
$pwd = 1234567;
|
||
|
// var_dump($id);
|
||
|
$adminPwd = AgentUserModel::where('id', $id)->value('pwd');
|
||
|
if ($pwd == $adminPwd) return JsonService::fail('您的密码无需重置!');
|
||
|
if (AgentUserModel::where('id', $id)->update(['pwd' => 1234567]))
|
||
|
return JsonService::successful('重置成功!');
|
||
|
else
|
||
|
return JsonService::fail('重置失败!');
|
||
|
}
|
||
|
}
|