Merge pull request 'dev' (#123) from dev into main

Reviewed-on: #123
This commit is contained in:
mkm 2024-08-10 20:45:15 +08:00
commit a93547de10
5 changed files with 60 additions and 40 deletions

View File

@ -52,12 +52,13 @@ class StoreOrderController extends BaseAdminController
*/
public function add()
{
$params = (new StoreOrderValidate())->post()->goCheck('add');
$params = $this->request->post();
$result = StoreOrderLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
if (StoreOrderLogic::hasError()) {
return $this->fail(StoreOrderLogic::getError());
}else{
return $this->success('添加成功,请在30分钟内支付', [], 1, 1);
}
return $this->fail(StoreOrderLogic::getError());
}

View File

@ -7,6 +7,7 @@ use app\admin\controller\BaseAdminController;
use app\admin\lists\store_product\StoreProductLists;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\validate\store_product\StoreProductValidate;
use app\common\model\store_product\StoreProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use Webman\RedisQueue\Redis;
@ -101,26 +102,31 @@ class StoreProductController extends BaseAdminController
$store_arr = $this->request->post('store_arr');
$stock_type = $this->request->post('stock_type', 1);
$warehouse_id = $this->request->post('warehouse_id');
$count=count($store_arr);
$count = count($store_arr);
foreach ($product_arr as $key => $arr) {
$stock=bcmul($arr['stock'],$count);
$nums=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$arr['id'])->value('nums');
if($nums<$stock){
$stock = bcmul($arr['stock'], $count);
$nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
if ($nums < $stock) {
return $this->fail('商品库存不足');
}
}
if ($count == 1) {
$store_id = $store_arr[0];
foreach ($product_arr as $key => $arr) {
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
}
} else {
foreach ($product_arr as $key => $arr) {
foreach ($store_arr as $k => $store_id) {
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
}
}
}
return $this->success('已导入后台队列,请在门店入库记录中查看',[],1,1);
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
}
}

View File

@ -2,11 +2,14 @@
namespace app\admin\logic\store_order;
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_order_cart_info\StoreOrderCartInfo;
use app\common\model\user\User;
use think\facade\Db;
@ -28,15 +31,23 @@ class StoreOrderLogic extends BaseLogic
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
StoreOrder::create([]);
Db::commit();
$cartId = [];
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'];
$res = CartLogic::add($v);
$cartId[] = $res['id'];
}
$user = User::where('id', $params['user_id'])->find();
$params['shipping_type'] = 2;
$params['pay_type'] = 7;
$order = OrderLogic::createOrder($cartId, null, $user, $params);
if ($order != false) {
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
} else {
OrderLogic::getError();
return false;
}
}

View File

@ -547,8 +547,8 @@ class StoreProductLogic extends BaseLogic
if($warehouse['nums']< $product_arr['stock']){
$storage['status'] = -1;
$data['status'] = -1;
$storage['mark'] = '库存不足,分库存为:' .$warehouse['nums'];
$data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock'];
$storage['mark'] = '库存【'.$warehouse_id.'】不足,分库存为:' .$warehouse['nums'];
$data['mark'] = '库存【'.$warehouse_id.'】不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock'];
}
$res=WarehouseProductLogic::add($data);
$storage['outbound_id']=$res['id']??0;

View File

@ -25,9 +25,9 @@ class CartLogic extends BaseLogic
* @author likeadmin
* @date 2024/04/24 10:37
*/
public static function add(array $params): bool
public static function add(array $params)
{
if($params['store_id']<=0){
if ($params['store_id'] <= 0) {
self::setError('门店ID不能为空');
return false;
}
@ -38,35 +38,35 @@ class CartLogic extends BaseLogic
'uid' => $params['uid'],
'store_id' => $params['store_id'],
'product_id' => $params['product_id'],
'is_pay'=>0
'is_pay' => 0
])->field('id')->find();
if($check){
Cart::where('id',$check['id'])->inc('cart_num',$params['cart_num'])
if ($check) {
Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num'])
->update();
$cart['id'] = $check['id'];
}else{
} else {
$cart = Cart::create([
'uid' => $params['uid'],
'type' => $params['type']??'',
'type' => $params['type'] ?? '',
'product_id' => $params['product_id'],
'store_id' => $params['store_id']??0,
'staff_id' => $params['staff_id']??0,
'store_id' => $params['store_id'] ?? 0,
'staff_id' => $params['staff_id'] ?? 0,
'product_attr_unique' => '',
'cart_num' => $params['cart_num'],
'is_new' => $params['is_new']??0,
'is_new' => $params['is_new'] ?? 0,
]);
}
StoreProductLog::create([
'type'=>'cart',
'type' => 'cart',
'uid' => $params['uid'],
'cart_id' => $cart['id'],
'store_id' => $params['store_id']??0,
'store_id' => $params['store_id'] ?? 0,
'visit_num' => 1,
'product_id' => $params['product_id'],
'cart_num' => $params['cart_num'],
]);
Db::commit();
return true;
return $cart;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
@ -82,14 +82,16 @@ class CartLogic extends BaseLogic
* @author likeadmin
* @date 2024/04/24 10:37
*/
public static function edit(array $params,$type='inc'): bool
public static function edit(array $params, $type = 'inc'): bool
{
Db::startTrans();
try {
Cart::where(['uid'=>$params['uid'],
'store_id'=>$params['store_id'],
'product_id'=>$params['product_id']])
->update(['cart_num'=>$params['cart_num']]);
Cart::where([
'uid' => $params['uid'],
'store_id' => $params['store_id'],
'product_id' => $params['product_id']
])
->update(['cart_num' => $params['cart_num']]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -124,4 +126,4 @@ class CartLogic extends BaseLogic
{
return Cart::findOrEmpty($params['id'])->toArray();
}
}
}