diff --git a/server/application/admin/controller/Appeal.php b/server/application/admin/controller/Appeal.php index 9605ede..e50ed55 100644 --- a/server/application/admin/controller/Appeal.php +++ b/server/application/admin/controller/Appeal.php @@ -35,4 +35,25 @@ class Appeal extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['order', 'master']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Invoice.php b/server/application/admin/controller/Invoice.php index 8eb8286..3d27f5d 100644 --- a/server/application/admin/controller/Invoice.php +++ b/server/application/admin/controller/Invoice.php @@ -35,4 +35,25 @@ class Invoice extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['user', 'merchant']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Master.php b/server/application/admin/controller/Master.php index 388dd57..854d636 100644 --- a/server/application/admin/controller/Master.php +++ b/server/application/admin/controller/Master.php @@ -35,4 +35,25 @@ class Master extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['user']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Merchant.php b/server/application/admin/controller/Merchant.php index 5cad79b..296e01e 100644 --- a/server/application/admin/controller/Merchant.php +++ b/server/application/admin/controller/Merchant.php @@ -35,4 +35,25 @@ class Merchant extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['user']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Order.php b/server/application/admin/controller/Order.php index 68e443b..32c2791 100644 --- a/server/application/admin/controller/Order.php +++ b/server/application/admin/controller/Order.php @@ -40,4 +40,25 @@ class Order extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['user', 'master']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Review.php b/server/application/admin/controller/Review.php index 1326b04..44685e1 100644 --- a/server/application/admin/controller/Review.php +++ b/server/application/admin/controller/Review.php @@ -34,4 +34,25 @@ class Review extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['user', 'master', 'order']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Service.php b/server/application/admin/controller/Service.php index 06c2c3a..9f8f71b 100644 --- a/server/application/admin/controller/Service.php +++ b/server/application/admin/controller/Service.php @@ -3,20 +3,24 @@ namespace app\admin\controller; use app\common\controller\Backend; +use think\Db; +use think\exception\PDOException; +use think\exception\ValidateException; +use Exception; /** - * 服务项目 + * 服务项目与商品管理 * * @icon fa fa-circle-o */ class Service extends Backend { - /** * Service模型对象 * @var \app\admin\model\Service */ protected $model = null; + protected $relationSearch = true; public function _initialize() { @@ -24,15 +28,205 @@ class Service extends Backend $this->model = new \app\admin\model\Service; $this->view->assign("priceTypeList", $this->model->getPriceTypeList()); $this->view->assign("statusList", $this->model->getStatusList()); + + // 获取全部可用的公共增项服务列表 + $addonsPool = Db::name('service_addon') + ->where('status', 'normal') + ->order('weigh desc, id asc') + ->select(); + $this->view->assign("addonsPool", $addonsPool); } - + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['cat']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } /** - * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 - * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 - * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + * 添加服务商品 */ + 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; + } + // 处理工项类型与增项配置 + $params = $this->formatServiceConfig($params); + + $result = false; + Db::startTrans(); + try { + $result = $this->model->allowField(true)->save($params); + $serviceId = $this->model->id; + + // 处理规格列表 + $this->syncSpecs($serviceId, $this->request->post('specs/a', [])); + + Db::commit(); + } catch (ValidateException|PDOException|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) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $params = $this->preExcludeFields($params); + + // 处理工项类型与增项配置 + $params = $this->formatServiceConfig($params); + + $result = false; + Db::startTrans(); + try { + $result = $row->allowField(true)->save($params); + + // 同步处理规格列表 + $this->syncSpecs($row->id, $this->request->post('specs/a', [])); + + Db::commit(); + } catch (ValidateException|PDOException|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', '')); + } + + // 解析工项与增项配置以供视图回显 + $serviceTypes = []; + if (!empty($row->service_types)) { + $serviceTypes = is_array($row->service_types) ? $row->service_types : json_decode($row->service_types, true); + } + $addons = []; + if (!empty($row->addons)) { + $addons = is_array($row->addons) ? $row->addons : json_decode($row->addons, true); + } + + // 获取已有规格 + $specs = Db::name('service_spec') + ->where('service_id', $row->id) + ->where('status', 'normal') + ->order('weigh desc, id asc') + ->select(); + + $this->view->assign("row", $row); + $this->view->assign("serviceTypes", $serviceTypes ?: []); + $this->view->assign("assignedAddons", $addons ?: []); + $this->view->assign("specs", $specs ?: []); + return $this->view->fetch(); + } + + /** + * 格式化工项与增项输入数据 + */ + protected function formatServiceConfig($params) + { + // 工项类型 JSON + if (isset($params['service_types_raw'])) { + $params['service_types'] = is_string($params['service_types_raw']) ? $params['service_types_raw'] : json_encode($params['service_types_raw'], JSON_UNESCAPED_UNICODE); + unset($params['service_types_raw']); + } + // 增项服务 JSON + if (isset($params['addons_raw'])) { + $params['addons'] = is_string($params['addons_raw']) ? $params['addons_raw'] : json_encode($params['addons_raw'], JSON_UNESCAPED_UNICODE); + unset($params['addons_raw']); + } + return $params; + } + + /** + * 同步商品规格表 + */ + protected function syncSpecs($serviceId, $specsInput) + { + if (empty($serviceId)) return; + $now = time(); + $keepIds = []; + if (!empty($specsInput) && is_array($specsInput)) { + foreach ($specsInput as $item) { + $name = trim(isset($item['name']) ? $item['name'] : ''); + if ($name === '') continue; + $specPrice = isset($item['base_price']) ? (float)$item['base_price'] : 0.00; + $specDesc = isset($item['description']) ? trim($item['description']) : ''; + $specId = isset($item['id']) ? (int)$item['id'] : 0; + + if ($specId > 0) { + Db::name('service_spec')->where('id', $specId)->where('service_id', $serviceId)->update([ + 'name' => $name, + 'base_price' => $specPrice, + 'description' => $specDesc, + 'updatetime' => $now, + ]); + $keepIds[] = $specId; + } else { + $newId = Db::name('service_spec')->insertGetId([ + 'service_id' => $serviceId, + 'name' => $name, + 'base_price' => $specPrice, + 'description' => $specDesc, + 'weigh' => 0, + 'status' => 'normal', + 'createtime' => $now, + 'updatetime' => $now, + ]); + $keepIds[] = $newId; + } + } + } + // 将未在列表中的历史规格软下架或删除 + $delQuery = Db::name('service_spec')->where('service_id', $serviceId); + if (!empty($keepIds)) { + $delQuery->whereNotIn('id', $keepIds); + } + $delQuery->delete(); + } } diff --git a/server/application/admin/controller/Settle.php b/server/application/admin/controller/Settle.php index e470101..207cf11 100644 --- a/server/application/admin/controller/Settle.php +++ b/server/application/admin/controller/Settle.php @@ -34,4 +34,25 @@ class Settle extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['order', 'master']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/Withdraw.php b/server/application/admin/controller/Withdraw.php index dd93771..d2ffebe 100644 --- a/server/application/admin/controller/Withdraw.php +++ b/server/application/admin/controller/Withdraw.php @@ -35,4 +35,25 @@ class Withdraw extends Backend */ + + protected $relationSearch = true; + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['master']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } } diff --git a/server/application/admin/controller/service/Addon.php b/server/application/admin/controller/service/Addon.php new file mode 100644 index 0000000..c1692d5 --- /dev/null +++ b/server/application/admin/controller/service/Addon.php @@ -0,0 +1,51 @@ +model = new \app\admin\model\service\Addon; + $this->view->assign("statusList", $this->model->getStatusList()); + + // 获取分类列表 + $cats = Db::name('service_cat')->where('status', 'normal')->column('id,name'); + $this->view->assign("catList", [0 => '通用全部类目'] + $cats); + } + + public function index() + { + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->with(['cat']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } +} diff --git a/server/application/admin/model/Appeal.php b/server/application/admin/model/Appeal.php index 3994738..d333244 100644 --- a/server/application/admin/model/Appeal.php +++ b/server/application/admin/model/Appeal.php @@ -60,4 +60,14 @@ class Appeal extends Model + + public function order() + { + return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + public function master() + { + return $this->belongsTo('Master', 'master_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Invoice.php b/server/application/admin/model/Invoice.php index 072e4fc..eb78ef5 100644 --- a/server/application/admin/model/Invoice.php +++ b/server/application/admin/model/Invoice.php @@ -60,4 +60,14 @@ class Invoice extends Model + + public function user() + { + return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + public function merchant() + { + return $this->belongsTo('Merchant', 'merchant_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Master.php b/server/application/admin/model/Master.php index 41cdf5d..68ad37c 100644 --- a/server/application/admin/model/Master.php +++ b/server/application/admin/model/Master.php @@ -60,4 +60,9 @@ class Master extends Model + + public function user() + { + return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Merchant.php b/server/application/admin/model/Merchant.php index 2c24780..7655c3f 100644 --- a/server/application/admin/model/Merchant.php +++ b/server/application/admin/model/Merchant.php @@ -60,4 +60,9 @@ class Merchant extends Model + + public function user() + { + return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Order.php b/server/application/admin/model/Order.php index 6eefe4e..4f56137 100644 --- a/server/application/admin/model/Order.php +++ b/server/application/admin/model/Order.php @@ -223,4 +223,14 @@ class Order extends Model } + + public function user() + { + return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + public function master() + { + return $this->belongsTo('Master', 'master_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Review.php b/server/application/admin/model/Review.php index 87da356..d4d5aa5 100644 --- a/server/application/admin/model/Review.php +++ b/server/application/admin/model/Review.php @@ -46,4 +46,19 @@ class Review extends Model + + public function user() + { + return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + public function master() + { + return $this->belongsTo('Master', 'master_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + public function order() + { + return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Service.php b/server/application/admin/model/Service.php index 6e6424b..968c7b1 100644 --- a/server/application/admin/model/Service.php +++ b/server/application/admin/model/Service.php @@ -70,4 +70,9 @@ class Service extends Model + + public function cat() + { + return $this->belongsTo('app\\admin\\model\\service\\Cat', 'cat_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Settle.php b/server/application/admin/model/Settle.php index 1779d8e..605bbdc 100644 --- a/server/application/admin/model/Settle.php +++ b/server/application/admin/model/Settle.php @@ -57,4 +57,14 @@ class Settle extends Model } + + public function order() + { + return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + public function master() + { + return $this->belongsTo('Master', 'master_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/Withdraw.php b/server/application/admin/model/Withdraw.php index 094781b..72866bb 100644 --- a/server/application/admin/model/Withdraw.php +++ b/server/application/admin/model/Withdraw.php @@ -60,4 +60,9 @@ class Withdraw extends Model + + public function master() + { + return $this->belongsTo('Master', 'master_id', 'id', [], 'LEFT')->setEagerlyType(0); + } } diff --git a/server/application/admin/model/service/Addon.php b/server/application/admin/model/service/Addon.php new file mode 100644 index 0000000..22063f6 --- /dev/null +++ b/server/application/admin/model/service/Addon.php @@ -0,0 +1,41 @@ + __('Normal'), 'hidden' => __('Hidden')]; + } + + public function getStatusTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); + $list = $this->getStatusList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + public function cat() + { + return $this->belongsTo('app\admin\model\service\Cat', 'cat_id', 'id', [], 'LEFT')->setEagerlyType(0); + } +} diff --git a/server/application/admin/model/service/Cat.php b/server/application/admin/model/service/Cat.php new file mode 100644 index 0000000..8d04353 --- /dev/null +++ b/server/application/admin/model/service/Cat.php @@ -0,0 +1,36 @@ + __('Normal'), 'hidden' => __('Hidden')]; + } + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } +} diff --git a/server/application/admin/view/common/script.html b/server/application/admin/view/common/script.html index 04d1e80..e239639 100755 --- a/server/application/admin/view/common/script.html +++ b/server/application/admin/view/common/script.html @@ -1 +1 @@ - + diff --git a/server/application/admin/view/service/addon/add.html b/server/application/admin/view/service/addon/add.html new file mode 100644 index 0000000..266b2dc --- /dev/null +++ b/server/application/admin/view/service/addon/add.html @@ -0,0 +1,49 @@ +
+ +
+ +
+ {:build_select('row[cat_id]', $catList, 0, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])} +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ {foreach name="statusList" item="vo"} + + {/foreach} +
+
+
+ +
diff --git a/server/application/admin/view/service/addon/edit.html b/server/application/admin/view/service/addon/edit.html new file mode 100644 index 0000000..859c731 --- /dev/null +++ b/server/application/admin/view/service/addon/edit.html @@ -0,0 +1,49 @@ +
+ +
+ +
+ {:build_select('row[cat_id]', $catList, $row.cat_id, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])} +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ {foreach name="statusList" item="vo"} + + {/foreach} +
+
+
+ +
diff --git a/server/application/admin/view/service/addon/index.html b/server/application/admin/view/service/addon/index.html new file mode 100644 index 0000000..6745585 --- /dev/null +++ b/server/application/admin/view/service/addon/index.html @@ -0,0 +1,24 @@ +
+ {:build_heading()} + +
+ +
+
diff --git a/server/application/admin/view/service/cat/add.html b/server/application/admin/view/service/cat/add.html index 9c28555..d287d01 100644 --- a/server/application/admin/view/service/cat/add.html +++ b/server/application/admin/view/service/cat/add.html @@ -13,9 +13,17 @@
- +
- +
+ +
+ + +
+ +
+
@@ -27,13 +35,11 @@
-
{foreach name="statusList" item="vo"} {/foreach}
-
- +
- +
+ +
+ + +
+ +
+
@@ -27,13 +35,11 @@
-
{foreach name="statusList" item="vo"} {/foreach}
-