feat: 优化了商品库存和订单处理的逻辑

This commit is contained in:
mkm 2024-08-25 16:26:52 +08:00
parent 9fca148539
commit 807b4cacd6
3 changed files with 30 additions and 111 deletions

View File

@ -30,9 +30,7 @@ class StoreBranchProductLogic extends BaseLogic
{
Db::startTrans();
try {
StoreBranchProduct::create([
]);
StoreBranchProduct::create([]);
Db::commit();
return true;
@ -86,21 +84,20 @@ class StoreBranchProductLogic extends BaseLogic
{
Db::startTrans();
try {
$find = StoreProduct::where('id', $params['product_id'])->find();
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find();
if ($type == 1) {
StoreBranchProduct::where('id', $params['id'])->inc('stock',$params['nums'])->update();
$find=StoreProduct::where('id', $params['product_id'])->find();
if($find){
$stock = bcadd($find['stock'], $params['nums'], 2);
$branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2);
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $stock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]);
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]);
}
} else {
StoreBranchProduct::where('id', $params['id'])->dec('stock',$params['nums'])->update();
$find=StoreProduct::where('id', $params['product_id'])->find();
if($find){
$branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2);
$stock = bcsub($find['stock'], $params['nums'], 2);
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $stock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]);
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]);
}
}
Db::commit();
return true;
} catch (\Throwable $e) {

View File

@ -48,7 +48,7 @@ class StoreOrderLogic extends BaseLogic
$cartId[] = $res['id'];
}
$user = User::where('id', $params['user_id'])->find();
$params['shipping_type']=4;
$params['shipping_type']=2;
$params['pay_type'] = 7;
$order = OrderLogic::createOrder($cartId, null, $user, $params);
if (OrderLogic::hasError()) {

View File

@ -2,6 +2,7 @@
namespace app\api\controller;
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
use app\common\logic\StoreFinanceFlowLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\validate\tools\GenerateTableValidate;
@ -13,8 +14,10 @@ use app\common\model\Config as ModelConfig;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\service\pay\PayService;
use app\common\service\PushService;
use app\common\service\wechat\WechatTemplate;
@ -42,87 +45,6 @@ class IndexController extends BaseApiController
public function index()
{
return json([1]);
$financeFlow = new StoreFinanceFlow();
$order_id = 544;
$store_id = 3;
$staff_id = 3;
Db::startTrans();
try {
// $res = $financeFlow->where('order_id', $order_id)->update(['store_id' => $store_id, 'staff_id' => $staff_id]);
// if ($res) {
// $order['store_id'] =$store_id;
// }
$financeFlowLogic = new StoreFinanceFlowLogic();
//other_uid大于0的
$select_1 = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'status' => 0])->where('other_uid', '>', 0)->select();
foreach ($select_1 as $k => $v) {
if ($v['other_uid'] > 0) {
$financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']);
}
}
$deposit = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 0, 'financial_type' => 11, 'status' => 0])->value('number') ?? 0;
$money = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 2, 'status' => 0])->value('number') ?? 0;
$financeFlowLogic->updateStatusStore($order_id, $store_id, $money, $deposit);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
d($e);
return false;
}
$all_where['paid'] = 1;
d(OrderLogic::dayPayPrice($all_where, date('Y-m-d', time())));
$uid = 9;
$a = PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '支付超时,订单已被取消,请重新提交订单', 'data' => ['id' => 5]]);
return json($a);
try {
$a = new WechatTemplate();
$a->NewQuotationNotification(['openid' => 'ocqhF6UfFQXE-SbzbP5YVQJlQAh0', 'data1' => '阿萨', 'data2' => date('Y-m-d H:i:s'), 'data3' => '占山', 'data3' => 18982406440]);
} catch (Exception $e) {
d($e);
}
d(22);
$auth_code = $this->request->get('code');
$pay = (new PayService());
$order = [
'description' => '条码商品',
'out_trade_no' => (string)time(),
'payer' => [
'auth_code' => (string)$auth_code
],
'amount' => [
'total' => 1,
],
'scene_info' => [
"store_info" => [
'id' => '1'
]
],
];
try {
$a = $pay->wechat->pos($order);
} catch (\Exception $th) {
d($th);
}
d($a);
$params = ['store_id' => 2, 'pay_type' => 17];
$a = StoreOrderLogic::createOrder([1], 0, null, $params);
d($a);
return json(['msg' => create_password(123456, '11d3')]);
}
/**