|
@@ -33,12 +33,18 @@ class ApproveInfoService
|
|
|
public static function create($id, $module, $params, $user)
|
|
|
{
|
|
|
$userid = $user['userid'];
|
|
|
- $apply_user_id = $params['apply_user_id'] ? $params['apply_user_id']: '';
|
|
|
-
|
|
|
- // 发起人信息
|
|
|
- $apply_user = User::field('userid,department')->where('userid',$apply_user_id)->find();
|
|
|
- if(!$apply_user){
|
|
|
- except('发起人信息不存在或已删除');
|
|
|
+ $department = $user['department'];
|
|
|
+ $apply_user_id = $params['apply_user_id'];
|
|
|
+
|
|
|
+ // 申请人信息
|
|
|
+ if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
|
|
|
+ $apply_user = User::field('department')
|
|
|
+ ->where('userid', $apply_user_id)
|
|
|
+ ->find();
|
|
|
+ if (!$apply_user) {
|
|
|
+ except('申请人信息不存在或已删除');
|
|
|
+ }
|
|
|
+ $department = $apply_user['department'];
|
|
|
}
|
|
|
|
|
|
// 编辑
|
|
@@ -69,7 +75,7 @@ class ApproveInfoService
|
|
|
'module' => $module,
|
|
|
'user_id' => $userid,
|
|
|
'apply_user_id' => $apply_user_id,
|
|
|
- 'department' => $apply_user['department'],
|
|
|
+ 'department' => $department,
|
|
|
'status' => CommonConstant::STATUS_2,
|
|
|
'approve_num' => $approve_num,
|
|
|
'cur_num' => 0,
|
|
@@ -326,7 +332,7 @@ class ApproveInfoService
|
|
|
$goods_name = '';
|
|
|
$goods_stock_name = '';
|
|
|
$apply_goods_data = [];
|
|
|
- foreach ($goods_ids as $key=>$value) {
|
|
|
+ foreach ($goods_ids as $key => $value) {
|
|
|
if (array_key_exists($value['id'], $goods_object)) {
|
|
|
// 商品库里有该商品
|
|
|
$goods_info = $goods_object[$value['id']];
|
|
@@ -361,7 +367,7 @@ class ApproveInfoService
|
|
|
'total_price' => $total_price,
|
|
|
'goods_stock' => json_encode($goods_stock_data, JSON_UNESCAPED_UNICODE),
|
|
|
];
|
|
|
- $total_amount = bcadd($total_amount,$total_price,2);
|
|
|
+ $total_amount = bcadd($total_amount, $total_price, 2);
|
|
|
} else {
|
|
|
// 商品库里没有该商品
|
|
|
$goods_name .= $value['goods_name'] . '、';
|
|
@@ -430,7 +436,7 @@ class ApproveInfoService
|
|
|
$goods_data['total_price'] = $total_price;
|
|
|
$goods_data['goods_stock'] = json_encode($goods_stock_data, JSON_UNESCAPED_UNICODE);
|
|
|
$apply_goods_data[] = $goods_data;
|
|
|
- $total_amount = bcadd($total_amount,$total_price,2);
|
|
|
+ $total_amount = bcadd($total_amount, $total_price, 2);
|
|
|
}
|
|
|
$model::insertAll($apply_goods_data);
|
|
|
}
|
|
@@ -546,9 +552,15 @@ class ApproveInfoService
|
|
|
}
|
|
|
|
|
|
$userid = $user['userid'];
|
|
|
- $list = ApproveInfo::field('module_id,user_id,department,is_deleted', true)
|
|
|
+ $list = ApproveInfo::field('module_id,user_id,apply_user_id,department,is_deleted', true)
|
|
|
->where('module', $module)
|
|
|
- ->where('user_id', $userid)
|
|
|
+ ->where(function ($query) use ($module, $userid) {
|
|
|
+ if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
|
|
|
+ $query->where('user_id', $userid)->whereOr('apply_user_id', $userid);
|
|
|
+ } else {
|
|
|
+ $query->where('user_id', $userid);
|
|
|
+ }
|
|
|
+ })
|
|
|
->where('status', $status)
|
|
|
->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
->when($search, function ($query) use ($search) {
|
|
@@ -573,6 +585,9 @@ class ApproveInfoService
|
|
|
$where = $user ? ['user_id' => $user['userid']] : [];
|
|
|
$info = ApproveInfo::field('is_deleted', true)
|
|
|
->where($where)
|
|
|
+ ->where(function ($query) use ($user) {
|
|
|
+ $query->where('user_id', $user['userid'])->whereOr('apply_user_id', $user['userid']);
|
|
|
+ })
|
|
|
->where('is_deleted', CommonConstant::IS_DELETED_0);
|
|
|
if ($type == 'detail') {
|
|
|
$info->with([
|
|
@@ -699,7 +714,7 @@ class ApproveInfoService
|
|
|
},
|
|
|
]);
|
|
|
}
|
|
|
- break;
|
|
|
+ break;
|
|
|
case CommonConstant::MODULE_4:
|
|
|
// 领用商品列表
|
|
|
if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
|
|
@@ -715,7 +730,7 @@ class ApproveInfoService
|
|
|
]);
|
|
|
}
|
|
|
]);
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
|
|
|
}
|
|
|
break;
|
|
@@ -780,14 +795,14 @@ class ApproveInfoService
|
|
|
switch ($module) {
|
|
|
case CommonConstant::MODULE_1:
|
|
|
if ($type == 'detail') {
|
|
|
- $info['apply_goods'] = $info->applyGoods()->field('id,info_id,goods_name,total_amount,goods_data')->select();
|
|
|
+ $info['apply_goods'] = $info->applyGoods()->field('id,info_id,goods_name,total_price,goods_stock')->select();
|
|
|
} else {
|
|
|
$info->apply_goods;
|
|
|
}
|
|
|
break;
|
|
|
case CommonConstant::MODULE_3:
|
|
|
if ($type == 'detail') {
|
|
|
- $info['stock_goods'] = $info->stockGoods()->field('id,info_id,goods_name,goods_data')->select();
|
|
|
+ $info['stock_goods'] = $info->stockGoods()->field('id,info_id,goods_name,total_price,goods_stock')->select();
|
|
|
} else {
|
|
|
$info->stock_goods;
|
|
|
}
|