Merge pull request 'dev' (#152) from dev into master

Reviewed-on: #152
This commit is contained in:
mkm 2024-02-23 11:22:29 +08:00
commit d182aae5b1
277 changed files with 169 additions and 28 deletions

View File

@ -235,6 +235,7 @@ class StoreActivityUserDao extends BaseDao
$query = UserBill::field('link_id,create_time,number coupon_price,mark')
->where('uid', $userId)
->where('category', 'red_pack')
->where('status', 1)
->where('type', "red_pack_{$type}");
$count = $query->count();
$record = $query->page($page)->limit($limit)->select()->toArray();

View File

@ -49,6 +49,9 @@ class StoreConsumptionUserDao extends BaseDao
/** @var float $profitRate 商品毛利率 */
public $profitRate;
public $startTime;
public $endTime;
protected function getModel(): string
{
return StoreConsumptionUser::class;
@ -233,7 +236,7 @@ class StoreConsumptionUserDao extends BaseDao
*/
public function send($consumption, float $rate, int $userId, string $groupOrderIds, float $amount, $status = -2, $type = 1)
{
$title = $type == StoreConsumptionUser::TYPE_TWO ? '现金抵扣补贴' : '无门槛实物通用补贴';
$title = $type == StoreConsumptionUser::TYPE_TWO ? '春耕采购补贴' : '春耕采购余额';
$model = StoreConsumptionUser::where('uid', $userId)->where('type', StoreConsumptionUser::TYPE_TWO)->find();
$couponPrice = bcmul($amount, $rate, 2);
if (!empty($model) && $model['type'] == $type) {
@ -249,8 +252,8 @@ class StoreConsumptionUserDao extends BaseDao
$model->balance = $model->coupon_price;
$model->order_amount = $amount;
$model->create_time = date('Y-m-d H:i:s');
$model->start_time = date('Y-m-d H:i:s', time() + 7 * 86400);
$model->end_time = '2026-01-15 23:59:59';
$model->start_time = $this->startTime ?: date('Y-m-d H:i:s', time() + 7 * 86400);
$model->end_time = $this->endTime ?: '2026-01-15 23:59:59';
$model->type = $type;
$model->status = $status;
}
@ -268,7 +271,7 @@ class StoreConsumptionUserDao extends BaseDao
}
$userBillRepository->incBill($userId, 'red_pack', "red_pack_{$type}", [
'link_id' => $model['coupon_user_id'],
'status' => 1,
'status' => $status == -1 ?: 1,
'title' => '获得' . $title,
'number' => $couponPrice,
'mark' => '获得' . $title . $couponPrice . ",订单金额:{$amount}",

View File

@ -7,6 +7,7 @@ use app\common\dao\store\order\StoreCartDao;
use app\common\dao\store\StoreActivityDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\product\ProductCate;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\community\CommunityRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
@ -81,8 +82,32 @@ class StoreOrderCreateRepository extends StoreOrderRepository
//检查商品类型, 活动商品只能单独购买
$allowDelivery = true;
$activityProductCount = 0;
//判断是否是平台购物卡,购物卡不允许使用任何优惠券
$merchantCate = $merchantCartList[0]['list'][0]->product->merCateId;
$isPlatformCard = false;
if (!empty($merchantCate) && in_array(env('PLATFORM_CARD_CATE_ID'), array_column($merchantCate->toArray(), 'mer_cate_id'))) {
$isPlatformCard = true;
}
if ($isPlatformCard) {
$merchantTypeId = Merchant::where('uid', $uid)->value('type_id');
if (empty($merchantTypeId) || $merchantTypeId != 21) {
throw new ValidateException('大礼包仅限种养殖户购买');
}
//平台购物卡仅能购买一次
$productIds = ProductCate::where('mer_cate_id', env('PLATFORM_CARD_CATE_ID'))->column('product_id');
$orderRecord = StoreOrder::alias('t1')
->leftJoin('store_order_product t2', 't1.order_id = t2.order_id')
->whereIn('product_id', $productIds)
->where('t1.uid', $uid)
->where('paid', 1)
->where('is_refund', 0)
->count();
if ($orderRecord > 0) {
throw new ValidateException('大礼包仅能购买一次');
}
}
foreach ($merchantCartList as $merchantCart) {
if (($merchantCart['type_id'] != Merchant::TypeSupplyChain) && $address && $merchantCart['list'][0]['product_type'] != 2) {
if (($merchantCart['type_id'] != Merchant::TypeSupplyChain) && $address && $merchantCart['list'][0]['product_type'] != 2 && $merchantCart['list'][0]['product']['type'] != 1) {
if ($merchantCart['street_id'] != $address['street_code'] && $createOrder && !in_array($merchantCart['mer_id'], $takes)) {
throw new ValidateException('不支持跨区域购买,请在【我的】-【地址管理】更改后重新购买');
}
@ -135,7 +160,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$order_extend = json_decode($cart['product']['extend'], true);
}
if ($address) {
if ($cart['source'] == 0 || $cart['source'] == 103) {
if (($cart['source'] == 0 || $cart['source'] == 103) && $cart['product']['type'] != 1) {
$userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0);
$getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode;
$curl = new Curl();
@ -161,13 +186,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$presellType = 0;
$consumption_coupon_id = 0;
$fn = [];
if (in_array($source, [0, 2, 103])) {
$enabledPlatformCoupon = true;
} else {
$enabledPlatformCoupon = false;
}
$enabledPlatformCoupon = true;
$order_total_postage = 0;
$platformCoupon = [];
if ($isPlatformCard) {
$enabledPlatformCoupon = false;
}
//套餐订单
@ -247,7 +271,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$enabledCoupon = !($order_type && $order_type != 2);
//只有预售和普通商品可以用优惠券
if (!$enabledCoupon) {
if (!$enabledCoupon || $isPlatformCard) {
$merchantCart['coupon'] = [];
}
$svip_coupon_merge = merchantConfig($merchantCart['mer_id'], 'svip_coupon_merge');
@ -521,22 +545,19 @@ class StoreOrderCreateRepository extends StoreOrderRepository
// if ($total_true_price > 0) {
$StoreCouponUser = app()->make(StoreCouponUserRepository::class);
$platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid);
$platformConsumption = [];
//消费金
if ($source == 103) {
$ConsumptionWhere = [
'uid' => $uid,
'status' => 0,
'is_fail' => 0
];
$ConsumptionWhere = [
'uid' => $uid,
'status' => 0,
'is_fail' => 0
];
$platformConsumption = Db::name('store_consumption_user')->where($ConsumptionWhere)->limit(100)->order('create_time', 'desc')
->field('coupon_user_id,uid,coupon_title,coupon_price,balance,start_time,end_time')
->select()->each(function ($item) {
$item['describe'] = '仅限平台指定商家商品可使用';
return $item;
});
}
$platformConsumption = Db::name('store_consumption_user')->where($ConsumptionWhere)->limit(100)->order('create_time', 'desc')
->field('coupon_user_id,uid,coupon_title,coupon_price,balance,start_time,end_time')
->select()->each(function ($item) {
$item['describe'] = '仅限平台指定商家商品可使用';
return $item;
});
// }
$usePlatformCouponId = 0;
@ -629,7 +650,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$consumptionTotal = 0;
$consumptionUsed = 0;
$groupOrderPayPrice = 0;
if ($consumption_id > 0 && $this->store_consumption_user && $source == 103) {
if ($consumption_id > 0 && $this->store_consumption_user) {
$consumptionTotal = min($order_total_price, $this->balance);
}
foreach ($merchantCartList as $k => &$merchantCart) {
@ -728,7 +749,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$order_model = $orderInfo['order_model'];
$order_extend = $orderInfo['order_extend'];
if ($pay_type == 'balance' && $orderInfo['source'] != 103 && $orderInfo['source'] != 105) {
throw new ValidateException('余额支付只能用于里海云仓');
// throw new ValidateException('余额支付只能用于里海云仓');
}
// 以下判断无意义v2CartIdByOrderInfo 已经判断过收货地址或自提地址
// if (!$orderInfo['order_delivery_status']) {

View File

@ -361,6 +361,19 @@ class StoreOrderRepository extends BaseRepository
// "惠农供销,谱写数字新篇章"活动首单分润,商户和村、小组合伙人
$financeDao = (new CommissionDao())->firstOrderCommission($order, $financeDao);
}
//判断是否是平台购物卡
$merchantCate = $order->orderProduct[0]->product->merCateId;
if (!empty($merchantCate) && in_array(env('PLATFORM_CARD_CATE_ID'), array_column($merchantCate->toArray(), 'mer_cate_id'))) {
//购物卡自动发货
$deliveryData = [
'delivery_type' => 3,
'remark' => '',
'delivery_name' => '',
'delivery_id' => '',
];
$this->runDelivery($order['order_id'], $order['mer_id'], $deliveryData, ['is_split' => 0, 'split' => []], 'delivery');
}
}
//分销判断
// if ($groupOrder->user->spread_uid) {

View File

@ -56,6 +56,7 @@ return [
\crmeb\listens\CloseUserSvipListen::class,
\crmeb\listens\SendSvipCouponListen::class,
\crmeb\listens\AutoCheckCreditBuyListen::class,
\crmeb\listens\ActivateConsumptionListen::class,
] : [],
'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class],
'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class],
@ -77,6 +78,7 @@ return [
'refund.deliver'=>[\app\listener\DeliverRefund::class],
'order.create'=>[\app\listener\OrderCreate::class],
'order.take'=>[\app\listener\OrderTake::class],
'order.delivery' => [\crmeb\listens\OrderDeliveryListen::class], // 发货事件
],
'subscribe' => [],

View File

@ -0,0 +1,48 @@
<?php
namespace crmeb\listens;
use app\common\model\store\consumption\StoreConsumption;
use app\common\model\store\consumption\StoreConsumptionUser;
use app\common\model\store\order\StoreOrder;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\UserBill;
use crmeb\interfaces\ListenerInterface;
use crmeb\services\TimerService;
use think\facade\Log;
/**
* 定时任务:激活商户补贴
*/
class ActivateConsumptionListen extends TimerService implements ListenerInterface
{
public function handle($event): void
{
$this->tick(1000 * 60, function () {
Log::info('定时任务:激活商户补贴');
$couponId = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->value('coupon_id');
if (empty($couponId)) {
return;
}
$storeConsumptionUser = StoreConsumptionUser::where('coupon_id', $couponId)
->where('status', StoreConsumptionUser::STATUS_REPEAL)
->select();
foreach ($storeConsumptionUser as $item) {
$isUsed = StoreConsumptionUser::where('order_id_set', $item['order_id_set'])
->where('balance', 0)
->count();
$merchantId = Merchant::where('uid', $item['uid'])->value('mer_id');
$saleTotal = StoreOrder::where('mer_id', $merchantId)->whereIn('status', [2, 3])->sum('pay_price');
if ($saleTotal >= $item['order_amount'] && $isUsed > 0) {
$item->status = StoreConsumptionUser::STATUS_UNUSED;
$item->start_time = date('Y-m-d H:i:s');
$item->end_time = date('Y-m-d H:i:s', strtotime('+1 year'));
$item->save();
UserBill::where('link_id', $item['coupon_user_id'])->where('type', 'red_pack_2')->update(['status', 1]);
}
}
});
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace crmeb\listens;
use app\common\dao\store\consumption\StoreConsumptionUserDao;
use app\common\model\store\consumption\StoreConsumption;
use app\common\model\store\consumption\StoreConsumptionUser;
use crmeb\interfaces\ListenerInterface;
/**
* Class OrderDeliveryListen
*/
class OrderDeliveryListen implements ListenerInterface
{
public function handle($event): void
{
$order = $event['order'];
foreach ($order->orderProduct as $orderProduct) {
$merchantCate = $orderProduct->product->merCateId;
if (empty($merchantCate) || $merchantCate[0]['mer_cate_id'] != env('PLATFORM_CARD_CATE_ID')) {
continue;
}
$consumption = StoreConsumption::where('type', StoreConsumption::TYPE_PULL_CONSUMPTION)->find();
/** @var StoreConsumptionUserDao $repo */
$repo = app()->make(StoreConsumptionUserDao::class);
$repo->startTime = date('Y-m-d H:i:s');
$repo->endTime = '2025-07-01';
$repo->send($consumption, 1, $order['uid'], $order['group_order_id'], $order->total_price, StoreConsumptionUser::STATUS_UNUSED);
//TODO 当商户销售和购买达到指定金额后,激活抵扣补贴
$consumption = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->find();
$repo->startTime = date('Y-m-d H:i:s');
$repo->endTime = '2025-07-01';
$rate = $this->getRate($order->total_price);
$repo->send($consumption, $rate, $order['uid'], $order['group_order_id'], $order->total_price, StoreConsumptionUser::STATUS_REPEAL, StoreConsumptionUser::TYPE_TWO);
}
}
public function getRate($orderAmount)
{
if ($orderAmount >= 1000 && $orderAmount < 5000) {
$rate = 0.05;
} elseif ($orderAmount >= 5000 && $orderAmount < 10000) {
$rate = 0.10;
} elseif ($orderAmount >= 10000 && $orderAmount < 50000) {
$rate = 0.15;
} elseif ($orderAmount >= 50000 && $orderAmount <= 100000) {
$rate = 0.20;
}
return $rate ?? 0;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Some files were not shown because too many files have changed in this diff Show More