diff --git a/app/admin/controller/Diamond.php b/app/admin/controller/Diamond.php new file mode 100644 index 0000000..07d6bd2 --- /dev/null +++ b/app/admin/controller/Diamond.php @@ -0,0 +1,189 @@ +isAjax()) { + $param = input('param.'); + $limit = $param['limit'] ?? 15; + $page = $param['page'] ?? 1; + $name = $param['name'] ?? ''; + $status = $param['status'] ?? ''; + + $where = []; + if ($name) { + $where[] = ['name', 'like', "%{$name}%"]; + } + if ($status !== '') { + $where[] = ['status', '=', $status]; + } + + $data = DiamondProducts::getList($where, $page, $limit); + + return json([ + 'code' => 0, + 'msg' => '', + 'count' => $data['count'], + 'data' => $data['list'] + ]); + } + // View::fetch("Goods/goods"); + return View::fetch('Diamond/index'); + } + + /** + * 添加钻石商品 + */ + public function add() + { + if (request()->isPost()) { + $param = input('post.'); + + // 验证数据 + $validate = [ + 'name' => 'require', + 'products_id' => 'require', + 'products_type' => 'require', + 'base_reward' => 'require', + 'price' => 'require|float', + 'is_first' => 'require|in:0,1', + 'sort_order' => 'require|number', + 'status' => 'require|in:0,1' + ]; + $message = [ + 'name.require' => '商品名称不能为空', + 'products_id.require' => '商品ID不能为空', + 'products_type.require' => '商品类型不能为空', + 'base_reward.require' => '基础钻石数量不能为空', + 'price.require' => '价格不能为空', + 'price.float' => '价格必须为数字', + 'is_first.require' => '请选择是否为首充', + 'is_first.in' => '是否为首充值无效', + 'sort_order.require' => '排序值不能为空', + 'sort_order.number' => '排序值必须为数字', + 'status.require' => '请选择状态', + 'status.in' => '状态值无效' + ]; + + $result = $this->validate($param, $validate, $message); + if ($result !== true) { + return $this->err($result); + } + + // 处理图片路径 + $fields = ['first_charge_image', 'first_select_charge_image', 'normal_image', 'normal_select_image']; + foreach ($fields as $field) { + if (isset($param[$field]) && $param[$field]) { + $param[$field] = str_replace('/www/wwwroot/test.zfunbox.cn/public', '', $param[$field]); + } + } + + // 保存数据 + $id = DiamondProducts::add($param); + if ($id) { + return $this->succ('添加成功'); + } else { + return $this->err('添加失败'); + } + } + + return View::fetch('Diamond/add'); + } + + /** + * 编辑钻石商品 + */ + public function edit() + { + $id = input('id/d', 0); + if (!$id) { + return $this->err('参数错误'); + } + + $info = DiamondProducts::getInfo($id); + if (!$info) { + return $this->err('数据不存在'); + } + + if (request()->isPost()) { + $param = input('post.'); + + // 验证数据 + $validate = [ + 'name' => 'require', + 'products_id' => 'require', + 'products_type' => 'require', + 'base_reward' => 'require', + 'price' => 'require|float', + 'is_first' => 'require|in:0,1', + 'sort_order' => 'require|number', + 'status' => 'require|in:0,1' + ]; + $message = [ + 'name.require' => '商品名称不能为空', + 'products_id.require' => '商品ID不能为空', + 'products_type.require' => '商品类型不能为空', + 'base_reward.require' => '基础钻石数量不能为空', + 'price.require' => '价格不能为空', + 'price.float' => '价格必须为数字', + 'is_first.require' => '请选择是否为首充', + 'is_first.in' => '是否为首充值无效', + 'sort_order.require' => '排序值不能为空', + 'sort_order.number' => '排序值必须为数字', + 'status.require' => '请选择状态', + 'status.in' => '状态值无效' + ]; + + $result = $this->validate($param, $validate, $message); + if ($result !== true) { + return $this->err($result); + } + + // 处理图片路径 + $fields = ['first_charge_image', 'first_select_charge_image', 'normal_image', 'normal_select_image']; + foreach ($fields as $field) { + if (isset($param[$field]) && $param[$field]) { + $param[$field] = str_replace('/www/wwwroot/test.zfunbox.cn/public', '', $param[$field]); + } + } + + // 更新数据 + $result = DiamondProducts::edit($id, $param); + if ($result) { + return $this->succ('修改成功'); + } else { + return $this->err('修改失败'); + } + } + + View::assign('info', $info); + return View::fetch('Diamond/edit'); + } + + /** + * 删除钻石商品 + */ + public function del() + { + $id = input('id/d', 0); + if (!$id) { + return $this->err('参数错误'); + } + + $result = DiamondProducts::del($id); + if ($result) { + return $this->succ('删除成功'); + } else { + return $this->err('删除失败'); + } + } +} \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 38d4728..eea860f 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -465,4 +465,12 @@ Route::get('dynamicJs.js', 'Config/dynamicJs')->ext('js'); #============================ Route::rule('markdown/index', 'Markdown/index', 'GET|POST'); Route::rule('markdown/order_info', 'Markdown/order_info', 'GET|POST'); + +#============================ +#Diamond.php钻石商品配置 +#============================ +Route::rule('diamond', 'Diamond/index', 'GET|POST'); +Route::rule('diamond_add', 'Diamond/add', 'GET|POST'); +Route::rule('diamond_edit', 'Diamond/edit', 'GET|POST'); +Route::rule('diamond_del', 'Diamond/del', 'GET|POST'); \ No newline at end of file diff --git a/app/admin/view/Diamond/index.html b/app/admin/view/Diamond/index.html new file mode 100644 index 0000000..97d8b95 --- /dev/null +++ b/app/admin/view/Diamond/index.html @@ -0,0 +1,394 @@ +{include file="Public:header3"/} + +
+