|
@@ -203,7 +203,7 @@ class OrderOutChild extends Base
|
|
|
|
|
|
if (empty($info)) return json_show(1004, '该发货单不存在或状态有误');
|
|
|
if ($info['wsend_num'] < $info['send_num']) return json_show(1004, "订单待发货数量不足");
|
|
|
- if ($info['wsend_num'] < array_sum($param['list'], 'num')) return json_show(1004, "仓库总发货数与发货单待发货数不同");
|
|
|
+ if ($info['wsend_num'] < array_sum(array_column($param['list'], 'num'))) return json_show(1004, "仓库总发货数与发货单待发货数不同");
|
|
|
|
|
|
//所有仓库信息
|
|
|
$wsm = Db::name('good_stock')
|
|
@@ -294,6 +294,8 @@ class OrderOutChild extends Base
|
|
|
public function send()
|
|
|
{
|
|
|
|
|
|
+ if ($this->level != 1) return json_show(0, '管理员不能操作');
|
|
|
+
|
|
|
$param = $this->request->post('list/a', '', 'trim');
|
|
|
|
|
|
$temp = Db::name('order_out_child')
|
|
@@ -305,7 +307,7 @@ class OrderOutChild extends Base
|
|
|
|
|
|
$child = Db::name('order_out_child')
|
|
|
->where(['is_del' => 0, 'status' => 1, 'outChildCode' => array_column($param, 'outChildCode')])
|
|
|
- ->column('id,orderCode,outCode,num', 'outChildCode');
|
|
|
+ ->column('id,orderCode,outCode,num,wsm_code,supplierNo', 'outChildCode');
|
|
|
|
|
|
//检查所有的发货单是否有正在进行的售后单
|
|
|
$temp = Db::name('order_return')
|
|
@@ -321,7 +323,22 @@ class OrderOutChild extends Base
|
|
|
|
|
|
$sale = Db::name('sale')
|
|
|
->where(['is_del' => 0, 'orderCode' => array_unique(array_column($child, 'orderCode'))])
|
|
|
- ->column('id,good_num,send_num,wsend_num,good_code', 'orderCode');
|
|
|
+ ->column('id,good_num,send_num,wsend_num,good_code,supNo,is_stock,order_source', 'orderCode');
|
|
|
+
|
|
|
+ $is_reurn = Db::name("sale_return")
|
|
|
+ ->field('id,orderCode')
|
|
|
+ ->where(['orderCode' => array_column($child, 'orderCode'), 'is_del' => 0])
|
|
|
+ ->where("status", "in", [1, 2, 3, 7, 9, 10])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if (!empty($is_reurn)) return json_show(1004, $is_reurn['orderCode'] . "存在退货未处理完成");
|
|
|
+
|
|
|
+
|
|
|
+ //判断供应商是否开通账号,若开通的话,则只能由供应商账号操作
|
|
|
+ if ($this->level != 3) {
|
|
|
+ $temp = checkHasAccountBySupplierNos(array_column($sale, 'supNo'));
|
|
|
+ if (!empty($temp)) return json_show(1004, implode(',', array_keys($temp)) . '这些供应商已经开通账号,请使用供应商账号操作');
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
$val = Validate::rule([
|
|
|
'outChildCode|发货工单号' => 'require|max:255',
|
|
@@ -335,10 +352,32 @@ class OrderOutChild extends Base
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
+ //所有供应商负责人
|
|
|
+ $userCommon = new \app\admin\common\User();
|
|
|
+ $person_temp = $userCommon->handle('sGetList', ['more_code' => array_unique(array_column($child, 'supplierNo'))]);
|
|
|
+ $person = array_column($person_temp['data']['list'], 'personid', 'code');
|
|
|
+ unset($userCommon);
|
|
|
+ unset($person_temp);
|
|
|
+
|
|
|
+ //所有仓库管理员
|
|
|
+ $wsm_contactor = Db::name('warehouse_info')
|
|
|
+ ->where(['is_del' => 0, 'wsm_code' => array_unique(array_column($child, 'wsm_code'))])
|
|
|
+ ->column('contactor', 'wsm_code');
|
|
|
+
|
|
|
+ $yz_tmp = [];
|
|
|
+
|
|
|
foreach ($param as $value) {
|
|
|
|
|
|
if ($val->check($value) == false) throw new Exception($val->getError());
|
|
|
|
|
|
+ //如果是库存品,只能由库管操作
|
|
|
+ //非库存品和采返商品只能由供应商负责人操作
|
|
|
+ if ($sale[$child[$value['outChildCode']]['orderCode']]['is_stock'] == 1) {
|
|
|
+ if ($this->uid != $wsm_contactor[$child[$value['outChildCode']]['wsm_code']]) throw new Exception('库存品只能由仓库管理员操作');
|
|
|
+ } else {
|
|
|
+ if ($this->uid != $person[$child[$value['outChildCode']]['supplierNo']]) throw new Exception('非库存品和采返商品只能由供应商负责人操作');
|
|
|
+ }
|
|
|
+
|
|
|
//工单
|
|
|
if (!isset($child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '工单不存在或状态不允许发货');
|
|
|
|
|
@@ -365,14 +404,24 @@ class OrderOutChild extends Base
|
|
|
$sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'] -= $child[$value['outChildCode']]['num'];
|
|
|
|
|
|
//销售单
|
|
|
+ $send_status = $sale[$child[$value['outChildCode']]['orderCode']]['send_num'] >= $sale[$child[$value['outChildCode']]['orderCode']]['good_num'] ? 3 : 2;
|
|
|
Db::name('sale')
|
|
|
->where(['is_del' => 0, 'id' => $sale[$child[$value['outChildCode']]['orderCode']]['id']])
|
|
|
->update([
|
|
|
'send_num' => $sale[$child[$value['outChildCode']]['orderCode']]['send_num'],
|
|
|
'wsend_num' => $sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'],
|
|
|
- 'send_status' => $sale[$child[$value['outChildCode']]['orderCode']]['send_num'] >= $sale[$child[$value['outChildCode']]['orderCode']]['good_num'] ? 3 : 2,
|
|
|
+ 'send_status' => $send_status,
|
|
|
]);
|
|
|
|
|
|
+ if ($sale[$child[$value['outChildCode']]['orderCode']]['order_source'] == 5 && $send_status == 3) {
|
|
|
+ $yz_tmp[] = [
|
|
|
+ 'post_name' => $value['post_name'],
|
|
|
+ 'post_code' => $value['post_code'],
|
|
|
+ 'outCode' => $child[$value['outChildCode']]['outCode'],
|
|
|
+ 'orderCode' => $child[$value['outChildCode']]['orderCode'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
//库存
|
|
|
Db::name('good_stock')
|
|
|
->where(['is_del' => 0, 'spuCode' => $sale[$child[$value['outChildCode']]['orderCode']]['good_code'], 'wsm_code' => $child[$value['outChildCode']]['wsm_code']])
|
|
@@ -381,8 +430,23 @@ class OrderOutChild extends Base
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //日志、待办已办……
|
|
|
+
|
|
|
Db::commit();
|
|
|
|
|
|
+
|
|
|
+ //如果是有赞订单 且 所属发货单全部发货了,将发货信息推到有赞
|
|
|
+ //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
|
|
|
+
|
|
|
+ foreach ($yz_tmp as $temp) {
|
|
|
+ curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $temp['orderCode'], 'out_stype' => $temp['post_name'], 'post_code' => $temp['post_code'], 'uid' => $this->uid, 'uname' => $this->uname, 'order_out' => $temp['outCode']]);
|
|
|
+ }
|
|
|
+// if ($einfo['order_source'] == 5) {
|
|
|
+// $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $einfo['orderCode'], 'out_stype' => $post_name, 'post_code' => $post_code, 'uid' => $uid, 'uname' => $uname, 'order_out' => $outCode]);
|
|
|
+// $res = json_decode($res, true);
|
|
|
+// if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
|
|
|
+// }
|
|
|
+
|
|
|
return json_show(0, '操作完成');
|
|
|
|
|
|
} catch (Exception $exception) {
|