作者 何书鹏

经销商管理

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use Exception;
use fast\Random;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Validate;
use app\admin\model\Admin;
use app\admin\model\AuthGroupAccess;
/**
* 经销商管理
*
* @icon fa fa-circle-o
*/
class Dealer extends Backend
{
/**
* Dealer模型对象
* @var \app\admin\model\Dealer
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Dealer;
}
public function import()
{
parent::import();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['admin'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','dealer_name','createtime']);
$row->visible(['admin']);
$row->getRelation('admin')->visible(['username']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
if(empty($params['username'])) {
$this->error('请填写账号');
}
if(empty($params['password'])) {
$this->error('请填写密码');
}
if (!Validate::is($params['password'], '\S{6,16}')) {
$this->error('密码长度必须在6-16位之间,不能包含空格');
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
// 生成管理员账号
$admin_model = new Admin;
$params['salt'] = Random::alnum();
$params['password'] = md5(md5($params['password']) . $params['salt']);
$params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
$admin_model->validate('Admin.add')->save($params);
(new AuthGroupAccess)->save(['uid'=>$admin_model->id,'group_id'=>2]);
// 增加经销商
$params['admin_id'] = $admin_model->id;
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'ID',
'Admin_id' => '管理员ID',
'Dealer_name' => '经销商名称',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'Deletetime' => '删除时间',
'Admin.username' => '经销商账号'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
use traits\model\SoftDelete;
class Dealer extends Model
{
use SoftDelete;
// 表名
protected $name = 'dealer';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
];
public function admin()
{
return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Dealer extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Dealer_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-dealer_name" data-rule="required" class="form-control" name="row[dealer_name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Admin.username')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-username" data-rule="required" class="form-control" name="row[username]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('密码')}:</label>
<div class="col-xs-12 col-sm-8">
<input type="password" data-rule="required;password" class="form-control" name="row[password]" autocomplete="new-password" value=""/>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Dealer_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-dealer_name" data-rule="required" class="form-control" name="row[dealer_name]" type="text" value="{$row.dealer_name|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('dealer/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('dealer/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('dealer/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('dealer/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
<div class="dropdown btn-group {:$auth->check('dealer/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
<a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('dealer/recyclebin')?'':'hide'}" href="dealer/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a>-->
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('dealer/edit')}"
data-operate-del="{:$auth->check('dealer/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
{:build_toolbar('refresh')}
<a class="btn btn-info btn-multi btn-disabled disabled {:$auth->check('dealer/restore')?'':'hide'}" href="javascript:;" data-url="dealer/restore" data-action="restore"><i class="fa fa-rotate-left"></i> {:__('Restore')}</a>
<a class="btn btn-danger btn-multi btn-disabled disabled {:$auth->check('dealer/destroy')?'':'hide'}" href="javascript:;" data-url="dealer/destroy" data-action="destroy"><i class="fa fa-times"></i> {:__('Destroy')}</a>
<a class="btn btn-success btn-restoreall {:$auth->check('dealer/restore')?'':'hide'}" href="javascript:;" data-url="dealer/restore" title="{:__('Restore all')}"><i class="fa fa-rotate-left"></i> {:__('Restore all')}</a>
<a class="btn btn-danger btn-destroyall {:$auth->check('dealer/destroy')?'':'hide'}" href="javascript:;" data-url="dealer/destroy" title="{:__('Destroy all')}"><i class="fa fa-times"></i> {:__('Destroy all')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover"
data-operate-restore="{:$auth->check('dealer/restore')}"
data-operate-destroy="{:$auth->check('dealer/destroy')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -503,10 +503,90 @@ class User extends Base
* @ApiHeaders (name="token", type="string", required=true, description="请求的token")
*
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"code": 1,
"msg": "成功",
"time": "1609056357",
"data": {
"url": "http://www.recruit.top/uploads/job/1.png", //职位海报地址
"url": "http://www.ant.top/uploads/user/1.png?v=1609056359", //海报地址
"goods": { //免费领取海报商品
"id": 1, //商品ID
"type": "normal",
"title": "分销海报",
"subtitle": "分销海报",
"weigh": 0,
"category_ids": "3",
"image": "https://yixiaoxian.qiniu.broing.cn/uploads/20201224/FpqzUt7YTrXlZUsarlqD8heEHA4O.png",
"images": [
"https://yixiaoxian.qiniu.broing.cn/uploads/20201224/FpqzUt7YTrXlZUsarlqD8heEHA4O.png"
],
"params": [],
"content": "海报",
"price": "0",
"original_price": "100.00",
"is_sku": 0,
"likes": 0,
"views": 100,
"sales": 0,
"show_sales": 0,
"service_ids": "",
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": null,
"activity_type": null,
"sku_price": [{ //商品规格
"id": 1, //规格ID
"goods_sku_ids": null,
"goods_id": 1,
"weigh": 0,
"image": null,
"stock": 999999,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.00", //商品价格
"goods_sku_text": null,
"status": "up",
"goods_sku_id_arr": [
""
]
}],
"stock": 999999,
"favorite": {
"id": 6,
"user_id": 1,
"goods_id": 1,
"deletetime": null
},
"dispatch_type_arr": [
"express"
],
"service": [],
"sku": [],
"coupons": [{
"id": 1,
"name": "满100减10",
"type": "cash",
"goods_ids": "0",
"amount": "10.00",
"enough": "100.00",
"stock": 0,
"limit": 1,
"gettime": {
"start": 1607875200,
"end": 1610640000
},
"usetime": {
"start": "2020.12.18",
"end": "2021.01.30"
},
"description": "满100减10",
"usetimestart": 1608220800,
"usetimeend": 1611936000,
"gettimestart": 1607875200,
"gettimeend": 1610640000
}]
}
}
})
*/
... ... @@ -558,6 +638,8 @@ class User extends Base
->water($qrcode,[253,441])
->save($filename);
$url = request()->domain().'/'.$filename.'?v='.time();
$this->success('成功',compact('url'));
// 免费领取推广海报商品
$goods = \addons\shopro\model\Goods::getGoodsDetail(1);
$this->success('成功',compact('url','goods'));
}
}
... ...
... ... @@ -4104,10 +4104,90 @@
<div class="row">
<div class="col-md-12">
<pre id="sample_response75">{
'code':'1',
'msg':'返回成功',
"code": 1,
"msg": "成功",
"time": "1609056357",
"data": {
"url": "http://www.recruit.top/uploads/job/1.png", //职位海报地址
"url": "http://www.ant.top/uploads/user/1.png?v=1609056359", //海报地址
"goods": { //免费领取海报商品
"id": 1, //商品ID
"type": "normal",
"title": "分销海报",
"subtitle": "分销海报",
"weigh": 0,
"category_ids": "3",
"image": "https://yixiaoxian.qiniu.broing.cn/uploads/20201224/FpqzUt7YTrXlZUsarlqD8heEHA4O.png",
"images": [
"https://yixiaoxian.qiniu.broing.cn/uploads/20201224/FpqzUt7YTrXlZUsarlqD8heEHA4O.png"
],
"params": [],
"content": "海报",
"price": "0",
"original_price": "100.00",
"is_sku": 0,
"likes": 0,
"views": 100,
"sales": 0,
"show_sales": 0,
"service_ids": "",
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": null,
"activity_type": null,
"sku_price": [{ //商品规格
"id": 1, //规格ID
"goods_sku_ids": null,
"goods_id": 1,
"weigh": 0,
"image": null,
"stock": 999999,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.00", //商品价格
"goods_sku_text": null,
"status": "up",
"goods_sku_id_arr": [
""
]
}],
"stock": 999999,
"favorite": {
"id": 6,
"user_id": 1,
"goods_id": 1,
"deletetime": null
},
"dispatch_type_arr": [
"express"
],
"service": [],
"sku": [],
"coupons": [{
"id": 1,
"name": "满100减10",
"type": "cash",
"goods_ids": "0",
"amount": "10.00",
"enough": "100.00",
"stock": 0,
"limit": 1,
"gettime": {
"start": 1607875200,
"end": 1610640000
},
"usetime": {
"start": "2020.12.18",
"end": "2021.01.30"
},
"description": "满100减10",
"usetimestart": 1608220800,
"usetimeend": 1611936000,
"gettimestart": 1607875200,
"gettimeend": 1610640000
}]
}
}
}</pre>
</div>
... ... @@ -11359,7 +11439,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2020-12-26 21:24:59 </div>
Generated on 2020-12-27 18:05:19 </div>
<div class="col-md-6" align="right">
<a href="./" target="_blank">My Website</a>
</div>
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'dealer/index' + location.search,
add_url: 'dealer/add',
edit_url: 'dealer/edit',
del_url: 'dealer/del',
multi_url: 'dealer/multi',
import_url: 'dealer/import',
table: 'dealer',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
{field: 'dealer_name', title: __('Dealer_name'), operate: 'LIKE'},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'dealer/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '130px',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'Restore',
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'dealer/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'dealer/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...