diff --git a/app/common/services/income/IncomeService.php b/app/common/services/income/IncomeService.php index 66031925..13bbefc6 100644 --- a/app/common/services/income/IncomeService.php +++ b/app/common/services/income/IncomeService.php @@ -209,6 +209,8 @@ class IncomeService const STORE_MANAGER = 200;// 经销商店长-店补 const CULTURAL_SPACE_CONTRIBUTION_BONUS = 201;// 文创空间 - 贡献分享分红 const CULTURAL_SPACE_AREA_BONUS = 202;// 文创空间 - 市场津贴 + const REBATE_MONEY = 203;// 消费返利 + /** * @param $data 会员id:member_id,分红类型:dividend_code,分红表id:dividend_table_id,金额:amount,订单号:order_sn,详情:detail @@ -681,6 +683,7 @@ class IncomeService self::STORE_MANAGER => '店补', self::CULTURAL_SPACE_CONTRIBUTION_BONUS => '贡献分享分红', self::CULTURAL_SPACE_AREA_BONUS => '市场津贴', + self::REBATE_MONEY => '消费返利' ]; if (empty($income_config_desc[$code])) { if ($func = app('ShopAsset')->getData('income')[$code]) { @@ -883,6 +886,7 @@ class IncomeService self::STORE_MANAGER => 'Yunshop\TeamDividend\Common\models\StoreManagerRecordModel', self::CULTURAL_SPACE_CONTRIBUTION_BONUS => 'Yunshop\CulturalSpace\models\ContributionBonusLog', self::CULTURAL_SPACE_AREA_BONUS => 'Yunshop\CulturalSpace\models\CulturalSpaceAreaBonus', + self::REBATE_MONEY => 'Yunshop\Rebate\models\Rebate' ]; if (empty($income_config_class[$code])) { if ($func = app('ShopAsset')->getData('income')[$code]) { diff --git a/plugins/cultural-space/src/models/CulturalSpace.php b/plugins/cultural-space/src/models/CulturalSpace.php index e414ca0a..b0bbf60a 100644 --- a/plugins/cultural-space/src/models/CulturalSpace.php +++ b/plugins/cultural-space/src/models/CulturalSpace.php @@ -74,7 +74,7 @@ class CulturalSpace extends BaseModel */ public function buyGoodsGiveContribution($uid, $orderId) { - \Log::debug('文创空间 - 购买商品奖励贡献值', ['uid' => $uid, 'order_id' => $orderId]); + // \Log::debug('文创空间 - 购买商品奖励贡献值', ['uid' => $uid, 'order_id' => $orderId]); DB::beginTransaction(); try { $set = Setting::get('plugin.cultural_space_set'); @@ -138,7 +138,7 @@ class CulturalSpace extends BaseModel DB::commit(); } catch (\Exception $e) { - \Log::debug('文创空间 - 购买商品奖励贡献值 - 错误抛出', $e->getMessage()); + // \Log::debug('文创空间 - 购买商品奖励贡献值 - 错误抛出', $e->getMessage()); DB::rollBack(); } } @@ -236,7 +236,7 @@ class CulturalSpace extends BaseModel } } catch (\Exception $e) { - \Log::debug('文创空间 - 基金池操作 - 错误:'.$e->getMessage()); + // \Log::debug('文创空间 - 基金池操作 - 错误:'.$e->getMessage()); DB::rollBack(); } } diff --git a/plugins/rebate/src/PluginApplication.php b/plugins/rebate/src/PluginApplication.php index 835c75b0..0d5ef8c9 100644 --- a/plugins/rebate/src/PluginApplication.php +++ b/plugins/rebate/src/PluginApplication.php @@ -2,6 +2,7 @@ namespace Yunshop\Rebate; use Yunshop\Rebate\listener\OrderPaidListener; +use Yunshop\Rebate\models\Rebate; class PluginApplication extends \app\common\services\PluginApplication{ @@ -89,6 +90,16 @@ class PluginApplication extends \app\common\services\PluginApplication{ ); } + public function getIncomeItems(){ + return [ + 'rebate' => [ + 'title' => '消费返利', + 'type' => 'rebate', + 'type_name' => '消费返利', + 'class' => 'Yunshop\Rebate\models\Rebate', + ] + ]; + } public function boot(){ $events = app('events'); @@ -98,5 +109,21 @@ class PluginApplication extends \app\common\services\PluginApplication{ } + public function cronConfig(){ + \Event::listen('cron.collectJobs', function () { + // 每天5分钟 执行一次消费返利解冻判断 + \Cron::add('rebate-settlement', '*/5 * * * *', function () { + Rebate::rebateThaw(); + return; + }); + + + + + + }); + } + + } \ No newline at end of file diff --git a/plugins/rebate/src/admin/IndexController.php b/plugins/rebate/src/admin/IndexController.php index f60725ce..8d8f1261 100644 --- a/plugins/rebate/src/admin/IndexController.php +++ b/plugins/rebate/src/admin/IndexController.php @@ -9,7 +9,13 @@ use Yunshop\CollectionRoom\models\CollectionRoomModel; use Yunshop\Rebate\models\Rebate; class IndexController extends BaseController{ - // 进入列表 + /** + * Common: 进入列表 + * Author: wu-hui + * Time: 2024/03/15 9:46 + * @return array|string + * @throws \Throwable + */ public function index(){ //参数获取 $pageSize = request()->input('page_size',10); diff --git a/plugins/rebate/src/models/Rebate.php b/plugins/rebate/src/models/Rebate.php index 5fddaf03..9501e90e 100644 --- a/plugins/rebate/src/models/Rebate.php +++ b/plugins/rebate/src/models/Rebate.php @@ -7,6 +7,7 @@ use app\common\models\Goods; use app\common\models\Member; use app\common\models\Order; use app\common\models\OrderGoods; +use app\common\services\income\IncomeService; class Rebate extends BaseModel{ @@ -110,7 +111,7 @@ class Rebate extends BaseModel{ ]; // 判断:第一季度第一个月 并且 (不是最后一个月 或者 本季度不需要复购):立即解冻 if($quarterIndex == 1 && $monthIndex == 1 && ($monthIndex != $endKey || (int)$quarterInfo['is_repurchase'] != 1)){ - $currentMonthData['reality_thaw_time'] = $currentExpectThawTime; + $currentMonthData['reality_thaw_time'] = time(); $currentMonthData['status'] = 1; } @@ -120,7 +121,10 @@ class Rebate extends BaseModel{ } // 添加数据 - if(count($insertData) > 0) self::insert($insertData); + if(count($insertData) > 0) { + self::insert($insertData); + self::rebateSettlement(); + } return true; } @@ -147,6 +151,58 @@ class Rebate extends BaseModel{ ->makeHidden(['order','after_sales','buttons']) ->toArray(); } + /** + * Common: 返利信息解冻 + * Author: wu-hui + * Time: 2024/03/15 9:58 + */ + public static function rebateThaw(){ + $time = time(); + // 预计解冻时间 低于当前时间 解冻 + self::where('expect_thaw_time','<=', $time)->update([ + 'status' => 1, + 'reality_thaw_time' => $time + ]); + // 执行 已解冻佣金结算到账 + self::rebateSettlement(); + } + /** + * Common: 已解冻返利 结算到佣金 + * Author: wu-hui + * Time: 2024/03/15 9:50 + */ + public static function rebateSettlement(){ + \Log::debug('--- 消费返利 - 结算到佣金 - 开始 ----'); + // 获取可以结算但是未结算的数据 + $list = self::select(['id','uid','money']) + ->where('status', 1) + ->get() + ->toArray(); + $incomeData = []; + foreach($list as $item){ + $incomeData[] = [ + 'uniacid' => \YunShop::app()->uniacid, + 'member_id' => $item['uid'], + 'amount' => $item['money'], + 'detail' => '', + 'dividend_table_id' => $item['id'], + 'dividend_code' => IncomeService::REBATE_MONEY, + 'order_sn' => '', + ]; + } + if(count($incomeData) > 0){ + // 添加结算信息 + IncomeService::insertIncome($incomeData); + // 修改为已结算 + $ids = array_column($list,'id'); + self::whereIn('id',$ids)->update([ + 'status' => 2 + ]); + } + } + + + diff --git a/plugins/rebate/views/index/index.blade.php b/plugins/rebate/views/index/index.blade.php index bede5a65..e26d4a5b 100644 --- a/plugins/rebate/views/index/index.blade.php +++ b/plugins/rebate/views/index/index.blade.php @@ -109,11 +109,11 @@