feat: 添加订单商品、编辑订单商品和删除订单商品的功能
This commit is contained in:
parent
bbbed26fbf
commit
1648d48c15
@ -54,7 +54,37 @@ class StoreOrderCartInfoController extends BaseAdminController
|
|||||||
$res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time);
|
$res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time);
|
||||||
return $this->data($res);
|
return $this->data($res);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @notes 追加订单商品
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/05/31 16:02
|
||||||
|
*/
|
||||||
|
public function add()
|
||||||
|
{
|
||||||
|
$params = $this->request->post();
|
||||||
|
$result = StoreOrderCartInfoLogic::add($params);
|
||||||
|
return $this->success('添加成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @notes 编辑订单商品
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/05/31 16:02
|
||||||
|
*/
|
||||||
|
public function edit()
|
||||||
|
{
|
||||||
|
$params = $this->request->post();
|
||||||
|
$result = StoreOrderCartInfoLogic::edit($params);
|
||||||
|
return $this->success('编辑成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function del()
|
||||||
|
{
|
||||||
|
$params = $this->request->post();
|
||||||
|
$result = StoreOrderCartInfoLogic::del($params);
|
||||||
|
return $this->success('删除成功', [], 1, 1);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 导出配送表格
|
* 导出配送表格
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +51,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return StoreOrderCartInfo::where($this->searchWhere)
|
return StoreOrderCartInfo::where($this->searchWhere)
|
||||||
->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
|
->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
|
||||||
->select()->each(function ($item) {
|
->select()->each(function ($item) {
|
||||||
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
|
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
|
||||||
if($find){
|
if($find){
|
||||||
|
@ -4,7 +4,12 @@ namespace app\admin\logic\store_order_cart_info;
|
|||||||
|
|
||||||
use app\admin\logic\statistic\TradeStatisticLogic;
|
use app\admin\logic\statistic\TradeStatisticLogic;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单购物详情表逻辑
|
* 订单购物详情表逻辑
|
||||||
@ -13,6 +18,129 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
|||||||
*/
|
*/
|
||||||
class StoreOrderCartInfoLogic extends BaseLogic
|
class StoreOrderCartInfoLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @notes 编辑商品列表
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/05/31 10:53
|
||||||
|
*/
|
||||||
|
public static function add(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find();
|
||||||
|
if($cart_info['is_pay']==1){
|
||||||
|
throw new BusinessException('已支付订单无法追加');
|
||||||
|
}
|
||||||
|
foreach($params['product_arr'] as $k=>$v){
|
||||||
|
$find=StoreProduct::where('id',$v['product_id'])->find();
|
||||||
|
|
||||||
|
$cart_select['total_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单总价
|
||||||
|
|
||||||
|
$cart_select['price'] = $v['price'];
|
||||||
|
$cart_select['cost'] = $v['price'];
|
||||||
|
$cart_select['vip'] = 0;
|
||||||
|
$cart_select['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称
|
||||||
|
|
||||||
|
$cart_select['purchase'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //成本
|
||||||
|
$cart_select['pay_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单支付金额
|
||||||
|
$cart_select['store_price'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //商户价
|
||||||
|
$cart_select['vip_price'] = 0; //vip售价
|
||||||
|
|
||||||
|
$cart_select['product_id'] = $find['id'];
|
||||||
|
$cart_select['old_cart_id'] = 0;
|
||||||
|
$cart_select['cart_num'] = $v['cart_num'];
|
||||||
|
$cart_select['verify_code'] =$cart_info['verify_code'];
|
||||||
|
$cart_select['vip_frozen_price'] = 0;
|
||||||
|
$cart_select['store_info'] = $find['store_info'];
|
||||||
|
$cart_select['rose'] = $find['rose'];
|
||||||
|
|
||||||
|
$cart_select['name'] = $find['store_name'];
|
||||||
|
$cart_select['image'] = $find['image'];
|
||||||
|
$aa[$k]['cart_info'] = json_encode($cart_select);
|
||||||
|
$aa[$k]['oid'] = $cart_info['oid'];
|
||||||
|
$aa[$k]['uid']=$cart_info['uid'];
|
||||||
|
$aa[$k]['product_id']=$find['id'];
|
||||||
|
$aa[$k]['verify_code']=$cart_info['verify_code'];
|
||||||
|
$aa[$k]['price']=$v['price'];
|
||||||
|
$aa[$k]['cart_num']=$v['cart_num'];
|
||||||
|
$aa[$k]['total_price']=$cart_select['pay_price'];
|
||||||
|
}
|
||||||
|
(new StoreOrderCartInfo())->saveAll($aa);
|
||||||
|
$total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price');
|
||||||
|
$total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count();
|
||||||
|
|
||||||
|
StoreOrder::where('id', $params['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]);
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
d($e);
|
||||||
|
throw new BusinessException('编辑商品失败' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @notes 编辑商品列表
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/05/31 10:53
|
||||||
|
*/
|
||||||
|
public static function edit(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$find = StoreOrderCartInfo::where('id', $params['id'])->find();
|
||||||
|
if ($find) {
|
||||||
|
if($find['is_pay']==1){
|
||||||
|
throw new BusinessException('已支付订单无法编辑');
|
||||||
|
}
|
||||||
|
$find->cart_num = $params['cart_num'];
|
||||||
|
$find->total_price = bcmul($params['cart_num'], $find->price, 2);
|
||||||
|
$find->save();
|
||||||
|
$total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price');
|
||||||
|
$total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count();
|
||||||
|
StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]);
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException('编辑商品失败' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除商品
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/05/31 10:53
|
||||||
|
*/
|
||||||
|
public static function del(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$find = StoreOrderCartInfo::where('id', $params['id'])->find();
|
||||||
|
if ($find) {
|
||||||
|
if($find['is_pay']==1){
|
||||||
|
throw new BusinessException('已支付订单无法删除');
|
||||||
|
}
|
||||||
|
$find->delete_time=time();
|
||||||
|
$find->save();
|
||||||
|
$total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price');
|
||||||
|
$total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count();
|
||||||
|
StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]);
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException('删除商品失败' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
public function curve($product_id, $start_time, $end_time)
|
public function curve($product_id, $start_time, $end_time)
|
||||||
{
|
{
|
||||||
$store_order_cart_info = new StoreOrderCartInfo();
|
$store_order_cart_info = new StoreOrderCartInfo();
|
||||||
@ -29,13 +157,13 @@ class StoreOrderCartInfoLogic extends BaseLogic
|
|||||||
$totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)');
|
$totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)');
|
||||||
$totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey);
|
$totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey);
|
||||||
|
|
||||||
$value1=[];
|
$value1 = [];
|
||||||
$value2=[];
|
$value2 = [];
|
||||||
foreach($totalCartNum1['y'] as $k=>$v){
|
foreach ($totalCartNum1['y'] as $k => $v) {
|
||||||
$value1[]=$v;
|
$value1[] = $v;
|
||||||
}
|
}
|
||||||
foreach($totalCartNum2['y'] as $k=>$v){
|
foreach ($totalCartNum2['y'] as $k => $v) {
|
||||||
$value2[]=$v;
|
$value2[] = $v;
|
||||||
}
|
}
|
||||||
$data = [];
|
$data = [];
|
||||||
$data['xAxis'] = $totalCartNum1['x'] ?? [];
|
$data['xAxis'] = $totalCartNum1['x'] ?? [];
|
||||||
@ -45,9 +173,9 @@ class StoreOrderCartInfoLogic extends BaseLogic
|
|||||||
'smooth' => 'true',
|
'smooth' => 'true',
|
||||||
'type' => 'line',
|
'type' => 'line',
|
||||||
'yAxisIndex' => 1,
|
'yAxisIndex' => 1,
|
||||||
'value' =>$value1
|
'value' => $value1
|
||||||
]
|
],
|
||||||
,[
|
[
|
||||||
'name' => '金额',
|
'name' => '金额',
|
||||||
'smooth' => 'true',
|
'smooth' => 'true',
|
||||||
'type' => 'line',
|
'type' => 'line',
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\common\logic;
|
namespace app\common\logic;
|
||||||
|
|
||||||
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\admin\logic\user_ship\UserShipLogic;
|
use app\admin\logic\user_ship\UserShipLogic;
|
||||||
use app\api\logic\order\OrderLogic;
|
use app\api\logic\order\OrderLogic;
|
||||||
use app\common\enum\OrderEnum;
|
use app\common\enum\OrderEnum;
|
||||||
@ -54,7 +55,6 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
Db::rollback();
|
Db::rollback();
|
||||||
Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile());
|
Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile());
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,22 +599,29 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
$branchProduct = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $v['store_id'])->find();
|
$branchProduct = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $v['store_id'])->find();
|
||||||
|
$storeProduct = StoreProduct::where('id', $v['product_id'])->find();
|
||||||
|
|
||||||
if ($branchProduct) {
|
if ($branchProduct) {
|
||||||
$stock = bcsub($branchProduct['stock'], $v['cart_num'], 2);
|
$stock = bcsub($branchProduct['stock'], $v['cart_num'], 2);
|
||||||
StoreBranchProduct::update([
|
StoreBranchProduct::update([
|
||||||
'stock' => $stock,
|
'stock' => $stock,
|
||||||
'total_price' => bcmul($stock, $branchProduct['purchase'], 2),
|
'total_price' => bcmul($stock, $branchProduct['purchase'], 2),
|
||||||
'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2)
|
'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2)
|
||||||
],['id'=>$branchProduct['id']]);
|
], ['id' => $branchProduct['id']]);
|
||||||
|
} else {
|
||||||
|
StoreProductLogic::ordinary(['id' => $v['product_id']], $v['store_id'], 0, $storeProduct);
|
||||||
|
StoreBranchProduct::update([
|
||||||
|
'stock' => -$v['cart_num'],
|
||||||
|
'sales' => $v['cart_num']
|
||||||
|
], ['product_id' => $v['product_id'],'store_id'=>$v['store_id']]);
|
||||||
}
|
}
|
||||||
$storeProduct = StoreProduct::where('id', $v['product_id'])->find();
|
|
||||||
if ($storeProduct) {
|
if ($storeProduct) {
|
||||||
$stock = bcsub($storeProduct['stock'], $v['cart_num'], 2);
|
$stock = bcsub($storeProduct['stock'], $v['cart_num'], 2);
|
||||||
StoreProduct::update([
|
StoreProduct::update([
|
||||||
'stock' => $stock,
|
'stock' => $stock,
|
||||||
'total_price' => bcmul($stock, $storeProduct['purchase'], 2),
|
'total_price' => bcmul($stock, $storeProduct['purchase'], 2),
|
||||||
'sales' => bcadd($storeProduct['sales'], $v['cart_num'], 2)
|
'sales' => bcadd($storeProduct['sales'], $v['cart_num'], 2)
|
||||||
],['id'=>$v['product_id']]);
|
], ['id' => $v['product_id']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@ -657,7 +664,7 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($order['uid']>0){
|
if ($order['uid'] > 0) {
|
||||||
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
|
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
|
||||||
if ($address) {
|
if ($address) {
|
||||||
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
|
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user