@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\store;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\shopro\store\Store as StoreModel;
|
||||
|
||||
/**
|
||||
* 门店
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Apply extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Apply模型对象
|
||||
* @var \app\admin\model\shopro\store\Apply
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\shopro\store\Apply;
|
||||
$this->view->assign("openweeksList", $this->model->getOpenweeksList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$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();
|
||||
$total = $this->model
|
||||
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->count();
|
||||
|
||||
$list = $this->model
|
||||
->with(['user'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->limit($offset, $limit)
|
||||
->select();
|
||||
|
||||
foreach ($list as $row) {
|
||||
$row->visible(['id','name','user_id','user','images','realname','phone','province_name','city_name','area_name','province_id','city_id','area_id','address','latitude','longitude','openhours','openweeks','apply_num','status','status_msg','createtime','updatetime']);
|
||||
}
|
||||
$list = collection($list)->toArray();
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return $this->success('操作成功', null, $result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function detail($ids = null)
|
||||
{
|
||||
$row = $this->model->with('user')->where('id', 'in', $ids)->find();
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assignconfig("row", $row);
|
||||
$this->view->assign("row", $row);
|
||||
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 审核操作
|
||||
*
|
||||
* @param [type] $id
|
||||
* @return void
|
||||
*/
|
||||
public function applyOper($id)
|
||||
{
|
||||
$status = $this->request->post('status', -1);
|
||||
$status_msg = $this->request->post('status_msg', '');
|
||||
|
||||
$apply = $this->model->get($id);
|
||||
|
||||
if ($apply->status != 0) {
|
||||
$this->error('该申请已处理,不能重复处理');
|
||||
}
|
||||
|
||||
$result = \think\Db::transaction(function () use ($apply, $status, $status_msg) {
|
||||
$apply->status = $status;
|
||||
$apply->status_msg = $status_msg;
|
||||
$apply->save();
|
||||
|
||||
if ($status == 1) {
|
||||
// 把门店申请信息同步到门店
|
||||
$store = new StoreModel();
|
||||
$store->name = $apply->name;
|
||||
$store->images = $apply->images;
|
||||
$store->realname = $apply->realname;
|
||||
$store->phone = $apply->phone;
|
||||
$store->province_name = $apply->province_name;
|
||||
$store->city_name = $apply->city_name;
|
||||
$store->area_name = $apply->area_name;
|
||||
$store->province_id = $apply->province_id;
|
||||
$store->city_id = $apply->city_id;
|
||||
$store->area_id = $apply->area_id;
|
||||
$store->address = $apply->address;
|
||||
$store->latitude = $apply->latitude;
|
||||
$store->longitude = $apply->longitude;
|
||||
$store->service_type = 'radius';
|
||||
$store->service_radius = 1000;
|
||||
$store->openhours = $apply->openhours;
|
||||
$store->openweeks = $apply->openweeks;
|
||||
$store->status = $apply->status;
|
||||
$store->save();
|
||||
|
||||
// 添加门店管理员
|
||||
$userStore = \think\Db::name('shopro_user_store')->insert([
|
||||
'user_id' => $apply->user_id,
|
||||
'store_id' => $store->id
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'apply' => $apply,
|
||||
'store' => $store ?? null
|
||||
];
|
||||
});
|
||||
|
||||
// 门店审核结果通知
|
||||
$user = \addons\shopro\model\User::where('id', $result['apply']['user_id'])->find();
|
||||
$user && $user->notify(
|
||||
new \addons\shopro\notifications\store\Apply([
|
||||
'apply' => $result['apply'],
|
||||
'store' => $result['store'],
|
||||
'event' => 'store_apply'
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
return $this->success('操作成功', null, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\store;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 门店统计
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Dashboard extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
$this->model = new \app\admin\model\shopro\order\Order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$params = $this->request->request();
|
||||
$datetimerange = $params['datetimerange'] ? explode(' - ', $params['datetimerange']) : [];
|
||||
$startTime = strtotime($datetimerange[0]);
|
||||
$endTime = strtotime($datetimerange[1]);
|
||||
$where = [
|
||||
'createtime' => ['between', [$startTime, $endTime]]
|
||||
];
|
||||
$store_id = isset($params['store_id']) ? $params['store_id'] : 0;
|
||||
|
||||
$list = $this->buildSearch()
|
||||
->with(['item' => function ($query) use ($store_id) {
|
||||
if ($store_id) {
|
||||
$query->where('store_id', $store_id);
|
||||
} else {
|
||||
$query->where('store_id', '<>', 0);
|
||||
}
|
||||
}])
|
||||
->where($where)
|
||||
->order('id')
|
||||
->select();
|
||||
|
||||
$data = $this->getTotalData($list);
|
||||
|
||||
$this->success('数据中心', null, $data);
|
||||
}
|
||||
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
private function getTotalData($list) {
|
||||
// 支付订单
|
||||
$data['payOrderNum'] = 0;
|
||||
$data['payOrderArr'] = [];
|
||||
//支付金额
|
||||
$data['payAmountNum'] = 0;
|
||||
$data['payAmountArr'] = [];
|
||||
// 代发货
|
||||
$data['noSentNum'] = 0;
|
||||
$data['noSentArr'] = [];
|
||||
//下单人数
|
||||
$data['downNum'] = 0;
|
||||
$data['downArr'] = [];
|
||||
//总订单数
|
||||
$data['orderNum'] = 0;
|
||||
$data['orderArr'] = [];
|
||||
//售后维权
|
||||
$data['aftersaleNum'] = 0;
|
||||
$data['aftersaleArr'] = [];
|
||||
//退款订单
|
||||
$data['refundNum'] = 0;
|
||||
$data['refundArr'] = [];
|
||||
// 待配送/待核销
|
||||
$data['offSentNum'] = 0;
|
||||
$data['offSentArr'] = [];
|
||||
|
||||
$userIds = [];
|
||||
foreach ($list as $key => $order) {
|
||||
// 总订单数
|
||||
$data['orderNum']++;
|
||||
$data['orderArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $order['createtime'] * 1000,
|
||||
'user_id' => $order['user_id']
|
||||
];
|
||||
|
||||
if (!in_array($order['user_id'], $userIds)) {
|
||||
$userIds[] = $order['user_id'];
|
||||
$data['downNum']++;
|
||||
$data['downArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $order['createtime'] * 1000,
|
||||
'user_id' => $order['user_id']
|
||||
];
|
||||
}
|
||||
|
||||
if ($order['status'] > 0) {
|
||||
// 支付订单
|
||||
$data['payOrderNum']++;
|
||||
$data['payOrderArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $order['createtime'] * 1000,
|
||||
'user_id' => $order['user_id']
|
||||
];
|
||||
|
||||
// 支付金额
|
||||
$data['payAmountNum'] = bcadd($data['payAmountNum'], $order['pay_fee'], 2);
|
||||
$data['payAmountArr'][] = [
|
||||
'counter' => $order['pay_fee'],
|
||||
'createtime' => $order['createtime'] * 1000
|
||||
];
|
||||
|
||||
$flagnoSent = false;
|
||||
$flagoffSent = false;
|
||||
$flagaftersale = false;
|
||||
$flagrefund = false;
|
||||
foreach ($order['item'] as $k => $item) {
|
||||
//待备货
|
||||
if (!$flagnoSent && $item['dispatch_status'] == 0 && $item['refund_status'] <= 0) {
|
||||
$data['noSentNum']++;
|
||||
$data['noSentArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $item['createtime'] * 1000
|
||||
];
|
||||
|
||||
$flagnoSent = true;
|
||||
}
|
||||
|
||||
//待配送/待核销
|
||||
if (!$flagoffSent && $item['dispatch_status'] == 1 && $item['refund_status'] <= 0) {
|
||||
$data['offSentNum']++;
|
||||
$data['offSentArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $item['createtime'] * 1000
|
||||
];
|
||||
$flagoffSent = true;
|
||||
}
|
||||
|
||||
// 维权
|
||||
if (!$flagaftersale && $item['aftersale_status'] > 0) {
|
||||
$data['aftersaleNum']++;
|
||||
$data['aftersaleArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $item['createtime'] * 1000
|
||||
];
|
||||
|
||||
$flagaftersale = true;
|
||||
}
|
||||
// 退款
|
||||
if (!$flagrefund && $item['refund_status'] > 0) {
|
||||
$data['refundNum']++;
|
||||
$data['refundArr'][] = [
|
||||
'counter' => 1,
|
||||
'createtime' => $item['createtime'] * 1000
|
||||
];
|
||||
|
||||
$flagrefund = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function buildSearch()
|
||||
{
|
||||
$params = $this->request->request();
|
||||
$store_id = isset($params['store_id']) ? $params['store_id'] : 0;
|
||||
|
||||
$name = $this->model->getQuery()->getTable();
|
||||
$tableName = $name . '.';
|
||||
|
||||
$orders = $this->model->withTrashed();
|
||||
|
||||
$orders = $orders->whereExists(function ($query) use ($store_id, $tableName) {
|
||||
$itemTableName = (new \app\admin\model\shopro\order\OrderItem())->getQuery()->getTable();
|
||||
|
||||
$query = $query->table($itemTableName)->where($itemTableName . '.order_id=' . $tableName . 'id');
|
||||
|
||||
if ($store_id) {
|
||||
$query = $query->where('store_id', $store_id);
|
||||
} else {
|
||||
$query = $query->where('store_id', '<>', 0);
|
||||
}
|
||||
|
||||
return $query;
|
||||
});
|
||||
|
||||
return $orders;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\store;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 门店
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Store extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Store模型对象
|
||||
* @var \app\admin\model\shopro\store\Store
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\shopro\store\Store;
|
||||
|
||||
// 获取 amap key
|
||||
$config = \addons\shopro\model\Config::get(['name' => 'services']);
|
||||
$config = ($config && $config->value) ? json_decode($config->value, true) : [];
|
||||
|
||||
$amapConfig = $config['amap'] ?? [];
|
||||
$hasAmap = ($amapConfig && $amapConfig['appkey']) ? true : false;
|
||||
$this->assignconfig("hasAmap", $hasAmap);
|
||||
$this->assign("amap", $amapConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
$search = $this->request->get('search');
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
$total = $this->model
|
||||
->where($where)
|
||||
->whereOr('name', 'LIKE', "%$search%")
|
||||
->order($sort, $order)
|
||||
->count();
|
||||
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->whereOr('name', 'LIKE', "%$search%")
|
||||
->order($sort, $order)
|
||||
->limit($offset, $limit)
|
||||
->select();
|
||||
$list = collection($list)->toArray();
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return $this->success('门店列表', null, $result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$search = $this->request->get('search');
|
||||
|
||||
$list = $this->model
|
||||
->where('name', 'LIKE', "%$search%")
|
||||
->order('id', 'desc')
|
||||
->select();
|
||||
|
||||
return $this->success('操作成功', null, $list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post();
|
||||
|
||||
if ($params) {
|
||||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||
$params[$this->dataLimitField] = $this->auth->id;
|
||||
}
|
||||
$result = false;
|
||||
$params = json_decode($params['data'], true);
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
$this->setStoreManager($this->model->id, $params['user_ids']);
|
||||
if (!$result) {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post();
|
||||
if ($params) {
|
||||
$params = json_decode($params['data'], true);
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$row->allowField(true)->save($params);
|
||||
$this->setStoreManager($row->id, $params['user_ids']);
|
||||
$row->save();
|
||||
$result = true;
|
||||
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 updated'));
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
|
||||
$this->assignconfig("row", $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function setStatus($ids, $status)
|
||||
{
|
||||
if ($ids) {
|
||||
$pk = $this->model->getPk();
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||||
}
|
||||
$list = $this->model->where($pk, 'in', $ids)->select();
|
||||
|
||||
$count = 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($list as $k => $v) {
|
||||
$v->status = $status;
|
||||
$count += $v->save();
|
||||
}
|
||||
Db::commit();
|
||||
} catch (PDOException $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($count) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
public function select()
|
||||
{
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
$searchWhere = $this->request->get('searchWhere');
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
$total = $this->model
|
||||
->where($where)
|
||||
->where(function ($query) use ($searchWhere) {
|
||||
return $query
|
||||
->whereOr('id', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('name', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('address', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('province_name', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('city_name', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('area_name', 'LIKE', "%$searchWhere%");
|
||||
})
|
||||
->order($sort, $order)
|
||||
->count();
|
||||
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where(function ($query) use ($searchWhere) {
|
||||
return $query
|
||||
->whereOr('id', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('name', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('address', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('province_name', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('city_name', 'LIKE', "%$searchWhere%")
|
||||
->whereOr('area_name', 'LIKE', "%$searchWhere%");
|
||||
})
|
||||
->order($sort, $order)
|
||||
->limit($offset, $limit)
|
||||
->select();
|
||||
$list = collection($list)->toArray();
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return $this->success('门店列表', null, $result);
|
||||
}
|
||||
}
|
||||
|
||||
private function setStoreManager($store_id, $user_ids)
|
||||
{
|
||||
$user_ids = explode(',', $user_ids);
|
||||
$existUserIds = Db::name('shopro_user_store')
|
||||
->where('store_id', $store_id)
|
||||
->column('user_id');
|
||||
$newUserIds = array_diff($user_ids, $existUserIds);
|
||||
|
||||
$deleteUserIds = array_diff($existUserIds, $user_ids);
|
||||
|
||||
$newData = [];
|
||||
foreach ($newUserIds as $id) {
|
||||
$newData[] = [
|
||||
'user_id' => $id,
|
||||
'store_id' => $store_id
|
||||
];
|
||||
}
|
||||
if (!empty($newData)) {
|
||||
Db::name('shopro_user_store')->insertAll($newData);
|
||||
}
|
||||
|
||||
if (!empty($deleteUserIds)) {
|
||||
Db::name('shopro_user_store')->where('user_id', 'in', $deleteUserIds)
|
||||
->where('store_id', $store_id)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户