商家管理添加导出功能
This commit is contained in:
parent
f704fb38cf
commit
0f24fc61bc
@ -160,7 +160,8 @@ class Store extends AdminBase
|
||||
return JsonServer::success('操作成功');
|
||||
}
|
||||
}
|
||||
public function adjustFirstLeader()
|
||||
|
||||
public function adjustFirstLeader()
|
||||
{
|
||||
if($this->request->isPost()) {
|
||||
$params = $this->request->post();
|
||||
@ -181,4 +182,14 @@ class Store extends AdminBase
|
||||
'first_leader' => $firstLeader
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportData()
|
||||
{
|
||||
$ids = $this->request->post('ids');
|
||||
$result = StoreLogic::exportData($ids);
|
||||
if(false === $result) {
|
||||
return JsonServer::error(StoreLogic::getError() ?: '导出失败');
|
||||
}
|
||||
return JsonServer::success('', $result);
|
||||
}
|
||||
}
|
||||
@ -8,8 +8,9 @@ use app\common\basics\Logic;
|
||||
use app\common\enum\ShopEnum;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\shop\ShopAdmin;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\ExportExcelServer;
|
||||
use app\common\server\UrlServer;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -17,9 +18,9 @@ class StoreLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* NOTE: 商家列表
|
||||
* @author: 张无忌
|
||||
* @param $get
|
||||
* @return array|bool
|
||||
* @author: 张无忌
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
@ -29,7 +30,7 @@ class StoreLogic extends Logic
|
||||
];
|
||||
|
||||
if (!empty($get['name']) and $get['name'])
|
||||
$where[] = ['name', 'like', '%'.$get['name'].'%'];
|
||||
$where[] = ['name', 'like', '%' . $get['name'] . '%'];
|
||||
|
||||
if (!empty($get['type']) and is_numeric($get['type']))
|
||||
$where[] = ['type', '=', $get['type']];
|
||||
@ -61,7 +62,7 @@ class StoreLogic extends Logic
|
||||
$where[] = ['expire_time', '>', 0];
|
||||
} else {
|
||||
// 未到期
|
||||
$condition = "expire_time=0 OR expire_time >". time();
|
||||
$condition = "expire_time=0 OR expire_time >" . time();
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,43 +75,43 @@ class StoreLogic extends Logic
|
||||
->with(['category', 'admin'])
|
||||
->append(['expire_desc'])
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
$user_msg = User::where("id",$item['reference_user_id'])->find();
|
||||
if($user_msg!=null){
|
||||
$item['nickname'] = $user_msg['nickname'];
|
||||
}else{
|
||||
$item['nickname'] = "";
|
||||
$user_msg = User::where("id", $item['reference_user_id'])->find();
|
||||
if ($user_msg != null) {
|
||||
$item['nickname'] = $user_msg['nickname'];
|
||||
} else {
|
||||
$item['nickname'] = "";
|
||||
}
|
||||
$item['category'] = $item['category']['name'] ?? '未知';
|
||||
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
|
||||
$item['is_run'] = ShopEnum::getShopIsRunDesc($item['is_run']);
|
||||
$item['category'] = $item['category']['name'] ?? '未知';
|
||||
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
|
||||
$item['is_run'] = ShopEnum::getShopIsRunDesc($item['is_run']);
|
||||
$item['is_freeze'] = ShopEnum::getShopFreezeDesc($item['is_freeze']);
|
||||
$item['is_recommend'] = ShopEnum::getShopIsRecommendDesc($item['is_recommend']);
|
||||
$item['account'] = $item['admin']['account'] ?? '';
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
return ['count' => $lists['total'], 'lists' => $lists['data']];
|
||||
} catch (Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
return ['error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: 商家详细
|
||||
* @author: 张无忌
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author: 张无忌
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new Shop();
|
||||
$detail = $model->json(['other_qualifications'],true)->findOrEmpty($id)->toArray();
|
||||
$detail = $model->json(['other_qualifications'], true)->findOrEmpty($id)->toArray();
|
||||
$detail['expire_time'] = $detail['expire_time'] == '无期限' ? 0 : $detail['expire_time'];
|
||||
|
||||
$detail['business_license'] = $detail['business_license'] ? UrlServer::getFileUrl($detail['business_license']) : '';
|
||||
@ -131,9 +132,9 @@ class StoreLogic extends Logic
|
||||
|
||||
/**
|
||||
* NOTE: 新增商家
|
||||
* @author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @author: 张无忌
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
@ -144,31 +145,31 @@ class StoreLogic extends Logic
|
||||
|
||||
// 创建商家
|
||||
$shop = Shop::create([
|
||||
'cid' => $post['cid'],
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'nickname' => $post['nickname'],
|
||||
'mobile' => $post['mobile'],
|
||||
'logo' => $post['logo'] ?? '',
|
||||
'background' => $post['background'] ?? '',
|
||||
'license' => $post['license'] ?? '',
|
||||
'keywords' => $post['keywords'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'weight' => $post['weight'] ?? 0,
|
||||
'cid' => $post['cid'],
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'nickname' => $post['nickname'],
|
||||
'mobile' => $post['mobile'],
|
||||
'logo' => $post['logo'] ?? '',
|
||||
'background' => $post['background'] ?? '',
|
||||
'license' => $post['license'] ?? '',
|
||||
'keywords' => $post['keywords'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'weight' => $post['weight'] ?? 0,
|
||||
'trade_service_fee' => $post['trade_service_fee'],
|
||||
|
||||
'is_run' => $post['is_run'],
|
||||
'is_freeze' => $post['is_freeze'],
|
||||
'is_product_audit' => $post['is_product_audit'],
|
||||
'is_recommend' => $post['is_recommend'] ?? 0,
|
||||
'expire_time' => !empty($post['expire_time']) ? strtotime($post['expire_time']) : 0,
|
||||
'province_id' => $post['province_id'] ?? 0,
|
||||
'city_id' => $post['city_id'] ?? 0,
|
||||
'district_id' => $post['district_id'] ?? 0,
|
||||
'address' => $post['address'] ?? '',
|
||||
'longitude' => $post['longitude'] ?? '',
|
||||
'latitude' => $post['latitude'] ?? '',
|
||||
'delivery_type' => $post['delivery_type'] ?? [1]
|
||||
|
||||
'is_run' => $post['is_run'],
|
||||
'is_freeze' => $post['is_freeze'],
|
||||
'is_product_audit' => $post['is_product_audit'],
|
||||
'is_recommend' => $post['is_recommend'] ?? 0,
|
||||
'expire_time' => !empty($post['expire_time']) ? strtotime($post['expire_time']) : 0,
|
||||
'province_id' => $post['province_id'] ?? 0,
|
||||
'city_id' => $post['city_id'] ?? 0,
|
||||
'district_id' => $post['district_id'] ?? 0,
|
||||
'address' => $post['address'] ?? '',
|
||||
'longitude' => $post['longitude'] ?? '',
|
||||
'latitude' => $post['latitude'] ?? '',
|
||||
'delivery_type' => $post['delivery_type'] ?? [1]
|
||||
]);
|
||||
// 创建账号
|
||||
// 新增商家登录账号
|
||||
@ -199,9 +200,9 @@ class StoreLogic extends Logic
|
||||
|
||||
/**
|
||||
* NOTE: 编辑商家
|
||||
* @author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @author: 张无忌
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
@ -210,36 +211,36 @@ class StoreLogic extends Logic
|
||||
self::checkDeliveryType($post);
|
||||
|
||||
Shop::update([
|
||||
'cid' => $post['cid'],
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'nickname' => $post['nickname'],
|
||||
'mobile' => $post['mobile'],
|
||||
'logo' => $post['logo'] ?? '',
|
||||
'keywords' => $post['keywords'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'cid' => $post['cid'],
|
||||
'type' => $post['type'],
|
||||
'name' => $post['name'],
|
||||
'nickname' => $post['nickname'],
|
||||
'mobile' => $post['mobile'],
|
||||
'logo' => $post['logo'] ?? '',
|
||||
'keywords' => $post['keywords'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'trade_service_fee' => $post['trade_service_fee'],
|
||||
'trade_promotion_fee' => $post['trade_promotion_fee'],
|
||||
|
||||
|
||||
'promotion_buy_fee' => $post['promotion_buy_fee'],
|
||||
'team_first_fee' => $post['team_first_fee'],
|
||||
'team_second_fee' => $post['team_second_fee'],
|
||||
'team_third_fee' => $post['team_third_fee'],
|
||||
|
||||
'is_run' => $post['is_run'],
|
||||
'is_freeze' => $post['is_freeze'],
|
||||
'is_product_audit' => $post['is_product_audit'],
|
||||
'expire_time' => !empty($post['expire_time']) ? strtotime($post['expire_time']) : 0,
|
||||
'province_id' => $post['province_id'] ?? 0,
|
||||
'city_id' => $post['city_id'] ?? 0,
|
||||
'district_id' => $post['district_id'] ?? 0,
|
||||
'address' => $post['address'] ?? '',
|
||||
'longitude' => $post['longitude'] ?? '',
|
||||
'latitude' => $post['latitude'] ?? '',
|
||||
'delivery_type' => $post['delivery_type'] ?? [1],
|
||||
'business_license' => empty($post['business_license']) ? '' : UrlServer::setFileUrl($post['business_license']),
|
||||
'team_first_fee' => $post['team_first_fee'],
|
||||
'team_second_fee' => $post['team_second_fee'],
|
||||
'team_third_fee' => $post['team_third_fee'],
|
||||
|
||||
'is_run' => $post['is_run'],
|
||||
'is_freeze' => $post['is_freeze'],
|
||||
'is_product_audit' => $post['is_product_audit'],
|
||||
'expire_time' => !empty($post['expire_time']) ? strtotime($post['expire_time']) : 0,
|
||||
'province_id' => $post['province_id'] ?? 0,
|
||||
'city_id' => $post['city_id'] ?? 0,
|
||||
'district_id' => $post['district_id'] ?? 0,
|
||||
'address' => $post['address'] ?? '',
|
||||
'longitude' => $post['longitude'] ?? '',
|
||||
'latitude' => $post['latitude'] ?? '',
|
||||
'delivery_type' => $post['delivery_type'] ?? [1],
|
||||
'business_license' => empty($post['business_license']) ? '' : UrlServer::setFileUrl($post['business_license']),
|
||||
'other_qualifications' => isset($post['other_qualifications']) ? json_encode($post['other_qualifications'], JSON_UNESCAPED_UNICODE) : '',
|
||||
], ['id'=>$post['id']]);
|
||||
], ['id' => $post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
@ -250,9 +251,9 @@ class StoreLogic extends Logic
|
||||
|
||||
/**
|
||||
* NOTE: 设置商家
|
||||
* @author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @author: 张无忌
|
||||
*/
|
||||
public static function set($post)
|
||||
{
|
||||
@ -261,8 +262,8 @@ class StoreLogic extends Logic
|
||||
'is_distribution' => $post['is_distribution'] ?? 0,
|
||||
'is_recommend' => $post['is_recommend'] ?? 0,
|
||||
'is_pay' => $post['is_pay'] ?? 1, //是否开启支付功能,默认开启
|
||||
'weight' => $post['weight']
|
||||
], ['id'=>$post['id']]);
|
||||
'weight' => $post['weight']
|
||||
], ['id' => $post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
@ -273,29 +274,29 @@ class StoreLogic extends Logic
|
||||
|
||||
/**
|
||||
* NOTE: 更新账号密码
|
||||
* @author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
* @author: 张无忌
|
||||
*/
|
||||
public static function account($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
if(!isset($post['account']) || empty($post['account'])) {
|
||||
if (!isset($post['account']) || empty($post['account'])) {
|
||||
throw new \think\Exception('账户不能为空');
|
||||
}
|
||||
$shopAdmin = ShopAdmin::where([
|
||||
['account', '=', trim($post['account'])],
|
||||
['shop_id', '<>', $post['id']]
|
||||
])->findOrEmpty();
|
||||
if(!$shopAdmin->isEmpty()) {
|
||||
if (!$shopAdmin->isEmpty()) {
|
||||
throw new \think\Exception('账户已存在,请更换其他名称重试');
|
||||
}
|
||||
|
||||
$shopAdmin = ShopAdmin::where(['shop_id' => $post['id'], 'root' => 1])->findOrEmpty();
|
||||
|
||||
$shopAdminUpdateData = [
|
||||
'account' => $post['account'],
|
||||
'account' => $post['account'],
|
||||
'update_time' => time()
|
||||
];
|
||||
if (!empty($post['password'])) {
|
||||
@ -326,7 +327,7 @@ class StoreLogic extends Logic
|
||||
{
|
||||
try {
|
||||
$result = Shop::whereIn('id', $ids)->update([
|
||||
$field => $value,
|
||||
$field => $value,
|
||||
'update_time' => time()
|
||||
]);
|
||||
return $result;
|
||||
@ -360,11 +361,12 @@ class StoreLogic extends Logic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static function adjustFirstLeader($params)
|
||||
|
||||
public static function adjustFirstLeader($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
switch($params['type']) {
|
||||
switch ($params['type']) {
|
||||
// 指定推荐人
|
||||
case 'assign':
|
||||
$formatData = self::assignFirstLeader($params);
|
||||
@ -378,12 +380,13 @@ class StoreLogic extends Logic
|
||||
Shop::where(['id' => $params['id']])->update($formatData);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function assignFirstLeader($params)
|
||||
{
|
||||
if (empty($params['first_id'])) {
|
||||
@ -392,7 +395,7 @@ class StoreLogic extends Logic
|
||||
$firstLeader = User::where('id', $params['first_id'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
if(empty($firstLeader)) {
|
||||
if (empty($firstLeader)) {
|
||||
throw new \think\Exception('推荐人不存在');
|
||||
}
|
||||
|
||||
@ -404,6 +407,7 @@ class StoreLogic extends Logic
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function clearFirstLeader($params)
|
||||
{
|
||||
$data = [
|
||||
@ -411,4 +415,69 @@ class StoreLogic extends Logic
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function exportData($ids)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['del', '=', 0]
|
||||
];
|
||||
|
||||
$condition = 'del=0';
|
||||
|
||||
$model = new Shop();
|
||||
|
||||
if ($ids) {
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->whereRaw($condition)
|
||||
->whereIn('id', $ids)
|
||||
->order('id', 'desc')
|
||||
->order('weight', 'asc')
|
||||
->with(['category', 'admin'])
|
||||
->append(['expire_desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
} else {
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->whereRaw($condition)
|
||||
->order('id', 'desc')
|
||||
->order('weight', 'asc')
|
||||
->with(['category', 'admin'])
|
||||
->append(['expire_desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$user_msg = User::where("id", $item['reference_user_id'])->find();
|
||||
if ($user_msg != null) {
|
||||
$item['nickname'] = $user_msg['nickname'];
|
||||
} else {
|
||||
$item['nickname'] = "";
|
||||
}
|
||||
$item['category'] = $item['category']['name'] ?? '未知';
|
||||
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
|
||||
$item['is_run'] = ShopEnum::getShopIsRunDesc($item['is_run']);
|
||||
$item['account'] = $item['admin']['account'] ?? '';
|
||||
}
|
||||
$title = [
|
||||
'id' => '商家编号',
|
||||
'name' => '商家名称',
|
||||
'type' => '商家类型',
|
||||
'account' => '商家账号',
|
||||
'category' => '主营类目',
|
||||
'is_run' => '营业状态',
|
||||
'nickname' => '推荐人',
|
||||
'create_time' => '开通日期',
|
||||
];
|
||||
$export = new ExportExcelServer();
|
||||
$export->setFileName('商家管理列表');
|
||||
$result = $export->createExcel($title, $lists);
|
||||
return ['url' => $result];
|
||||
} catch (Exception $e) {
|
||||
return ['error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,6 +109,7 @@
|
||||
<div class="layui-inline">
|
||||
<a class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">搜索</a>
|
||||
<a class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</a>
|
||||
<a class="layui-btn layui-btn-sm layuiadmin-btn-ad layui-btn-primary " lay-submit lay-filter="data-export">导出</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -392,8 +393,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
form.on("submit(search)", function(data){
|
||||
table.reload("like-table-lists", {
|
||||
where: data.field,
|
||||
@ -403,7 +402,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
form.on("submit(clear-search)", function(){
|
||||
$("#name").val("");
|
||||
$("#type").val("");
|
||||
@ -423,5 +421,27 @@
|
||||
});
|
||||
});
|
||||
|
||||
// 导出
|
||||
form.on('submit(data-export)', function (data) {
|
||||
var checkStatus = table.checkStatus('like-table-lists');
|
||||
var checkData = checkStatus.data;
|
||||
var ids = [];
|
||||
// 取出选中的行ID
|
||||
checkData.forEach(function (item) {
|
||||
ids.push(parseInt(item['id']));
|
||||
});
|
||||
|
||||
var field = data.field;
|
||||
like.ajax({
|
||||
url: '{:url("shop.Store/exportData")}'
|
||||
, data: {ids}
|
||||
, type: 'post'
|
||||
, success: function (res) {
|
||||
if (res.code == 1) {
|
||||
window.location.href = res.data.url;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user