From 36bb257eff622165859b14ff39fefefa6e93963e Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 13 Mar 2024 14:16:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=B6=88=E8=B4=B9?= =?UTF-8?q?=E8=BF=94=E5=88=A9=20-=20=E5=95=86=E5=93=81=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/rebate/src/PluginApplication.php | 19 ++ plugins/rebate/src/admin/IndexController.php | 24 +- .../rebate/src/admin/widget/RebateWidget.php | 27 +++ plugins/rebate/src/models/GoodsRebate.php | 62 +++++ plugins/rebate/views/index/set.blade.php | 5 - plugins/rebate/views/widget/profit/rebate.js | 218 ++++++++++++++++++ 6 files changed, 333 insertions(+), 22 deletions(-) create mode 100644 plugins/rebate/src/admin/widget/RebateWidget.php create mode 100644 plugins/rebate/src/models/GoodsRebate.php create mode 100644 plugins/rebate/views/widget/profit/rebate.js diff --git a/plugins/rebate/src/PluginApplication.php b/plugins/rebate/src/PluginApplication.php index dd2a74db..887be665 100644 --- a/plugins/rebate/src/PluginApplication.php +++ b/plugins/rebate/src/PluginApplication.php @@ -68,6 +68,25 @@ class PluginApplication extends \app\common\services\PluginApplication{ ]); } + public function getWidgetItems() + { + return [ + 'vue-goods.rebate' => [ + 'title' => '消费返利', + 'class' => \Yunshop\Rebate\admin\widget\RebateWidget::class, + ], + ]; + } + + protected function setConfig(){ + \app\common\modules\shop\ShopConfig::current()->set( + 'observer.goods.rebate', [ + 'class' => 'Yunshop\Rebate\models\GoodsRebate', + 'function_save' => 'relationSave' + ] + ); + } + public function boot(){ $events = app('events'); diff --git a/plugins/rebate/src/admin/IndexController.php b/plugins/rebate/src/admin/IndexController.php index ddfbf547..8119dd85 100644 --- a/plugins/rebate/src/admin/IndexController.php +++ b/plugins/rebate/src/admin/IndexController.php @@ -25,8 +25,13 @@ class IndexController extends BaseController{ return view('Yunshop\Rebate::index.index',$data)->render(); } - - // 基本设置 + /** + * Common: 基本设置 + * Author: wu-hui + * Time: 2024/03/13 10:47 + * @return array|\Illuminate\Http\JsonResponse|string + * @throws \Throwable + */ public function set(){ // 获取设置信息 判断是否为设置 $setInfo = request()->input('rebate'); @@ -37,21 +42,6 @@ class IndexController extends BaseController{ }else{ // 获取信息 $set = Setting::get('plugin.rebate'); - - // $start = "2024-3-31 12:12:59"; - // echo "购买时间:".$start."
"; - // for($i=1;$i <= 20;$i++){ - // $d = strtotime($start ); - // echo "第{$i}个月返利时间:".date("Y-m-d H:i:s",getNextMonthDays($d, $i))."
"; - // } - // die; - - - - - - - return view('Yunshop\Rebate::index.set',[ 'set' => $set, ])->render(); diff --git a/plugins/rebate/src/admin/widget/RebateWidget.php b/plugins/rebate/src/admin/widget/RebateWidget.php new file mode 100644 index 00000000..4c622a0e --- /dev/null +++ b/plugins/rebate/src/admin/widget/RebateWidget.php @@ -0,0 +1,27 @@ +where('goods_id', $this->goods->id) + ->first(); + } + + public function pagePath(){ + return plugin_assets('rebate','views/widget'); + } +} \ No newline at end of file diff --git a/plugins/rebate/src/models/GoodsRebate.php b/plugins/rebate/src/models/GoodsRebate.php new file mode 100644 index 00000000..825b235f --- /dev/null +++ b/plugins/rebate/src/models/GoodsRebate.php @@ -0,0 +1,62 @@ +delete(); + // 公共 + $info->uniacid = \YunShop::app()->uniacid; + $info->goods_id = $goodsId;// 商品ID + $info->is_open = $data['is_open'] ?? 0;// 当前商品是否参与消费返利:0=未开启,1=开启 + $info->is_alone = $data['is_alone'] ?? 0;// 是否独立设置:0=不是,1=是 + $info->total_quarter = $data['total_quarter'] ?? 0;// 总多少季度 + $info->quarter_list = json_encode($data['quarter_list'] ?? []);// 每季度配置信息 + + return $info->save(); + } + + public static function getModel($goodsId, $operate){ + $model = false; + // 商品设置 + if ($operate != 'created') $model = static::where(['goods_id' => $goodsId])->first(); + + !$model && $model = new static; + + return $model; + } + + public function getGoodsSet($goodsId){ + self::where('goods_id', $goodsId); + } + + //关联商品信息 + public function belongsToGoods(){ + return $this->belongsTo(Goods::class, 'goods_id', 'id'); + } + + + + + + + + +} diff --git a/plugins/rebate/views/index/set.blade.php b/plugins/rebate/views/index/set.blade.php index 1bd8ffd1..3a4c94d7 100644 --- a/plugins/rebate/views/index/set.blade.php +++ b/plugins/rebate/views/index/set.blade.php @@ -212,11 +212,6 @@ created() {}, mounted() {}, methods: { - // 修改 每月返利金额 - - - - // 提交 onSubmit() { let _this = this; diff --git a/plugins/rebate/views/widget/profit/rebate.js b/plugins/rebate/views/widget/profit/rebate.js new file mode 100644 index 00000000..df1ee49e --- /dev/null +++ b/plugins/rebate/views/widget/profit/rebate.js @@ -0,0 +1,218 @@ +define({ + name:"rebate", + template:` +
+ +
+ + 关闭 + 开启 + +
+ +
+
+ `, + style:` + .shortInput{ + width: 500px!important; + } + .quarter-block{ + border: 1px solid #DCDFE6; + margin-top: 20px; + padding: 0 15px; + } + .quarter-block .tips{ + font-size: 12px; + color: #737373; + line-height: 20px; + width: 100%; + } + .quarter-block .title{ + height: 40px; + line-height: 40px; + font-weight: bold; + font-size: 14px; + padding-left: 10px; + position: relative; + } + .quarter-block .title:after{ + content: ""; + position: absolute; + left: 0; + top: 11px; + width: 4px; + height: 18px; + background: #29ba9c; + } + .quarter-block .isRepurchase{ + margin-top: 15px; + margin-right: 50px; + } + .quarter-block .monthInput{ + min-width: 350px; + width: calc((100% - 30px) / 4); + margin-bottom: 10px; + margin-right: 10px; + } + .quarter-block .monthInput:nth-child(4n){ + margin-right: 0!important; + } + .quarter-block .monthInput .prepend-month{ + font-weight: bold; + } + .quarter-block .monty-list{ + margin-top: 15px; + } + `, + props: { + form: { + default() { + return {} + } + } + }, + data() { + return { + json: { + is_open: 0, + is_alone: 0, + total_quarter: '', + quarter_list: {}, + } + } + }, + computed:{ + countTotalMonth(){ + let json = Object.assign({}, this.json); + let quarterList = Object.assign({}, json.quarter_list); + + return Object.values(quarterList).reduce((sum, item) => sum + item.total_month, 0); + } + }, + watch:{ + // 总季度信息变更 + 'json.total_quarter':{ + handler(val, olVal) { + let value = Number(val) >= 0 ? Number(val) : 0; + let newQuarterList = {}; + if(Number(value) > 0){ + let quarterList = Object.assign({}, this.json.quarter_list); + for(value;value > 0;value--){ + let currentQuarter = quarterList[value] || {}; + if(Object.values(currentQuarter).length <= 0){ + // 当前季度信息不存在 + newQuarterList[value] = { + total_month: 0,// 本季度总多少月 + is_repurchase: 0,// 是否需要复购 + repurchase_money: 0,// 复购支付金额 + month_list: {},// 每月返利金额 + }; + }else{ + // 当前季度信息存在 + newQuarterList[value] = currentQuarter; + } + } + } + + this.$set(this.json, 'quarter_list', newQuarterList) + this.$forceUpdate(); + }, + deep:true + }, + // 月度信息变更 + countTotalMonth:{ + handler(val, olVal) { + if(Number(val) !== Number(olVal)){ + let json = Object.assign({}, this.json); + let quarterList = Object.assign({}, json.quarter_list); + // 循环处理每个季度 + for(const index in quarterList){ + let currentMonthInfo = quarterList[index] || {}; + let totalMonth = Number(currentMonthInfo.total_month) || 0; + let monthList = currentMonthInfo.month_list || {}; + let newMonthList = {}; + if(totalMonth > 0){ + for(totalMonth;totalMonth > 0;totalMonth--){ + let currentMonth = monthList[totalMonth] || ''; + newMonthList[totalMonth] = currentMonth || ''; + } + } + + quarterList[index].month_list = newMonthList; + } + + this.$set(this.json, 'quarter_list', quarterList) + this.$forceUpdate(); + } + }, + deep:true + }, + }, + mounted() { + if (this.form) { + let rebate = this.form || {}; + this.json.is_alone = rebate.is_alone ? rebate.is_alone : 0; + this.json.is_open = rebate.is_open ? rebate.is_open : 0; + this.json.total_quarter = rebate.total_quarter ? rebate.total_quarter : ''; + this.json.quarter_list = rebate.quarter_list ? rebate.quarter_list : {}; + } + }, + methods:{ + validate(){ + + return this.json; + } + } +}) \ No newline at end of file