commit
45f0ea5fe8
@ -101,5 +101,83 @@ class StoreProductController extends BaseAdminController
|
||||
public function import()
|
||||
{
|
||||
return $this->fail('接口已关闭');
|
||||
$product_arr = $this->request->post('product_arr');
|
||||
$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);
|
||||
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) {
|
||||
return $this->fail('商品库存不足');
|
||||
}
|
||||
}
|
||||
if ($count == 1) {
|
||||
$store_id = $store_arr[0];
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
if ($arr['stock'] == 0) {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
} else {
|
||||
WarehouseProductLogic::add($data);
|
||||
$find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find();
|
||||
if ($find) {
|
||||
StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update();
|
||||
} else {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
if ($arr['stock'] == 0) {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
} else {
|
||||
WarehouseProductLogic::add($data);
|
||||
$find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find();
|
||||
if ($find) {
|
||||
StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update();
|
||||
} else {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
|
||||
}
|
||||
}
|
||||
|
||||
// $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);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use app\common\service\xlsx\OrderDetail;
|
||||
use app\common\service\xlsx\WarehouseOrdeRentry;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
@ -108,59 +109,32 @@ class WarehouseOrderController extends BaseAdminController
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $find['purchase'], 2);
|
||||
$data['purchase'] = $find['purchase'];
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
WarehouseProductLogic::add($data);
|
||||
$find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find();
|
||||
if ($find) {
|
||||
StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update();
|
||||
} else {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
|
||||
$ordinary=StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
|
||||
if(empty($ordinary)){
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
StoreBranchProduct::where('id', $ordinary['id'])->inc('stock', $arr['stock'])->update();
|
||||
}
|
||||
$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']]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $this->fail('暂不支持多门店入库');
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
foreach ($store_arr as $k => $store_id) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
if ($arr['stock'] == 0) {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
} else {
|
||||
WarehouseProductLogic::add($data);
|
||||
$find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find();
|
||||
if ($find) {
|
||||
StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update();
|
||||
} else {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
|
@ -33,7 +33,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['warehouse_id', 'financial_pm', 'store_id','oid'],
|
||||
'=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ class StoreProductLogic extends BaseLogic
|
||||
|
||||
|
||||
/**普通 */
|
||||
public static function ordinary($product_arr, $store_id, $admin_id, $find, $warehouse_id)
|
||||
public static function ordinary($product_arr, $store_id, $admin_id, $find)
|
||||
{
|
||||
$store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray();
|
||||
if ($find && !$store_find) {
|
||||
@ -439,32 +439,14 @@ class StoreProductLogic extends BaseLogic
|
||||
'bar_code' => $attr_value['bar_code']
|
||||
];
|
||||
StoreBranchProductAttrValue::create($arr);
|
||||
// if ($product_arr['stock'] > 0) {
|
||||
// self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
|
||||
// }
|
||||
Db::commit();
|
||||
return true;
|
||||
return $branch;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// //更新门店库存
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// // if ($product_arr['stock'] > 0) {
|
||||
// // self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
|
||||
// // }
|
||||
// Db::commit();
|
||||
// return true;
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**兑换 */
|
||||
|
@ -116,7 +116,7 @@ class CapitalFlowLogic extends BaseLogic
|
||||
$model->mark = empty($mark) ? $model->title : $mark;
|
||||
$model->save();
|
||||
//这里有bug 要修改
|
||||
$this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||
// $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||
return $model->id;
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ class CapitalFlowLogic extends BaseLogic
|
||||
$model->mark = empty($mark) ? $model->title : $mark;
|
||||
$model->save();
|
||||
//这里有bug 要修改
|
||||
$this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||
// $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||
return $model->id;
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ class DemoPayNotifyLogic extends BaseLogic
|
||||
//微信日志 user_order_refund
|
||||
$capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1);
|
||||
//处理财务流水退还
|
||||
(new StoreFinanceFlowLogic())->store_finance_back($orderSn);
|
||||
(new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']);
|
||||
self::addStock($order['id']); //微信
|
||||
return true;
|
||||
// self::afterPay($order,$extra['transaction_id']);
|
||||
|
@ -324,7 +324,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]);
|
||||
|
||||
//处理财务流水退还
|
||||
(new StoreFinanceFlowLogic())->store_finance_back($orderSn);
|
||||
(new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']);
|
||||
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
|
||||
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
|
||||
$user = User::where('id', $order['uid'])->findOrEmpty();
|
||||
@ -393,6 +393,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
//增加数量
|
||||
self::addStock($order['id']);
|
||||
StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]);
|
||||
(new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -176,39 +176,44 @@ class StoreFinanceFlowLogic extends BaseLogic
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function store_finance_back($orderSn)
|
||||
public function store_finance_back($orderSn, $store_id)
|
||||
{
|
||||
$list=StoreFinanceFlow::where('order_sn', $orderSn)
|
||||
$list = StoreFinanceFlow::where('order_sn', $orderSn)
|
||||
->where(['financial_pm' => 1, 'status' => 1])
|
||||
->select();
|
||||
foreach ($list as $k => $value) {
|
||||
//用户
|
||||
switch ($value['type']) {
|
||||
case 0:
|
||||
if ($value['financial_type'] == 12&& $value['other_uid']>0) {
|
||||
if ($value['financial_type'] == 12 && $value['other_uid'] > 0) {
|
||||
$user = User::where('id', $value['other_uid'])->findOrEmpty();
|
||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||
$user->now_money = bcsub($user['now_money'],$value['number'], 2);
|
||||
$user->now_money = bcsub($user['now_money'], $value['number'], 2);
|
||||
$user->save();
|
||||
// Log::error('aa'.$a);
|
||||
// Log::error('aa'.$user['now_money']);
|
||||
// Log::error('aa'.$value['number']);
|
||||
$capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'],'',$value['pay_type']);
|
||||
$capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']);
|
||||
}
|
||||
break;
|
||||
//商户
|
||||
case 1:
|
||||
$store = SystemStore::where('id', $store_id)->find();
|
||||
$capitalFlowDao = new CapitalFlowLogic($store, 'store');
|
||||
if ($value['number'] > 0 && $value['financial_type'] == 2) {
|
||||
SystemStore::where('id', $value['store_id'])->dec('store_money', $value['number'])->update();
|
||||
$capitalFlowDao->storeExpense('store_paid_deposit_dec', 'order', $value['order_id'],$value['number']);
|
||||
|
||||
}
|
||||
if ($value['number'] > 0 && $value['financial_type'] == 16) {
|
||||
SystemStore::where('id', $value['store_id'])->dec('attrition', $value['number'])->update();
|
||||
$capitalFlowDao->storeExpense('store_attrition_dec', 'order', $value['order_id'], $value['number']);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status',1)->find();
|
||||
$find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status', 1)->find();
|
||||
if ($find && $find['number'] > 0) {
|
||||
SystemStore::where('id', $find['store_id'])->dec('paid_deposit', $find['number'])->update();
|
||||
}
|
||||
@ -220,7 +225,7 @@ class StoreFinanceFlowLogic extends BaseLogic
|
||||
// $value['financial_type'] = OrderEnum::PAY_BACK;
|
||||
// $value['create_time'] = time();
|
||||
// }
|
||||
StoreFinanceFlow::where('order_sn', $orderSn)->update(['status'=>-1]);
|
||||
StoreFinanceFlow::where('order_sn', $orderSn)->update(['status' => -1]);
|
||||
// (new StoreFinanceFlow)->saveAll($data);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user