feat: 修改用户充值API,优化订单逻辑和用户签到逻辑

This commit is contained in:
mkm 2024-07-12 11:09:16 +08:00
parent 9ea0327998
commit 42a9130a7a
3 changed files with 96 additions and 63 deletions

View File

@ -1,60 +1,46 @@
<?php
namespace app\api\controller\user;
namespace app\api\controller\user;
use app\api\lists\user\UserFeedbackLists;
use app\api\logic\user\UserFeedbackLogic;
use app\admin\validate\user\UserFeedbackValidate;
use app\api\controller\BaseApiController;
use app\api\lists\user\UserFeedbackLists;
use app\api\logic\user\UserFeedbackLogic;
use app\admin\validate\user\UserFeedbackValidate;
use app\api\controller\BaseApiController;
use app\api\lists\user\UserRechargeLists;
use app\common\model\dict\DictData;
class UserRechargeController extends BaseApiController
{
/**
* @notes 获取用户充值
* @return \support\Response
* @author likeadmin
* @date 2024/05/13 16:56
*/
public function lists()
{
return $this->dataLists(new UserRechargeLists());
}
class UserRechargeController extends BaseApiController
{
/**
* @notes 获取用户充值
* @return \support\Response
* @author likeadmin
* @date 2024/05/13 16:56
*/
public function lists()
{
return $this->dataLists(new UserRechargeLists());
}
public function recharge_list()
{
$buy_bar = "元采购包";
$send_bar = "品牌礼品券";
$arr = [
[
'money'=>1000,//采购包
// 'money'=>1,//采购包
'send'=>249,//礼品券
'money_string'=>$buy_bar,
'send_string'=>$send_bar,
],
[
'money'=>2000,//采购包
'send'=>560,//礼品券
'money_string'=>$buy_bar,
'send_string'=>$send_bar,
],
[
'money'=>5000,//采购包
'send'=>1550,//礼品券
'money_string'=>$buy_bar,
'send_string'=>$send_bar,
],
[
'money'=>10000,//采购包
'send'=>3500,//礼品券
'money_string'=>$buy_bar,
'send_string'=>$send_bar,
]
];
return $this->success('ok',$arr);
}
}
public function recharge_list()
{
$buy_bar = "元采购包";
$send_bar = "品牌礼品券";
$list = DictData::where('type_value', 'recharge')->select()
->each(function($item)use($buy_bar,$send_bar){
$item['money'] = $item['value'];
$item['money_string'] = $buy_bar;
$item['send_string'] = $send_bar;
if($item['name']=='level_one'){
$item['send'] = 249;
}elseif($item['name']=='level_two'){
$item['send'] = 560;
}elseif($item['name']=='level_three'){
$item['send'] = 1550;
}elseif($item['name']=='level_four'){
$item['send'] = 3500;
}
});
return $this->success('ok', $list?->toArray());
}
}

View File

@ -16,6 +16,7 @@ use app\common\model\dict\DictData;
use app\common\model\dict\DictType;
use app\common\model\order\Cart;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
@ -62,7 +63,7 @@ class OrderLogic extends BaseLogic
* @param $params
* @return array|bool
*/
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [])
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0)
{
$where = ['is_pay' => 0];
$cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray();
@ -80,16 +81,29 @@ class OrderLogic extends BaseLogic
self::$deduction_price = 0;
self::$frozen_money = 0; //返还金额
$deduction_price = 0; //抵扣金额
$fresh_price = 0; //生鲜金额
/** 计算价格 */
$off_activity = Config::where('name', 'off_activity')->value('value');
$field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id';
$field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id';
foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find();
if (!$find) {
// unset($cart_select[$k]);
// continue;
$field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id';
$field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id,cate_id';
$find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
if ($find) {
$cate_id = StoreCategory::where('id', $find['cate_id'])->value('pid');
if ($cate_id > 0) {
$cate_id = StoreCategory::where('id', $cate_id)->value('pid');
if ($cate_id > 0) {
$cate_id = StoreCategory::where('id', $cate_id)->value('pid');
$find['top_cate_id'] = $cate_id;
} else {
$find['top_cate_id'] = $cate_id;
}
}
}
$cart_select[$k]['status'] = 1; //缺货标识
}
unset($cart_select[$k]['id']);
@ -114,6 +128,10 @@ class OrderLogic extends BaseLogic
$deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2);
$cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额
}
//计算生鲜
if ($createOrder == 1 && $find['top_cate_id'] == 15201) {
$fresh_price=bcadd($fresh_price,$cart_select[$k]['pay_price']);
}
$cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num'];
@ -153,6 +171,14 @@ class OrderLogic extends BaseLogic
// if ($user && $user['user_ship'] == 1 && $pay_type != 17) {
// $pay_price = self::$pay_price;
// } else {
//判断生鲜是否大于200
if($createOrder==1 && $fresh_price>0){
if($fresh_price<200){
self::setError('订单里的生鲜必须大于金额200元');
return false;
}
}
$pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
// }
//成本价 收益
@ -236,7 +262,11 @@ class OrderLogic extends BaseLogic
$verify_code = createCode($code);
$params['order_id'] = $order_id;
$params['verify_code'] = $verify_code;
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params);
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1);
if($orderInfo==false){
self::setError(self::getError());
return false;
}
if (!$orderInfo) {
return false;
}

View File

@ -5,6 +5,7 @@ namespace app\common\logic;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\dict\DictData;
use app\common\model\user\User;
use app\common\model\user_recharge\UserRecharge;
use app\common\model\user_sign\UserSign;
@ -23,22 +24,38 @@ class UserSignLogic extends BaseLogic
*/
public static function dealRechargeFrozen($user, $order, $user_ship = 0)
{
$total_vip = 0;
$level_one = 1000;
$level_two = 2000;
$level_three = 5000;
$level_four = 10000;
$list = DictData::where('type_value', 'recharge')->select();
foreach( $list as $k=>$v){
if($v['name']=='level_one'){
$level_one = $v['value'];
}elseif($v['name']=='level_two'){
$level_two = $v['value'];
}elseif($v['name']=='level_three' ){
$level_three = $v['value'];
}elseif($v['name']=='level_four'){
$level_four = $v['value'];
}
}
$price=(int)$order['price'];
switch ($price) {
case 1000:
case $level_one:
$total_vip = 249;
break;
case 2000:
case $level_two:
$total_vip = 560;
break;
case 5000:
case $level_three:
$total_vip = 1550;
break;
case 10000:
case $level_four:
$total_vip = 3500;
break;
default:
$total_vip = 0;
break;
}
if($total_vip==0){