From 29060c709a786e8e9994a2345692c0b76801ba03 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 16 Mar 2024 15:31:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A1=A5=E8=B4=B4=E5=8F=91?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/Enum.php | 13 ++++++++ app/common/dao/store/StoreActivityUserDao.php | 30 ++++++++++--------- .../consumption/StoreConsumptionUserDao.php | 14 ++++++--- .../store/order/StoreOrderRepository.php | 3 +- crmeb/listens/SendSubsidyCouponListen.php | 8 ++++- 5 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 app/common/Enum.php diff --git a/app/common/Enum.php b/app/common/Enum.php new file mode 100644 index 00000000..2b4496f2 --- /dev/null +++ b/app/common/Enum.php @@ -0,0 +1,13 @@ +whereIn('type', [StoreConsumptionUser::TYPE_ONE, StoreConsumptionUser::TYPE_TWO]) - ->where('status', StoreConsumptionUser::STATUS_UNUSED) - ->field('SUM(balance) as total_amount,type') - ->group('type') + ->whereIn('status', [StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::STATUS_REPEAL]) + ->field('balance,type') ->select()->toArray(); - $totalAmount = reset_index($totalAmount, 'type'); $result = [ - [ + '1' => [ 'type' => 1, - 'total_amount' => 0.00 + 'total_amount' => 0.00, + 'type_cn' => StoreConsumptionUser::TYPE_MAP[1], ], - [ + '2' => [ 'type' => 2, - 'total_amount' => 0.00 + 'total_amount' => 0.00, + 'type_cn' => StoreConsumptionUser::TYPE_MAP[2], ] ]; - foreach ($result as &$item) { - if (isset($totalAmount[$item['type']])) { - $item['total_amount'] = $totalAmount[$item['type']]['total_amount']; + foreach ($totalAmount as $item) { + if (isset($result[$item['type']])) { + $result[$item['type']]['total_amount']= bcadd($result[$item['type']]['total_amount'], $item['balance'], 2); } - $item['type_cn'] = StoreConsumptionUser::TYPE_MAP[$item['type']]; } - return $result; + return array_values($result); } } diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index 64e0754d..9b30e2eb 100755 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -52,6 +52,7 @@ class StoreConsumptionUserDao extends BaseDao public $startTime; public $endTime; public $billExtra; + public $onlyBill = false; // 是否只写入用户账单 protected function getModel(): string { @@ -241,10 +242,12 @@ class StoreConsumptionUserDao extends BaseDao $model = StoreConsumptionUser::where('uid', $userId)->where('type', StoreConsumptionUser::TYPE_TWO)->find(); $couponPrice = bcmul($amount, $rate, 2); if (!empty($model) && $model['type'] == $type) { - $model->coupon_price = bcadd($model->coupon_price, $couponPrice, 2); - $model->balance = bcadd($model->balance, $couponPrice, 2); - if ($model->status != StoreConsumptionUser::STATUS_UNUSED) { - $model->status = StoreConsumptionUser::STATUS_UNUSED; + if (!$this->onlyBill) { + $model->coupon_price = bcadd($model->coupon_price, $couponPrice, 2); + $model->balance = bcadd($model->balance, $couponPrice, 2); + if ($model->status != StoreConsumptionUser::STATUS_UNUSED) { + $model->status = StoreConsumptionUser::STATUS_UNUSED; + } } } else { $model = new StoreConsumptionUser(); @@ -260,6 +263,9 @@ class StoreConsumptionUserDao extends BaseDao $model->end_time = $this->endTime ?: '2026-01-15 23:59:59'; $model->type = $type; $model->status = $status; + if ($this->onlyBill === true) { + $model->status = StoreConsumptionUser::STATUS_REPEAL; + } } if (!$model->save()) { throw new \Exception('发放失败'); diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index e234f95c..ce057a19 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -844,10 +844,11 @@ class StoreOrderRepository extends BaseRepository $money = bcsub($money, $refundPrice, 2); //订单确认收货,增加商户销售金额 Merchant::where('mer_id', $order->mer_id)->update(['sale_amount' => Db::raw('sale_amount+' . $money)]); + $field = $order->merchant['type_id'] == 22 ? 'official_purchase_amount' : 'purchase_amount'; //订单确认收货,增加商户采购金额 $merId = Merchant::where('uid', $order->uid)->value('mer_id'); if (!empty($merId)) { - Merchant::where('mer_id', $merId)->update(['purchase_amount' => Db::raw('purchase_amount+' . $money)]); + Merchant::where('mer_id', $merId)->update([$field => Db::raw("{$field}+" . $money)]); } } }); diff --git a/crmeb/listens/SendSubsidyCouponListen.php b/crmeb/listens/SendSubsidyCouponListen.php index fedc4bda..825d8328 100644 --- a/crmeb/listens/SendSubsidyCouponListen.php +++ b/crmeb/listens/SendSubsidyCouponListen.php @@ -3,6 +3,7 @@ namespace crmeb\listens; use app\common\dao\store\consumption\StoreConsumptionUserDao; +use app\common\Enum; use app\common\model\store\consumption\StoreConsumption; use app\common\model\store\consumption\StoreConsumptionUser; use app\common\model\system\merchant\Merchant; @@ -23,10 +24,12 @@ class SendSubsidyCouponListen extends TimerService implements ListenerInterface $count = 0; if ($consumption) { foreach ($consumption['config'] as $item) { - $purchaseAmount = $item['amount'] * 0.5; + $purchaseAmount = $item['amount'] * 0.2; //普通店铺采购金额 + $officialPurchaseAmount = $item['amount'] * 0.3; //官方店铺采购金额 $merchants = Merchant::whereIn('type_id', $item['type_id']) ->where('sale_amount', '>=', $item['amount']) ->where('purchase_amount', '>=', $purchaseAmount) + ->where('official_purchase_amount', '>=', $officialPurchaseAmount) ->select(); foreach ($merchants as $merchant) { //商户已获得的补贴金额 @@ -43,7 +46,10 @@ class SendSubsidyCouponListen extends TimerService implements ListenerInterface 'coupon_id' => $consumption['coupon_id'], 'sale_amount' => $item['amount'], 'purchase_amount' => $purchaseAmount, + 'official_purchase_amount' => $officialPurchaseAmount, + 'status' => Enum::CONSUMPTION_STATUS_REPEAL, ]; + $consumptionRepo->onlyBill = true; $consumptionRepo->send($consumption, 1, $merchant->uid, 0, $amount, StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO); $count++; }