|
@@ -16,6 +16,7 @@ use app\common\model\ApproveUseGoods;
|
|
|
use app\common\model\GoodsStock;
|
|
|
use app\common\model\GoodsStockLog;
|
|
|
use app\common\model\User;
|
|
|
+use think\cache\driver\Redis;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
|
|
@@ -448,10 +449,10 @@ class ApproveService
|
|
|
}
|
|
|
// TODO 没有判断反馈状态
|
|
|
|
|
|
- // 更新维修信息
|
|
|
- $params['maintain_user_id'] = $info->maintain_user_id;
|
|
|
- $params['feedback_status'] = CommonConstant::IS_WHO_1;
|
|
|
try {
|
|
|
+ // 更新维修信息
|
|
|
+ $params['maintain_user_id'] = $info->maintain_user_id;
|
|
|
+ $params['feedback_status'] = CommonConstant::IS_WHO_1;
|
|
|
ApproveMaintain::where('info_id', $info->id)->update($params);
|
|
|
} catch (Exception $e) {
|
|
|
except('出现错误:' . $e->getMessage());
|
|
@@ -477,36 +478,58 @@ class ApproveService
|
|
|
$approve_time = date('Y-m-d H:i:s');
|
|
|
$duration = time() - strtotime($approve['approve_time']);
|
|
|
|
|
|
- if ($status == CommonConstant::STATUS_3) {
|
|
|
- if ($info->module == CommonConstant::MODULE_3) {
|
|
|
- // 3=入库申请
|
|
|
- $goods = $info->stock_goods;
|
|
|
- if (!$goods->toArray()) {
|
|
|
- except('入库商品不存在');
|
|
|
- }
|
|
|
- }
|
|
|
- if ($info->module == CommonConstant::MODULE_8) {
|
|
|
- // 8=维修申请
|
|
|
- $is_maintain = CommonService::isMaintain($user);
|
|
|
- if ($is_maintain && !$maintain_user_id) {
|
|
|
- except('请选择维修人员');
|
|
|
- }
|
|
|
- // 维修人员ID
|
|
|
- if ($maintain_user_id > 0) {
|
|
|
- $info->maintain_user_id = $maintain_user_id;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ $goodsStockSave = [];
|
|
|
+ $goodsStockLog = [];
|
|
|
if ($info->module == CommonConstant::MODULE_4) {
|
|
|
// 4=领用申请
|
|
|
$goods = $info->use_goods;
|
|
|
if (!$goods->toArray()) {
|
|
|
except('领用商品不存在');
|
|
|
}
|
|
|
+ if ($status == CommonConstant::STATUS_3) {
|
|
|
+ if ($approve['approve_flow'] < $info['approve_num']) {
|
|
|
+ } else {
|
|
|
+ list($goodsStockSave,$goodsStockLog,$redisStock) = ApproveInfoService::composition_data($goods->toArray(),CommonConstant::MODULE_4,CommonConstant::STATUS_3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($status == CommonConstant::STATUS_4) {
|
|
|
+ list($goodsStockSave,$goodsStockLog,$redisStock) = ApproveInfoService::composition_data($goods->toArray(),CommonConstant::MODULE_4,CommonConstant::STATUS_4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($info->module == CommonConstant::MODULE_3 && $status == CommonConstant::STATUS_3) {
|
|
|
+ // 3=入库申请
|
|
|
+ $goods = $info->stock_goods;
|
|
|
+ if (!$goods->toArray()) {
|
|
|
+ except('入库商品不存在');
|
|
|
+ }
|
|
|
+ if ($approve['approve_flow'] < $info['approve_num']) {
|
|
|
+ } else{
|
|
|
+ list($goodsStockSave,$goodsStockLog,$redisStock) = ApproveInfoService::composition_data($goods->toArray(),CommonConstant::MODULE_3,CommonConstant::STATUS_3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($info->module == CommonConstant::MODULE_8 && $status == CommonConstant::STATUS_3) {
|
|
|
+ // 8=维修申请
|
|
|
+ $is_maintain = CommonService::isMaintain($user);
|
|
|
+ if ($is_maintain && !$maintain_user_id) {
|
|
|
+ except('请选择维修人员');
|
|
|
+ }
|
|
|
+ // 维修人员ID
|
|
|
+ if ($maintain_user_id > 0) {
|
|
|
+ $info->maintain_user_id = $maintain_user_id;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
+ if ($goodsStockSave) {
|
|
|
+ // 批量更新商品库存
|
|
|
+ (new GoodsStock)->saveAll($goodsStockSave);
|
|
|
+ }
|
|
|
+ if ($goodsStockLog) {
|
|
|
+ // 批量添加商品入库出库记录
|
|
|
+ GoodsStockLog::insertAll($goodsStockLog);
|
|
|
+ }
|
|
|
+
|
|
|
// 更新审批申请
|
|
|
if ($status == CommonConstant::STATUS_3) {
|
|
|
// 审批流程批次小于审批次数 更新下一级审批状态
|
|
@@ -515,35 +538,6 @@ class ApproveService
|
|
|
} else {
|
|
|
// 审批通过
|
|
|
$info->status = $status;
|
|
|
- if ($info->module == CommonConstant::MODULE_3) {
|
|
|
- // 入库商品列表
|
|
|
- $goodsStockSave = [];
|
|
|
- $goodsStockLog = [];
|
|
|
- foreach ($goods as $key => $val) {
|
|
|
- foreach ($val['goods_stock_text'] as $k => $v) {
|
|
|
- $goodsStockSave[] = [
|
|
|
- 'id' => $v['id'],
|
|
|
- 'stock' => ['inc', $v['stock']],
|
|
|
- ];
|
|
|
- $goodsStockLog[] = [
|
|
|
- 'info_id' => $val['info_id'],
|
|
|
- 'goods_id' => $v['goods_id'],
|
|
|
- 'stock_id' => $v['id'],
|
|
|
- 'name' => $v['name'],
|
|
|
- 'price' => $v['price'],
|
|
|
- 'stock' => $v['stock'],
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- if ($goodsStockSave) {
|
|
|
- // 批量更新商品库存
|
|
|
- (new GoodsStock)->saveAll($goodsStockSave);
|
|
|
- }
|
|
|
- if ($goodsStockLog) {
|
|
|
- // 批量添加商品入库记录
|
|
|
- GoodsStockLog::insertAll($goodsStockLog);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
if ($status == CommonConstant::STATUS_4) {
|
|
@@ -564,9 +558,22 @@ class ApproveService
|
|
|
} catch (Exception $e) {
|
|
|
except('出现错误:' . $e->getMessage(), 2, $e);
|
|
|
}
|
|
|
+
|
|
|
+ // 4=领用申请 扣除冻结库存
|
|
|
+ if ($module == CommonConstant::MODULE_4) {
|
|
|
+ if($redisStock){
|
|
|
+ // 库存缓存记录
|
|
|
+ $redis = new Redis(config('redis.'));
|
|
|
+ foreach ($redisStock as $key=>$val){
|
|
|
+ $redis->dec($val['id'], $val['stock']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 修改
|
|
|
*
|