feat: 修改订单和仓库逻辑,优化库存和支付处理
This commit is contained in:
parent
375d915045
commit
cf1d6db00a
@ -56,11 +56,12 @@ class StoreOrderController extends BaseAdminController
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = StoreOrderLogic::add($params);
|
||||
if (StoreOrderLogic::hasError()) {
|
||||
return $this->fail(StoreOrderLogic::getError());
|
||||
} else {
|
||||
return $this->success('添加成功,请在30分钟内支付', [], 1, 1);
|
||||
return $this->success('添加成功,该订单不会因为系统时间而删除', [], 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,14 +2,20 @@
|
||||
|
||||
namespace app\admin\logic\store_order;
|
||||
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\api\logic\order\CartLogic;
|
||||
use app\api\logic\order\OrderLogic;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -35,20 +41,56 @@ class StoreOrderLogic extends BaseLogic
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$v['uid'] = $params['user_id'];
|
||||
$v['store_id'] = $params['store_id'];
|
||||
$v['product_id'] = $v['id'];
|
||||
$v['cart_num'] = $v['stock'];
|
||||
StoreBranchProduct::where('id',$v['id'])->update(['price'=>$v['price'],'vip_price'=>$v['price'],'cost'=>$v['price'],'purchase'=>$v['purchase']]);
|
||||
unset($v['id']);
|
||||
$res = CartLogic::add($v);
|
||||
$cartId[] = $res['id'];
|
||||
}
|
||||
$user = User::where('id', $params['user_id'])->find();
|
||||
$params['shipping_type'] = 2;
|
||||
$params['shipping_type']=4;
|
||||
$params['pay_type'] = 7;
|
||||
$order = OrderLogic::createOrder($cartId, null, $user, $params);
|
||||
if ($order != false) {
|
||||
return true;
|
||||
} else {
|
||||
OrderLogic::getError();
|
||||
if (OrderLogic::hasError()) {
|
||||
StoreOrderLogic::setError(OrderLogic::getError());
|
||||
return false;
|
||||
} else {
|
||||
$arr = [
|
||||
'warehouse_id' => 1,
|
||||
'store_id' => $params['store_id'],
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
'admin_id' => $params['admin_id'],
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$arr['delivery_time'] = time();
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data = [
|
||||
'warehouse_id' => 1,
|
||||
'product_id' => $v['product_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $params['admin_id'],
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $params['store_id'], $params['admin_id'], $storeProduct);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
WarehouseProductLogic::add($data);
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ class Task
|
||||
new Crontab('0 */10 * * * *', function () {
|
||||
$where = ['paid' => 0];
|
||||
$where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单
|
||||
// 删除10分钟未支付的订单
|
||||
$where[] = ['shipping_type', '<>',4];
|
||||
// 删除10分钟未支付的订单
|
||||
$oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除
|
||||
if ($oid) {
|
||||
StoreOrder::where('id', 'in', $oid)->update(['delete_time' => time()]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user