|
@@ -362,15 +362,11 @@ class Order extends HomeBaseController
|
|
|
|
|
|
$cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] != "" ? $this->post['cgdNo'] : [];
|
|
|
|
|
|
- if (empty($cgdNo)) {
|
|
|
- return json_show(1004, "参数cgdNo 不能为空");
|
|
|
- }
|
|
|
+ if (empty($cgdNo)) return json_show(1004, "参数cgdNo 不能为空");
|
|
|
|
|
|
$remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
|
|
|
$status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
|
|
|
- if ($status === "") {
|
|
|
- return json_show(1004, "参数status 不能为空");
|
|
|
- }
|
|
|
+ if ($status === "") return json_show(1004, "参数status 不能为空");
|
|
|
|
|
|
if ($status == 0) {
|
|
|
$data = Db::name("purchease_order")
|
|
@@ -379,9 +375,8 @@ class Order extends HomeBaseController
|
|
|
->where(["is_del" => 0])
|
|
|
->where('send_status', '>', 1)
|
|
|
->find();
|
|
|
- if (!empty($data)) {
|
|
|
- return json_show(1004, $data['cgdNo'] . "采购单发货中无法取消");
|
|
|
- }
|
|
|
+ if (!empty($data)) return json_show(1004, $data['cgdNo'] . "采购单发货中无法取消");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//原始数据
|
|
@@ -391,26 +386,29 @@ class Order extends HomeBaseController
|
|
|
->column('id,cgdNo,status,supplierNo,spuCode,order_type', 'cgdNo');
|
|
|
if (empty($info)) return json_show(1005, '没有可供确认的订单');
|
|
|
|
|
|
- $upd = Db::name("purchease_order")
|
|
|
- ->whereIn('cgdNo', $cgdNo)
|
|
|
- ->where('status', 0)
|
|
|
- ->save([
|
|
|
- 'status' => $status,
|
|
|
- 'remark' => $remark,
|
|
|
- 'updatetime' => date("Y-m-d H:i:s"),
|
|
|
- ]);
|
|
|
- if ($upd) {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $upd = Db::name("purchease_order")
|
|
|
+ ->whereIn('cgdNo', $cgdNo)
|
|
|
+ ->where('status', 0)
|
|
|
+ ->save([
|
|
|
+ 'status' => $status,
|
|
|
+ 'remark' => $remark,
|
|
|
+ 'updatetime' => date("Y-m-d H:i:s"),
|
|
|
+ ]);
|
|
|
+ if ($upd) {
|
|
|
// $user=GetUserInfo($this->post['token']);
|
|
|
- $uid = $this->request->user['uid']; //isset($user['data']['id'])?$user['data']['id']:0;
|
|
|
- $uname = $this->request->user['nickname'];//isset($user['data']['nickname'])?$user['data']['nickname']:'';
|
|
|
+ $uid = $this->request->user['uid']; //isset($user['data']['id'])?$user['data']['id']:0;
|
|
|
+ $uname = $this->request->user['nickname'];//isset($user['data']['nickname'])?$user['data']['nickname']:'';
|
|
|
|
|
|
- $supplier_cgderid = Db::name('supplier')
|
|
|
- ->where('is_del',0)
|
|
|
- ->whereIn('code',array_column($info,'supplierNo'))
|
|
|
- ->column('personid','code');
|
|
|
+ $supplier_cgderid = Db::name('supplier')
|
|
|
+ ->where('is_del', 0)
|
|
|
+ ->whereIn('code', array_column($info, 'supplierNo'))
|
|
|
+ ->column('personid', 'code');
|
|
|
|
|
|
- foreach ($cgdNo as $vlue) {
|
|
|
- if($status==1 || $status==2){
|
|
|
+ foreach ($cgdNo as $vlue) {
|
|
|
+ if ($status == 1 || $status == 2) {
|
|
|
// $orderinfo = Db::name('sale')
|
|
|
// ->alias('a')
|
|
|
// ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
|
|
@@ -420,42 +418,45 @@ class Order extends HomeBaseController
|
|
|
// 'b.cgdNo'=>$vlue,
|
|
|
// ])->findOrEmpty();
|
|
|
|
|
|
- $is_stock = Db::name('good_basic')
|
|
|
- ->where(['is_del'=>0,'spuCode'=>$info[$vlue]['spuCode']])
|
|
|
- ->value('is_stock');
|
|
|
-
|
|
|
- if($is_stock==1){
|
|
|
- //库存品,推给31库管人员、41库管-张凯旋
|
|
|
- $uids = Db::name('user_role')
|
|
|
- ->where([
|
|
|
- ['is_del', '=', 0],
|
|
|
- ['roleid', 'in', [31, 41]],
|
|
|
- ['status', '=', 1]
|
|
|
- ])->column('uid');
|
|
|
- if(!in_array($uid,$uids)) throw new Exception('库存品订单只能由库管人员操作');
|
|
|
+ $is_stock = Db::name('good_basic')
|
|
|
+ ->where(['is_del' => 0, 'spuCode' => $info[$vlue]['spuCode']])
|
|
|
+ ->value('is_stock');
|
|
|
+
|
|
|
+ if ($is_stock == 1) {
|
|
|
+ //库存品,推给31库管人员、41库管-张凯旋
|
|
|
+ $uids = Db::name('user_role')
|
|
|
+ ->where([
|
|
|
+ ['is_del', '=', 0],
|
|
|
+ ['roleid', 'in', [31, 41]],
|
|
|
+ ['status', '=', 1]
|
|
|
+ ])->column('uid');
|
|
|
+ if (!in_array($uid, $uids)) throw new Exception('库存品订单只能由库管人员操作');
|
|
|
// $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0,'handle_user_list'=>implode(',', $uids)];
|
|
|
- }else{
|
|
|
- //非库存品和采返商品,推给供应商负责人(还得是没开通账号的供应商)
|
|
|
-
|
|
|
- $res = SupplierRelationUserModel::field('id')
|
|
|
- ->where(['is_del' => SupplierUserModel::$is_del_normal, 'supplierNo' => $info[$vlue]['supplierNo'], 'status' => SupplierUserModel::$status_normal])
|
|
|
- ->findOrEmpty()
|
|
|
- ->isEmpty();
|
|
|
- if(!$res) throw new Exception('供应商已开通账号,只能由供应商端操作');
|
|
|
-
|
|
|
- if($uid != $supplier_cgderid[$info[$vlue]['supplierNo']])throw new Exception('非库存品和采返商品只能由供应商负责人操作');
|
|
|
+ } else {
|
|
|
+ //非库存品和采返商品,推给供应商负责人(还得是没开通账号的供应商)
|
|
|
+ $res = SupplierRelationUserModel::field('id')
|
|
|
+ ->where(['is_del' => SupplierUserModel::$is_del_normal, 'supplierNo' => $info[$vlue]['supplierNo'], 'status' => SupplierUserModel::$status_normal])
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->isEmpty();
|
|
|
+ if (!$res) throw new Exception('供应商已开通账号,只能由供应商端操作');
|
|
|
+
|
|
|
+ if ($uid != $supplier_cgderid[$info[$vlue]['supplierNo']]) throw new Exception('非库存品和采返商品只能由供应商负责人操作');
|
|
|
// $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0,'handle_user_list'=>isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
|
|
|
- }
|
|
|
- }//else $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
|
|
|
-
|
|
|
- $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0,'handle_user_list'=>isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
|
|
|
- ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], $process);
|
|
|
- $order = ["order_code" => $vlue, "status" => '', "action_remark" => $remark, "action_type" => "status"];
|
|
|
- ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], $order, 'CGD', $status, $this->post);
|
|
|
- }
|
|
|
- return json_show(0, "更新成功");
|
|
|
- } else return json_show(1004, '更新失败');
|
|
|
+ }
|
|
|
+ }//else $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
|
|
|
|
|
|
+ $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0, 'handle_user_list' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
|
|
|
+ ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], $process);
|
|
|
+ $order = ["order_code" => $vlue, "status" => '', "action_remark" => $remark, "action_type" => "status"];
|
|
|
+ ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], $order, 'CGD', $status, $this->post);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, "更新成功");
|
|
|
+ } else throw new Exception('更新失败');
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1004, $exception->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//批量入库
|