添加:消费返利 - 商品相关设置
This commit is contained in:
parent
c62df020e7
commit
36bb257eff
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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."<br />";
|
||||
// for($i=1;$i <= 20;$i++){
|
||||
// $d = strtotime($start );
|
||||
// echo "第{$i}个月返利时间:".date("Y-m-d H:i:s",getNextMonthDays($d, $i))."<br />";
|
||||
// }
|
||||
// die;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return view('Yunshop\Rebate::index.set',[
|
||||
'set' => $set,
|
||||
])->render();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Yunshop\Rebate\admin\widget;
|
||||
|
||||
use app\backend\modules\goods\widget\BaseGoodsWidget;
|
||||
use Yunshop\Rebate\models\GoodsRebate;
|
||||
|
||||
class RebateWidget extends BaseGoodsWidget{
|
||||
public $group = 'profit';
|
||||
public $widget_key = 'rebate';
|
||||
public $code = 'rebate';
|
||||
|
||||
|
||||
public function pluginFileName(){
|
||||
return 'goods';
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
return GoodsRebate::uniacid()
|
||||
->where('goods_id', $this->goods->id)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function pagePath(){
|
||||
return plugin_assets('rebate','views/widget');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
namespace Yunshop\Rebate\models;
|
||||
|
||||
use app\common\models\BaseModel;
|
||||
use app\frontend\models\Goods;
|
||||
|
||||
class GoodsRebate extends BaseModel{
|
||||
|
||||
public $table = 'yz_goods_rebate';
|
||||
public $timestamps = false;
|
||||
|
||||
public function getQuarterListAttribute($value){
|
||||
|
||||
return is_array(json_decode($value, true)) ? json_decode($value, true) : [];
|
||||
}
|
||||
|
||||
|
||||
public static function relationSave($goodsId, $data, $operate){
|
||||
if (!$goodsId) return false;
|
||||
if (!$data) return false;
|
||||
|
||||
$info = self::getModel($goodsId, $operate);
|
||||
// 判断deleted
|
||||
if ($operate == 'deleted') return $info->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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -212,11 +212,6 @@
|
|||
created() {},
|
||||
mounted() {},
|
||||
methods: {
|
||||
// 修改 每月返利金额
|
||||
|
||||
|
||||
|
||||
|
||||
// 提交
|
||||
onSubmit() {
|
||||
let _this = this;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,218 @@
|
|||
define({
|
||||
name:"rebate",
|
||||
template:`
|
||||
<div class="rebate">
|
||||
<el-form>
|
||||
<div style="margin:0 auto;width:80%;">
|
||||
<el-form-item label="是否参与消费返利" label-width="155px">
|
||||
<el-radio v-model="json.is_open" :label="0">关闭</el-radio>
|
||||
<el-radio v-model="json.is_open" :label="1">开启</el-radio>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<template v-if="json.is_open == 1">
|
||||
<div style="margin:0 auto;width:80%;">
|
||||
<el-form-item label="是否独立设置" label-width="155px">
|
||||
<el-radio v-model="json.is_alone" :label="0">默认设置</el-radio>
|
||||
<el-radio v-model="json.is_alone" :label="1">独立设置</el-radio>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="json.is_alone == 1" label="返利季度">
|
||||
<el-input placeholder="请输入返利总季度" v-model.number="json.total_quarter" min="0" type="number" class="shortInput">
|
||||
<template slot="prepend">总共返利</template>
|
||||
<template slot="append">个季度</template>
|
||||
</el-input>
|
||||
<!--循环每个季度-->
|
||||
<div v-for="(quarter,index) in json.quarter_list" :key="index" class="quarter-block">
|
||||
<div class="title">第 {{ index }} 季度</div>
|
||||
<el-input v-model.number="quarter.total_month" min="0" type="number" class="shortInput">
|
||||
<template slot="prepend">本季度总</template>
|
||||
<template slot="append">个月</template>
|
||||
</el-input>
|
||||
<div class="tips">本季度总的月数,必须大于等于1</div>
|
||||
<div class="isRepurchase">
|
||||
是否需要复购:
|
||||
<el-radio-group v-model.number="quarter.is_repurchase">
|
||||
<el-radio :label="0">不需要</el-radio>
|
||||
<el-radio :label="1">需要</el-radio>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<template v-if="quarter.is_repurchase == 1">
|
||||
<el-input v-model.number="quarter.repurchase_money" type="number" class="shortInput">
|
||||
<template slot="prepend">复购需要支付</template>
|
||||
<template slot="append">元</template>
|
||||
</el-input>
|
||||
</template>
|
||||
<div class="tips">不需要复购:在下一个季度开始返利时可以直接领取;需要复购:在本季度最后一笔返利领取后指定时间内需要重新购买指定产品,否则后续不在返利,后续未领取返利全部失效!</div>
|
||||
<div class="monty-list" v-if="Object.values(quarter.month_list).length > 0">
|
||||
<el-input
|
||||
v-for="(month,monthIndex) in quarter.month_list"
|
||||
:value="month"
|
||||
:key="monthIndex"
|
||||
placeholder="返利金额"
|
||||
type="number"
|
||||
step="0.01"
|
||||
class="monthInput"
|
||||
v-model="quarter.month_list[monthIndex]"
|
||||
>
|
||||
<template slot="prepend">第 <span class="prepend-month">{{ monthIndex }}</span> 个月返利</template>
|
||||
<template slot="append">元</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</template>
|
||||
</el-form>
|
||||
</div>
|
||||
`,
|
||||
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;
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Reference in New Issue