diff --git a/app/admin/controller/goods/Subsidy.php b/app/admin/controller/goods/Subsidy.php new file mode 100644 index 00000000..f1f5928b --- /dev/null +++ b/app/admin/controller/goods/Subsidy.php @@ -0,0 +1,62 @@ +request->isAjax()) { + $get = $this->request->get(); + return JsonServer::success('获取成功', SubsidyLogic::lists($get)); + } + return view(); + } + + public function add() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + (new SubsidyValidate())->goCheck(); + if (SubsidyLogic::add($post)) { + return JsonServer::success('操作成功'); + } + return JsonServer::error(SubsidyLogic::getError() ?: '操作失败'); + } + return view(); + } + + public function edit() + { + $id = $this->request->get('id'); + if ($this->request->isAjax()) { + $post = $this->request->post(); + (new SubsidyValidate())->goCheck(); + if (SubsidyLogic::edit($post)) { + return JsonServer::success('操作成功'); + } + return JsonServer::error(SubsidyLogic::getError() ?: '操作失败'); + } + + return view('', [ + 'detail' => GoodsSubsidy::find($id), + ]); + } + + public function del() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + if (SubsidyLogic::del($id)) { + return JsonServer::success('操作成功'); + } + return JsonServer::error(SubsidyLogic::getError() ?: '操作失败'); + } + } +} \ No newline at end of file diff --git a/app/admin/logic/goods/SubsidyLogic.php b/app/admin/logic/goods/SubsidyLogic.php new file mode 100755 index 00000000..0a88a27d --- /dev/null +++ b/app/admin/logic/goods/SubsidyLogic.php @@ -0,0 +1,91 @@ +withAttr('discount', function ($value) { + $arr = explode('.', $value); + if ($arr[1] > 0) { + return $value . '%'; + } + + return intval($value) . '%'; + }) + ->withAttr('subsidy', function ($value) { + $arr = explode('.', $value); + if ($arr[1] > 0) { + return $value . '%'; + } + + return intval($value) . '%'; + }) + ->paginate([ + 'list_rows'=> $get['limit'], + 'page'=> $get['page'], + ]); + + return ['count' => $lists->total(), 'lists' => $lists->getCollection()]; + } + + + // 添加返补比例设置 + public static function add($post) + { + try { + Db::startTrans(); + GoodsSubsidy::create([ + 'discount' => str_replace('%', '', $post['discount']), + 'subsidy' => str_replace('%', '', $post['subsidy']), + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + + /** + * Notes: 编辑 + * @param $post + * @return bool + *@author 段誉(2021/4/15 10:54) + */ + public static function edit($post) + { + try { + Db::startTrans(); + GoodsSubsidy::update([ + 'discount' => str_replace('%', '', $post['discount']), + 'subsidy' => str_replace('%', '', $post['subsidy']), + ], ['id' => $post['id']]); + Db::commit(); + return true; + } catch (\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + // 删除 + public static function del($id) + { + return GoodsSubsidy::update(['is_delete' => 1, 'delete_time' => time()], ['id' => $id]); + } +} \ No newline at end of file diff --git a/app/admin/validate/goods/SubsidyValidate.php b/app/admin/validate/goods/SubsidyValidate.php new file mode 100755 index 00000000..bf4641d9 --- /dev/null +++ b/app/admin/validate/goods/SubsidyValidate.php @@ -0,0 +1,19 @@ + 'require', + 'subsidy' => 'require', + ]; + + protected $message = [ + 'discount.require' => '商品让利比例参数不能为空', + 'subsidy.require' => '商品全返比例参数不能为空', + ]; +} \ No newline at end of file diff --git a/app/admin/view/goods/subsidy/add.html b/app/admin/view/goods/subsidy/add.html new file mode 100755 index 00000000..b6781de0 --- /dev/null +++ b/app/admin/view/goods/subsidy/add.html @@ -0,0 +1,50 @@ +{layout name="layout2" /} + +
+
+ +
+
+ +

%

+
+
+
+ +
+ +
+
+ +

%

+
+
+
+ +
+ +
+
+ + + diff --git a/app/admin/view/goods/subsidy/edit.html b/app/admin/view/goods/subsidy/edit.html new file mode 100755 index 00000000..7a1b2f1f --- /dev/null +++ b/app/admin/view/goods/subsidy/edit.html @@ -0,0 +1,52 @@ +{layout name="layout2" /} + +
+ + +
+ +
+
+ +

%

+
+
+
+ +
+ +
+
+ +

%

+
+
+
+ +
+ +
+
+ + + diff --git a/app/admin/view/goods/subsidy/lists.html b/app/admin/view/goods/subsidy/lists.html new file mode 100755 index 00000000..8a022be8 --- /dev/null +++ b/app/admin/view/goods/subsidy/lists.html @@ -0,0 +1,184 @@ +{layout name="layout1" /} + + +
+
+
+ +
+ +
+ + +
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/app/common/model/goods/GoodsSubsidy.php b/app/common/model/goods/GoodsSubsidy.php new file mode 100644 index 00000000..390bb0c5 --- /dev/null +++ b/app/common/model/goods/GoodsSubsidy.php @@ -0,0 +1,10 @@ +