|
@@ -8,7 +8,12 @@ use app\models\system\SystemStore;
|
|
|
use app\models\system\SystemStoreStock;
|
|
|
use app\models\system\SystemStoreStockBill;
|
|
|
use app\admin\model\store\{StoreCategory as CategoryModel, StoreProduct as ProductModel, StoreProductAttrValue};
|
|
|
-use crmeb\services\{FormBuilder, JsonService, JsonService as Json, UtilService as Util, FormBuilder as Form};
|
|
|
+use crmeb\services\{FormBuilder,
|
|
|
+ JsonService,
|
|
|
+ JsonService as Json,
|
|
|
+ UtilService as Util,
|
|
|
+ FormBuilder as Form
|
|
|
+};
|
|
|
use crmeb\traits\CurdControllerTrait;
|
|
|
use think\facade\Route as Url;
|
|
|
|
|
@@ -129,6 +134,7 @@ class Goods extends AuthController
|
|
|
if (!$this->adminInfo['store_id']) return app('json')->fail('门店铺货用通道');
|
|
|
if ($where['in_stock'] < 1) return app('json')->fail('补货数量不能少于1');
|
|
|
$info = SystemStoreStock::alias('a')->join("StoreProduct b", "a.product_id=b.id", "left")->where('a.bar_code', $where['bar_code'])->field('a.price,a.unique,a.in_stock,a.is_consumer,a.product_id,b.store_name,b.image,a.bar_code')->find();
|
|
|
+ if (!$info && $where['info'] != 1) return app('json')->fail('门店尚无库存无法减少');
|
|
|
if (!$info) {
|
|
|
$store_product = StoreProductAttrValue::where('type', 0)->where('bar_code', $where['bar_code'])->find();
|
|
|
if (!$store_product)
|
|
@@ -202,7 +208,6 @@ class Goods extends AuthController
|
|
|
|
|
|
$this->assign('product_id', $product_id);
|
|
|
$this->assign('store_id', $store_id);
|
|
|
-
|
|
|
$this->assign('count', SystemStoreStockBill::where(compact('product_id', 'store_id'))->value('count(id)') ?: 0);
|
|
|
return $this->fetch();
|
|
|
}
|
|
@@ -251,15 +256,23 @@ class Goods extends AuthController
|
|
|
['refuse_msg', ''],
|
|
|
['status', 1],
|
|
|
]);
|
|
|
- if (!SystemStoreStockBill::be(['id' => $id, 'status' => 0])) return $this->failed('数据不存在或已经审核');
|
|
|
- $where['audit_time'] = time();
|
|
|
- $where['audit_admin'] = $this->adminId;
|
|
|
- SystemStoreStockBill::edit($where, $id);
|
|
|
+ $rs = true;
|
|
|
if ($where['status'] == 1) {
|
|
|
+ if (!SystemStoreStockBill::be(['id' => $id, 'status' => 0])) Json::fail('数据不存在或已经审核');
|
|
|
$info = SystemStoreStockBill::find($id)->toArray();
|
|
|
+ $stock_info = SystemStoreStock::where(['store_id' => $info['store_id'], 'product_id' => $info['product_id'], 'bar_code' => $info['bar_code']])->find();
|
|
|
+ if (!$stock_info && $info['type'] == 2) Json::fail('库存无法减少');
|
|
|
+ if ($info['type'] == 2 && $info['in_stock'] > $stock_info['in_stock']) Json::fail('库存不足');
|
|
|
$rs = SystemStoreStock::replenish($info['store_id'], $info);
|
|
|
}
|
|
|
- return Json::successful('审核成功');
|
|
|
+ if ($rs) {
|
|
|
+ $where['audit_time'] = time();
|
|
|
+ $where['audit_admin'] = $this->adminId;
|
|
|
+ SystemStoreStockBill::edit($where, $id);
|
|
|
+ Json::successful('审核成功');
|
|
|
+ } else {
|
|
|
+ Json::fail(SystemStoreStock::getErrorInfo());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -272,18 +285,40 @@ class Goods extends AuthController
|
|
|
['status', 1],
|
|
|
]);
|
|
|
$ids = explode(',', input('id'));
|
|
|
+ $msg = [];
|
|
|
if ($where['status'] == 1) {
|
|
|
- foreach ($ids as $v) {
|
|
|
+ foreach ($ids as $k => $v) {
|
|
|
$info = SystemStoreStockBill::where('id', $v)->where('status', 0)->find();
|
|
|
+ if (!$info) {
|
|
|
+ unset($ids[$k]);
|
|
|
+ $msg[] = $v . ':数据不存在或已经审核';
|
|
|
+ }
|
|
|
+ $stock_info = SystemStoreStock::where(['store_id' => $info['store_id'], 'product_id' => $info['product_id'], 'bar_code' => $info['bar_code']])->find();
|
|
|
+ if (!$stock_info && $info['type'] == 2) {
|
|
|
+ unset($ids[$k]);
|
|
|
+ $msg[] = $v . ':库存无法减少';
|
|
|
+ }
|
|
|
+ if ($info['type'] == 2 && $info['in_stock'] > $stock_info['in_stock']) {
|
|
|
+ unset($ids[$k]);
|
|
|
+ $msg[] = $v . ':库存不足';
|
|
|
+ }
|
|
|
if ($info) {
|
|
|
$rs = SystemStoreStock::replenish($info['store_id'], $info);
|
|
|
+ if (!$rs) {
|
|
|
+ unset($ids[$k]);
|
|
|
+ $msg[] = $v . ':' . SystemStoreStock::getErrorInfo();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$where['audit_time'] = time();
|
|
|
$where['audit_admin'] = $this->adminId;
|
|
|
SystemStoreStockBill::where('id', 'in', join(",", $ids))->update($where);
|
|
|
- return Json::successful('批量审核成功');
|
|
|
+ if (!count($msg)) {
|
|
|
+ return Json::successful('批量审核成功');
|
|
|
+ } else {
|
|
|
+ return Json::successful('批量审核部分成功' . implode(',', $msg));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|