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.
zhishifufei_php/application/admin/controller/agent/Agentuser.php

222 lines
7.8 KiB

10 months ago
<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\controller\agent;
use app\admin\controller\AuthController;
use service\JsonService as Json;
use app\admin\model\special\AgentUser as AgentUserModel;
use service\JsonService;
use think\Url;
use app\merchant\model\merchant\AgentMenus;
/**代理控制器
* Class EventRegistration
* @package app\admin\controller\ump
*/
class Agentuser extends AuthController
{
/**
* 代理列表展示
* @return
* */
public function index(){
return $this->fetch();
}
/**
* 讲师列表获取
* @return
* */
public function lecturer_list()
{
$where = parent::getMore([
['page', 1],
['is_show', ''],
['limit', 20],
['title', ''],
['entry_type',2],
['mer_id',0]
]);
return JsonService::successlayui(AgentUserModel::getLecturerList($where));
}
/**添加/编辑
* @param int $id
* @return mixed|void
* @throws \think\exception\DbException
*/
public function create($id = 0)
{
if ($id) {
$lecturer = AgentUserModel::get($id);
$lecturer['label'] = json_decode($lecturer['label']);
$lecturer['introduction'] = htmlspecialchars_decode($lecturer['introduction']);
if (!$lecturer) return JsonService::fail('讲师信息不存在!');
} else {
$lecturer = [];
}
$this->assign(['lecturer' => json_encode($lecturer), 'id' => $id]);
return $this->fetch();
}
/**
* 添加和修改机构
* @param int $id 修改
* @return JsonService
* */
public function save_lecturer($id = 0)
{
$data = parent::postMore([
['lecturer_name', ''],
['lecturer_head', ''],
['label', []],
['phone', ''],
['explain', ''],
['introduction', ''],
['sort', 0],
['is_show', 1],
]);
$data['lecturer_name'] = preg_replace("#(^( |\s)+|( |\s)+$)#", "", $data['lecturer_name']);
$data['entry_type'] = 2;
if (!$data['lecturer_name']) return JsonService::fail('请输入机构负责人');
if (mb_strlen($data['lecturer_name']) > 8) return JsonService::fail('机构负责人不能超过8个字');
if (!$data['lecturer_head']) return JsonService::fail('请选择机构头像');
if (!count($data['label'])) return JsonService::fail('请输入标签');
if (!$data['explain']) return JsonService::fail('请编辑讲师说明');
if (!$data['introduction']) return JsonService::fail('请编辑讲师介绍');
$data['label'] = json_encode($data['label']);
$data['introduction'] = htmlspecialchars($data['introduction']);
if ($id) {
AgentUserModel::edit($data, $id);
return JsonService::successful('修改成功');
} else {
$data['add_time'] = time();
if (!AgentUserModel::be(['lecturer_name' => $data['lecturer_name'], 'lecturer_head' => $data['lecturer_head'], 'label' => $data['label'], 'phone' => $data['phone'], 'is_del' => 0])) {
$res = AgentUserModel::set($data);
} else {
return JsonService::fail('机构已存在');
}
if ($res)
return JsonService::successful('添加成功');
else
return JsonService::fail('添加失败');
}
}
/**生成机构后台
* @return mixed
*/
public function mercreate($id)
{
$lecturer = AgentUserModel::get($id);
$this->assign([
'title' => '添加机构后台',
'lecturer' => json_encode($lecturer),
'action' => Url::build('save'),
'menus' => json(AgentMenus::ruleList())->getContent()
]);
return $this->fetch();
}
/**
* 添加讲师商户
*/
public function save()
{
$data = parent::postMore([
'account',
['id', 0],
'conf_pwd',
'pwd',
'phone',
'mer_avatar',
'mark',
'mer_address',
['checked_menus', [], '', 'rules'],
['username', 0],
['status', 0],
['type', 1],
['mer_data_divide', 0],
['mer_event_divide', 0],
['mer_special_divide', 0],
['mer_store_divide', 0],
['mer_test_divide', 0],
['gold_divide', 0]
]);
if (!is_array($data['rules']) || !count($data['rules'])) return JsonService::fail('请选择最少一个权限');
$data['rules'] = implode(',', $data['rules']);
if (!$data['account']) return JsonService::fail('请输入代理端后台账号');
if (AgentUserModel::where('account', trim($data['account']))->where('is_del', 0)->count() > 1) return JsonService::fail('代理账号已存在,请使用别的商户账号注册');
if (!$data['pwd']) return JsonService::fail('请输入代理端后台登陆密码');
if ($data['pwd'] != $data['conf_pwd']) return JsonService::fail('两次输入密码不相同');
$res = AgentUserModel::where('id',$data['id'])->update($data);
if($res){
return JsonService::successful('代理后台生成成功!');
}else{
return JsonService::successful('代理后台生成失败!');
}
}
public function update()
{
$data = parent::postMore([
['id', 0],
'phone',
'mark',
'mer_address',
['checked_menus', [], '', 'rules'],
['username', 0],
['status', 0],
['type', 1],
['mer_data_divide', 0],
['mer_event_divide', 0],
['mer_special_divide', 0],
['mer_store_divide', 0],
['mer_test_divide', 0],
['gold_divide', 0]
]);
$id = $data['id'];
if (!is_array($data['rules']) || !count($data['rules'])) return JsonService::fail('请选择最少一个权限');
$data['rules'] = implode(',', $data['rules']);
AgentUserModel::where('id',$id)->update($data);
return JsonService::successful('修改成功!');
}
/**代理端信息
* @param $id
* @return mixed
*/
public function edit($id)
{
$role = AgentUserModel::get($id);
$menus = json(AgentMenus::ruleList())->getContent();
$this->assign(['title' => '编辑讲师后台', 'roles' => $role->toJson(), 'menus' => $menus, 'action' => Url::build('update', array('id' => $id))]);
return $this->fetch('edit');
}
/**
* 删除代理后台
* @param int $id 修改的主键
* @return json
* */
public function delete($id = 0)
{
if (!$id) return JsonService::fail('缺少参数');
$merchant = AgentUserModel::get($id);
if (!$merchant) return JsonService::fail('代理后台不存在');
if (AgentUserModel::delMerchant($id)) {
return JsonService::successful('删除成功');
} else
return JsonService::fail(UserEnterModel::getErrorInfo('删除失败'));
}
}