feat: 修改商品列表接口,移除无用代码并优化响应数据

This commit is contained in:
mkm 2024-06-26 13:40:31 +08:00
parent 2d0979333e
commit 27b199994a
6 changed files with 124 additions and 165 deletions

View File

@ -61,8 +61,8 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
//2或者1
$where[]=['cate_id','=',$class_all];
}
return StoreBranchProduct::where($this->searchWhere)->where($where)
$this->searchWhere[]=$where;
return StoreBranchProduct::where($this->searchWhere)
->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status','batch','vip_price','manufacturer_information'])
->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']);
@ -99,17 +99,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/
public function count(): int
{
$status = $this->params['status'] ?? '';
$class_all=$this->request->get('class_all');
$where=[];
if($class_all){
$arr=Cate::where('pid',$class_all)->column('id');
if($arr){
$arr2=Cate::where('pid','in',$arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)];
}
}
return StoreBranchProduct::where($this->searchWhere)->where($where)
return StoreBranchProduct::where($this->searchWhere)
->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']);
})

View File

@ -81,57 +81,57 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt
$item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
})->toArray();
foreach ($data as $key => $item) {
$list1 = StoreFinanceFlow::where('order_id', $item['order_id'])->where('financial_type', '>', 1)->field($field)->select()->each(function ($item) {
if ($item['user_id'] <= 0) {
$item['nickname'] = '游客';
} else {
$id = $item['user_id'];
$item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "|$id";
}
if (!empty($this->request->adminInfo['store_id'])) {
$item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0;
}
if ($item['financial_pm'] == 0) {
$item['number'] = '-' . $item['number'];
$item['financial_type_name'] = '订单支出:' . OrderEnum::getFinancialType($item['financial_type']);
} else {
$item['financial_type_name'] = OrderEnum::getFinancialType($item['financial_type']) . '获得';
$item['number'] = '+' . $item['number'];
}
$item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name');
$item['store_name'] = $item['store_id'] > 0 ? SystemStore::where('id', $item['store_id'])->value('name') : '';
$item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
});
$list2 = UserSign::where('order_id', $item['order_sn'])->whereIn('user_ship', [0, 2, 3])->select();
foreach ($list2 as $k => $v) {
$list2[$k]['id'] = 'JF' . $v['id'];
$list2[$k]['order_sn'] = $item['order_sn'];
$list2[$k]['store_name'] = $item['store_name'];
if($v['user_ship']==0){
$list2[$k]['financial_pm'] = 1;
$list2[$k]['number'] = '+' . $v['number'];
}else{
if($v['financial_pm']==1){
$list2[$k]['financial_pm'] = 1;
$list2[$k]['number'] = '+' . $v['number'];
}else{
$list2[$k]['financial_pm'] = 0;
$list2[$k]['number'] = '-' . $v['number'];
}
}
$list2[$k]['nickname'] = $v['uid'] > 0 ? User::where('id', $v['uid'])->value('nickname') . '|' . $v['uid'] : '游客';
$list2[$k]['financial_type_name'] = $v['title'];
$list2[$k]['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
}
$list3 = array_merge($list1->toArray(), $list2->toArray());
// 提取 financial_pm 字段到单独的数组
$financial_pm = array_column($list3, 'financial_pm');
// foreach ($data as $key => $item) {
// $list1 = StoreFinanceFlow::where('order_id', $item['order_id'])->where('financial_type', '>', 1)->field($field)->select()->each(function ($item) {
// if ($item['user_id'] <= 0) {
// $item['nickname'] = '游客';
// } else {
// $id = $item['user_id'];
// $item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "|$id";
// }
// if (!empty($this->request->adminInfo['store_id'])) {
// $item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0;
// }
// if ($item['financial_pm'] == 0) {
// $item['number'] = '-' . $item['number'];
// $item['financial_type_name'] = '订单支出:' . OrderEnum::getFinancialType($item['financial_type']);
// } else {
// $item['financial_type_name'] = OrderEnum::getFinancialType($item['financial_type']) . '获得';
// $item['number'] = '+' . $item['number'];
// }
// $item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name');
// $item['store_name'] = $item['store_id'] > 0 ? SystemStore::where('id', $item['store_id'])->value('name') : '';
// $item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
// });
// $list2 = UserSign::where('order_id', $item['order_sn'])->whereIn('user_ship', [0, 2, 3])->select();
// foreach ($list2 as $k => $v) {
// $list2[$k]['id'] = 'JF' . $v['id'];
// $list2[$k]['order_sn'] = $item['order_sn'];
// $list2[$k]['store_name'] = $item['store_name'];
// if($v['user_ship']==0){
// $list2[$k]['financial_pm'] = 1;
// $list2[$k]['number'] = '+' . $v['number'];
// }else{
// if($v['financial_pm']==1){
// $list2[$k]['financial_pm'] = 1;
// $list2[$k]['number'] = '+' . $v['number'];
// }else{
// $list2[$k]['financial_pm'] = 0;
// $list2[$k]['number'] = '-' . $v['number'];
// }
// }
// $list2[$k]['nickname'] = $v['uid'] > 0 ? User::where('id', $v['uid'])->value('nickname') . '|' . $v['uid'] : '游客';
// $list2[$k]['financial_type_name'] = $v['title'];
// $list2[$k]['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']);
// }
// $list3 = array_merge($list1->toArray(), $list2->toArray());
// // 提取 financial_pm 字段到单独的数组
// $financial_pm = array_column($list3, 'financial_pm');
// 对 financial_pm 数组进行排序,这将影响原始数组
array_multisort($financial_pm, SORT_ASC, $list3);
$data[$key]['list']=$list3;
}
// // 对 financial_pm 数组进行排序,这将影响原始数组
// array_multisort($financial_pm, SORT_ASC, $list3);
// $data[$key]['list']=$list3;
// }
return $data;
}

View File

@ -75,7 +75,7 @@ class OrderLogic extends BaseLogic
self::$store_price = 0; //门店零售价
/** 计算价格 */
$off_activity=Config::where('name','off_activity')->value('value');
if($off_activity==1){
if($off_activity!=1){
$field='id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id';
}else{
$field='id branch_product_id,store_name,image,unit,cost price,vip_price,cost,purchase,product_id';

View File

@ -19,6 +19,7 @@ use app\common\service\SmsService;
use Exception;
use support\Cache;
use think\facade\Db;
use app\common\model\system_store\SystemStore;
class StoreOrderLogic extends BaseLogic
{
@ -32,6 +33,11 @@ class StoreOrderLogic extends BaseLogic
* @notes 获取购物车商品信息
* @param $params
* @return array|bool
*/
/**
* @notes 获取购物车商品信息
* @param $params
* @return array|bool
*/
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [])
{
@ -45,14 +51,19 @@ class StoreOrderLogic extends BaseLogic
try {
self::$total_price = 0;
self::$pay_price = 0;
self::$cost = 0; //成本
self::$cost = 0; //成本由采购价替代原成本为门店零售价
self::$profit = 0; //利润
self::$activity_price = 0; //活动减少
self::$store_price = 0; //门店零售价
/** 计算价格 */
$pay_type = isset($params['pay_type'])?$params['pay_type']:0;
// $off_activity=Config::where('name','off_activity')->value('value');
// if($off_activity==1){
// $field='id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id';
// }else{
$field='id branch_product_id,store_name,image,unit,cost price,vip_price,cost,purchase,product_id';
// }
foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,swap')->withTrashed()->find();
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->withTrashed()->find();
if (!$find) {
continue;
}
@ -63,47 +74,39 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
$cart_select[$k]['vip'] = 0;
if ($user && $user['user_ship'] == 1) {
//更新 会员为1的时候原价减去会员价
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
$cart_select[$k]['vip'] =1;
}
// if($off_activity!=1){
// if ($user && $user['user_ship'] == 1) {
// //更新 会员为1的时候原价减去会员价
// $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
// $cart_select[$k]['deduction_price'] =$deduction_price_count;
// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
// $cart_select[$k]['vip'] =1;
// }
// if ($user && $user['user_ship'] == 4) {
// //更新 为4商户的时候减去商户价格
// $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
// $cart_select[$k]['deduction_price'] =$deduction_price_count;
// self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
// }
// }
if ($user && $user['user_ship'] == 4) {
//更新 为4商户的时候减去商户价格
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
if($pay_type ==19){
if ($find['swap'] < $cart_select[$k]['cart_num']) {
throw new \Exception('兑换数量不足');
}
}
//利润
// $cart_select[$k]['profit'] = bcmul($cart_select[$k]['total_price'],0.05,2); //利润
// $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
$cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价
$cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2)??0; //vip售价
$cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['vip_price'],2);
// d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] );
$cartInfo = $cart_select[$k];
$cartInfo['name'] = $find['store_name'];
$cartInfo['image'] = $find['image'];
//计算好vip价格
// $vipPrice = self::dealVip($find['price']);
// if ($vipPrice) {
// $cartInfo['price'] = $vipPrice;
// }
//$cart_select[$k]['total'] - $vipPrice ?? 0;
$cart_select[$k]['cart_info'] = json_encode($cartInfo);
$cart_select[$k]['branch_product_id'] = $find['branch_product_id'];
//理论上每笔都是拆分了
@ -113,53 +116,52 @@ class StoreOrderLogic extends BaseLogic
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2);
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
}
if ($user && $user['user_ship'] == 1 && $pay_type !=17) {
$pay_price = self::$pay_price;
$activity_string = '';
}else{
$pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
$activity_string = '减免';
}
if($pay_type == 19){
$pay_price = self::$pay_price;
$activity_string = '';
}
//加支付方式限制
// $pay_type = isset($params['pay_type'])?$params['pay_type']:0;
// if ($user && $user['user_ship'] == 1 && $pay_type !=17) {
// $pay_price = self::$pay_price;
// }else{
// $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
// }
$pay_price = self::$pay_price;
// if($pay_price < 500){
// throw new \think\Exception('金额低于500');
// throw new Exception('金额低于500');
// }
$vipPrice = 0;
//成本价 收益
$order = [
'create_time' => time(),
'order_id' =>$params['order_id'] ?? getNewOrderId('PF'),
'order_id' => $params['order_id'] ?? getNewOrderId('PF'),
'total_price' => self::$total_price, //总价
'cost' => self::$cost,//成本价
'profit' => 0,//利润
'pay_price' => $pay_price,//后期可能有降价抵扣
'vip_price' => $vipPrice,
'total_num' => count($cart_select),//总数
'cost' => self::$cost, //成本价1-
'pay_price' => $pay_price, //后期可能有降价抵扣
'vip_price' => 0,
'total_num' => count($cart_select), //总数
'pay_type' => $params['pay_type'] ?? 0,
'reservation_time' => $params['reservation_time'] ?? null,
'cart_id' => implode(',', $cartId),
'store_id' => $params['store_id'] ?? 0,
'shipping_type' =>3,//配送方式 1=快递 2=门店自提
'activity' =>$activity_string,
'activity_price' =>self::$activity_price,//活动优惠价
'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 2=门店自提
'activity' => '减免',
'activity_price' => self::$activity_price,
'activities' => self::$activity_price>0?1:0,
'default_delivery'=>1,
'original_price'=>self::$total_price,
'deduction_price' => self::$activity_price,//抵扣金额
'deduction_price' => self::$activity_price,
'is_vip' => 0,
'is_storage' => $params['is_storage']??0,
];
if($user && $user['user_ship']!=4){
$order['is_vip']=1;
$order['default_delivery'] = 0;
if ($params['store_id']) {
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
}
if($user && $user['user_ship']>=1 &&$user['user_ship']<=3){
$order['is_vip'] = 1;
}
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;

View File

@ -85,7 +85,6 @@ class StoreOrderController extends BaseAdminController
$params = $this->request->post();
$params['store_id'] = $this->adminInfo['store_id'];
$user = User::where('id', $params['uid'])->find();
$params['shipping_type'] =3;
$res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, $user, $params);
if ($res == false) {
$msg = StoreOrderLogic::getError();
@ -347,34 +346,25 @@ class StoreOrderController extends BaseAdminController
*/
public function rechange_amount()
{
// $order = UserRecharge::where('order_id','CZ1719052252643357')->find();
// $order['pay_price'] = $order['price'];
// d(1);
// PayNotifyLogic::handle('recharge', $order['order_id'], $order);
// d(1);
$pay_type = $this->request->post('pay_type');
$auth_code = $this->request->post('auth_code'); //微信支付条码
if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {
return $this->fail('支付条码不能为空');
}
$params = $this->request->post();
switch ($pay_type) {
case PayEnum::CASH_PAY:
$recharge_type = 'CASH_PAY';
break;
case PayEnum::WECHAT_PAY_BARCODE:
$recharge_type = 'INDUSTRYMEMBERS';
break;
case PayEnum::ALIPAY_BARCODE:
$recharge_type = 'ALI_INDUSTRYMEMBERS';
break;
default:
$recharge_type = '';
break;
}
$data = [
'store_id' => $this->adminInfo['store_id'],
'uid' => $params['uid'],
'staff_id' => $this->adminId,
'order_id' => getNewOrderId('CZ'),
'price' => $params['price'],
'recharge_type' =>$recharge_type,
'type' => 1,
'recharge_type' => 'INDUSTRYMEMBERS',
];
$order = UserRecharge::create($data);
$order['pay_price'] = $order['price'];

View File

@ -19,31 +19,9 @@ use app\store\validate\store_product\StoreProductValidate;
// #[ApiDoc\title('商品列表')]
class StoreProductController extends BaseAdminController
{
// #[
// ApiDoc\Title('商品列表'),
// ApiDoc\url('/store/store_product/storeProduct/lists'),
// ApiDoc\Method('GET'),
// ApiDoc\NotHeaders(),
// ApiDoc\Query(name: 'cate_id', type: 'int', require: false, desc: '分类id'),
// ApiDoc\Query(name: 'store_name', type: 'string', require: false, desc: '商品名称'),
// ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态1上架2下架3售罄4库存告警'),
// ApiDoc\Header(ref: [Definitions::class, "token"]),
// ApiDoc\Query(ref: [Definitions::class, "page"]),
// ApiDoc\ResponseSuccess("data", type: "array", children: [
// ['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
// ['name' => 'product_id', 'desc' => '商品ID', 'type' => 'int'],
// ['name' => 'image', 'desc' => '图片', 'type' => 'string'],
// ['name' => 'store_name', 'desc' => '商品名称', 'type' => 'string'],
// ['name' => 'price', 'desc' => '零售价', 'type' => 'float'],
// ['name' => 'cost', 'desc' => '成本价', 'type' => 'float'],
// ['name' => 'sales', 'desc' => '销量', 'type' => 'int'],
// ['name' => 'stock', 'desc' => '库存', 'type' => 'int'],
// ['name' => 'unit_name', 'desc' => '单位', 'type' => 'string'],
// ['name' => 'cate_name', 'desc' => '分类', 'type' => 'string'],
// ['name' => 'status', 'desc' => '状态1上架0下架', 'type' => 'string'],
// ]),
// ]
/**
* 商品列表
*/
public function lists()
{
return $this->dataLists(new StoreBranchProductLists());
@ -194,5 +172,4 @@ class StoreProductController extends BaseAdminController
StoreBranchProductLogic::stock($params);
return $this->success('操作成功', [], 1, 1);
}
}