Browse Source

供应商账号新增、修改优化;复制原接口

wufeng 2 years ago
parent
commit
cfa51d655a
3 changed files with 558 additions and 41 deletions
  1. 513 0
      app/abutment/controller/Sale.php
  2. 41 41
      app/abutment/logic/Account.php
  3. 4 0
      app/abutment/route/app.php

+ 513 - 0
app/abutment/controller/Sale.php

@@ -0,0 +1,513 @@
+<?php
+
+
+namespace app\abutment\controller;
+
+
+use app\admin\model\ActionLog;
+use app\admin\model\GoodLog;
+use app\admin\model\ProcessOrder;
+use app\BaseController;
+use Exception;
+use think\facade\Cache;
+use think\facade\Db;
+
+class Sale extends BaseController
+{
+
+    //发货单列表
+    public function saleout()
+    {
+        $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
+        $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
+        $where = [["a.is_del", "=", 0], ['wpo.supplierNo', '=', $this->request->user['supplierNo']]];
+        $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
+        if ($orderCode !== "") {
+            $where[] = ['a.orderCode', "like", "%$orderCode%"];
+        }
+        $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
+        if ($order_type !== "") {
+            $where[] = ['a.order_type', "=", $order_type];
+        }
+        $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
+        if ($outCode !== "") {
+            $where[] = ['a.outCode', "like", "%$outCode%"];
+        }
+        $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
+        if ($apply_name !== "") {
+            $where[] = ['a.apply_name', "like", "%$apply_name%"];
+        }
+        $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
+        if ($good_code !== "") {
+            $where[] = ['b.good_code', "like", "%$good_code%"];
+        }
+        $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
+        if ($good_name !== "") {
+            $where[] = ['b.good_name', "like", "%$good_name%"];
+        }
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
+        if ($status !== "") {
+            $where[] = ['a.status', "=", $status];
+        }
+        $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
+        if ($start != "") {
+            $where[] = ["a.addtime", '>=', $start];
+        }
+        $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
+        if ($end != "") {
+            $where[] = ["a.addtime", '<=', $end];
+        }
+        $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
+        if ($companyNo != "") {
+            $where[] = ['b.customer_code', "like", "%$companyNo%"];
+
+        }
+        $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
+        if ($cgdNo != "") {
+            $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
+        }
+        $role = $this->checkRole();
+        $condition = '';
+        if (!empty($role['write']) && $this->uid != "") {
+            // $where[]=["a.apply_id","in",$role['write']];
+            $condition .= " (b.is_stock=1 and n.contactor = {$this->uid}) or (b.is_stock=0 and wpo.cgder_id = {$this->uid}) or a.apply_id in (" . implode(',',
+                    $role['write']) . ")";
+        }
+//        if(!empty($role['platform']) ){
+//            $where[]=["b.platform_id","in",$role['platform']];
+//        }
+        $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
+        if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
+
+        //发货时间筛选
+        $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
+        $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
+
+        if ($start_sendtime != "" && $end_sendtime != "") {
+            $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 223:59:59"]];
+            $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
+        }
+
+        $count = Db::name('order_out')
+            ->alias('a')
+            ->join("sale b", "b.orderCode=a.orderCode", "left")
+            ->join("customer_info v", "v.companyNo=b.customer_code", "left")
+            ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
+            ->leftJoin("order_send os", "os.outCode=a.outCode")
+            ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
+            ->where($where)
+            ->where($condition)
+            ->count();
+        $total = ceil($count / $size);
+        $page = $page >= $total ? $total : $page;
+        $list = Db::name('order_out')
+            ->alias('a')
+            ->join("sale b", "b.orderCode=a.orderCode", "left")
+            ->join("customer_info v", "v.companyNo=b.customer_code", "left")
+            ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
+            ->leftJoin("order_send os", "os.outCode=a.outCode")
+            ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
+            ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
+            ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,u.itemid")
+            ->where($where)
+            ->where($condition)
+            ->order("addtime desc")
+            ->page($page, $size)
+            ->cursor();
+
+        $data = [];
+        foreach ($list as $value) {
+            $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
+                ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
+            $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
+            if ($addr) {
+                $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
+                if (is_string($addinfo) && $addinfo != '') {
+                    $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
+                    list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
+                }
+                $addr['addr_cn'] = GetAddr(json_encode($addinfo));
+            }
+            if ($value['order_type'] == 3) {
+                $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
+            } else {
+                $goon = Db::name('good_platform')->field('a.id,b.cat_id')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $value['skuCode']])->find();
+            }
+            $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
+            $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
+            $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
+            $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
+            $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
+            $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
+            $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
+            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
+            $data[] = $value;
+        }
+        return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
+    }
+
+
+    //发货单详情
+    public function saleOutInfo()
+    {
+        $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
+        if ($outCode == "") {
+            return error_show(1002, "参数outcode不能为空");
+        }
+        $codeinfo = Db::name("order_out")->where(['outCode' => $outCode, "is_del" => 0])->find();
+        if (empty($codeinfo)) {
+            return error_show(1002, "未找到出库数据");
+        }
+        $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
+        if ($item['order_type'] == 3) {
+            $goodinfo = Db::name("good_zixun")->where(["spuCode" => $item['good_code'], "is_del" => 0])->find();
+            if ($goodinfo == false) {
+                return error_show(1004, "未找到商品数据");
+            }
+        } else {
+            $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
+                ->where(['a.skuCode' => $item['skuCode']])->find();
+            if ($goodinfo == false) {
+                return error_show(1002, "未找到商品数据");
+            }
+        }
+        $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
+        $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
+        if ($addr) {
+            $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
+            if (is_string($addinfo) && $addinfo != '') {
+                $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
+                list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
+            }
+            $addr['addr_cn'] = GetAddr(json_encode($addinfo));
+        }
+        $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
+        $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
+        $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
+        $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
+        $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
+        $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
+        $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
+        $codeinfo['addr'] = $addr['addr_cn'] ?? '';
+        $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
+        $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
+        $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
+        $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
+        $codeinfo['sendtime'] = $codeinfo['status'] < 2 ? '' : $codeinfo['sendtime'];
+        $codeinfo['can'] = $int;
+        $codeinfo['order_source'] = $item['order_source'];
+        $orderReturn = Db::name("order_return")->where(["outCode" => $outCode, "is_del" => 0])->order("id desc")->find();
+        $codeinfo['order_return'] = $orderReturn;
+        return app_show(0, "获取成功", $codeinfo);
+    }
+
+    //库管发货
+    public function outSend()
+    {
+        $outCode = isset($this->post['outCode']) && $this->post['outCode'] != "" ? trim($this->post['outCode']) : "";
+        if ($outCode == "") {
+            return error_show(1004, "参数outCode不能为空");
+        }
+        $outinfo = Db::name("order_out")->where(["outCode" => $outCode, "is_del" => 0])->find();
+        if ($outinfo == false) {
+            return error_show(1004, "发货数据未找到");
+        }
+        $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
+        if (empty($einfo)) {
+            return error_show(1002, "未找到销售订单数据");
+        }
+        $is_reurn = Db::name("sale_return")->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->where("status", "<", 4)->find();
+        if ($is_reurn != false) {
+            return error_show(1002, "销售单存在退货未处理完成");
+        }
+        $post_name = isset($this->post['post_name']) && $this->post['post_name'] != "" ? trim($this->post['post_name']) : "";
+        if ($post_name == "") {
+            return error_show(1004, "参数post_name不能为空");
+        }
+        $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
+        if ($post_code == "") {
+            return error_show(1004, "参数post_code不能为空");
+        }
+        $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
+        $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] != "" ? floatval($this->post['post_fee']) : "";
+        $outinfo['post_name'] = $post_name;
+        $outinfo['post_code'] = $post_code;
+        $outinfo['post_fee'] = $post_fee;
+        $outinfo['sendtime'] = date("Y-m-d H:i:s");
+        $old_outinfo_status = $outinfo['status'];
+        $outinfo['status'] = 2;
+        $outinfo['updatetime'] = date("Y-m-d H:i:s");
+        $outinfo['remark'] = $remark;
+        if ($einfo['wsend_num'] < $outinfo['send_num']) {
+            return error_show(1004, "订单未发货数量不足");
+        }
+        Db::startTrans();
+        try {
+            $up = Db::name("order_out")->save($outinfo);
+
+            $user_info = GetUserInfo($this->post['token']);
+            $uid = isset($user_info['data']['id']) ? $user_info['data']['id'] : 0;
+            $uname = isset($user_info['data']['nickname']) ? $user_info['data']['nickname'] : '';
+
+
+            if ($up) {
+                //修改状态,添加待办
+                ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
+                    "order_code" => $outinfo['outCode'],//出库单号
+                    "status" => $old_outinfo_status,//这里的status是之前的值
+                    "action_remark" => '',//备注
+                    "action_type" => "edit"//新建create,编辑edit,更改状态status
+                ], "CKD", $outinfo['status'], $outinfo);
+
+
+                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
+                    "order_type" => 'CKD',
+                    "order_code" => $outinfo['outCode'],//出库单号
+                    "order_id" => $outinfo['id'],
+                    "order_status" => $outinfo['status'],
+                    "before_status" => $old_outinfo_status,
+                    'wait_id'=>$outinfo['apply_id'],
+                    'wait_name'=>$outinfo['apply_name'],
+                ]);
+                $orderstatus = $einfo['status'];
+                $einfo['send_num'] += $outinfo['send_num'];
+                $einfo['wsend_num'] -= $outinfo['send_num'];
+                $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
+                $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
+                $einfo['updatetime'] = date("Y-m-d H:i:s");
+                $saleup = Db::name("sale")->save($einfo);
+                if ($saleup == false) {
+                    Db::rollback();
+                    return error_show(1002, "销售单状态更新失败");
+                }
+//                }
+                //修改状态,添加待办
+
+                ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
+                    "order_code" => $einfo['orderCode'],//出库单号
+                    "status" => $orderstatus,//这里的status是之前的值
+                    "action_remark" => '',//备注
+                    "action_type" => "edit"//新建create,编辑edit,更改状态status
+                ], "XSQRD", $einfo['status'], $einfo);
+
+
+                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
+                    "order_type" => 'XSQRD',
+                    "order_code" => $einfo['orderCode'],//出库单号
+                    "order_id" => $einfo['id'],
+                    "order_status" => $einfo['status'], "before_status" => $orderstatus
+                ]);
+
+                $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
+                if ($stokc == false) {
+                    Db::rollback();
+                    return error_show(1002, "未找到库存数据");
+                } else {
+                    if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
+                        Db::rollback();
+                        return error_show(1002, "超出库存数量");
+                    }
+                    $stokc['wait_out_stock'] -= $outinfo['send_num'];
+                    $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
+                    //  $stokc['intra_stock']+=$outinfo['send_num'];
+                    $stokc['updatetime'] = date("Y-m-d H:i:s");
+                }
+                $stoc = Db::name("good_stock")->save($stokc);
+                if ($stoc == false) {
+                    Db::rollback();
+                    return error_show(1002, "库存更新失败");
+                }
+                $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stokc['id'], "type" => 2, 'stock' => $outinfo['send_num'], "stock_name" => "wait_out_stock"];
+
+                GoodLog::LogAdd(['id' => $uid, 'nickname' => $uname], $good_data, "CKD");
+                Cache::store("redis")->handler()->lPush("SENDOUT", $outCode);
+                Db::commit();
+
+
+            } else {
+                Db::rollback();
+                return error_show(1004, "发货失败");
+            }
+
+            //如果是有赞订单的话,将发货信息推到有赞
+            //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
+            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 app_show(0, "发货成功");
+
+        } catch (\Exception $e) {
+            Db::rollback();
+            return error_show(1004, $e->getMessage());
+        }
+
+    }
+
+    //库管批量发货
+    public function outSendBatchByImport()
+    {
+
+        $param = $this->request->only(['list', 'token'], 'post', 'trim');
+
+        if (empty($param['list'])) return error_show(1005, 'list参数不能为空');
+
+        $user = GetUserInfo($param['token']);
+        $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
+        $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+
+        //所有发货单信息
+        $order_out_infos = Db::name("order_out")
+            ->where('status', 1)
+            ->where('is_del', 0)
+            ->whereIn('outCode', array_column($param['list'], 'outCode'))
+            ->column('id,status,send_num,orderCode,wsm_code,apply_id,apply_name', 'outCode');
+
+        //处理数据
+        Db::startTrans();
+        try {
+
+            $good_data = [];
+
+            $temp_out_codes = [];
+
+            foreach ($param['list'] as $value) {
+
+                if (!isset($order_out_infos[$value['outCode']])) throw new Exception($value['outCode'] . '该发货单未找到或状态不允许发货');
+                //每次循环都需要重新查询对应数据,为了数据及时更新
+                $sale_infos = Db::name("sale")
+                    ->where('orderCode', $order_out_infos[$value['outCode']]['orderCode'])
+                    ->where('is_del', 0)
+                    ->column('id,send_num,wsend_num,status,good_code,order_source', 'orderCode');
+
+                if (!isset($sale_infos[$order_out_infos[$value['outCode']]['orderCode']])) throw new Exception($value['outCode'] . '该发货单对应的销售单未找到');
+
+                //判断发货单是否重复
+                if (isset($temp_out_codes[$value['outCode']])) {
+                    Db::rollback();
+                    return app_show(1005, '下列发货申请单号重复', [$value]);
+                } else $temp_out_codes[$value['outCode']] = $value['outCode'];
+
+                //【发货单】
+                //查询已有发货单信息及状态
+
+                //更新发货单
+                $up = Db::name("order_out")
+                    ->where(['id' => $order_out_infos[$value['outCode']]['id'], 'outCode' => $value['outCode'], 'status' => 1, "is_del" => 0])
+                    ->update([
+                        'post_name' => isset($value['post_name']) ? $value['post_name'] : '',
+                        'post_code' => $value['post_code'],
+                        'post_fee' => $value['post_fee'],
+                        'sendtime' => date('Y-m-d H:i:s'),
+                        'status' => 2,
+                        'updatetime' => date('Y-m-d H:i:s'),
+                        'remark' => isset($value['remark']) ? $value['remark'] : '',
+                    ]);
+
+                if ($up) {
+
+                    //修改状态,添加待办
+                    ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
+                        "order_code" => $value['outCode'],//出库单号
+                        "status" => $order_out_infos[$value['outCode']]['status'],//这里的status是之前的值
+                        "action_remark" => '',//备注
+                        "action_type" => "edit"//新建create,编辑edit,更改状态status
+                    ], "CKD", 2, $order_out_infos[$value['outCode']]);
+
+                    ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
+                        "order_type" => 'CKD',
+                        "order_code" => $value['outCode'],//出库单号
+                        "order_id" => $order_out_infos[$value['outCode']]['id'],
+                        "order_status" => 2,
+                        "before_status" => $order_out_infos[$value['outCode']]['status'],
+                        'wait_id' => $order_out_infos[$value['outCode']]['apply_id'],
+                        'wait_name' => $order_out_infos[$value['outCode']]['apply_name'],
+                    ]);
+
+
+                    //【销售单】
+                    $einfo = [];
+                    $einfo['send_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['send_num'] + $order_out_infos[$value['outCode']]['send_num'];
+                    $einfo['wsend_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['wsend_num'] - $order_out_infos[$value['outCode']]['send_num'];
+                    $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
+                    $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
+                    $einfo['updatetime'] = date("Y-m-d H:i:s");
+
+                    $saleup = Db::name("sale")
+                        ->where('id', $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'])
+                        ->update($einfo);
+                    if ($saleup == false) throw new Exception($value['outCode'] . '销售单状态更新失败');
+
+                    //修改状态,添加待办
+                    ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
+                        "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//销售单号
+                        "status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],//这里的status是之前的值
+                        "action_remark" => '',//备注
+                        "action_type" => "edit"//新建create,编辑edit,更改状态status
+                    ], "XSQRD", $einfo['status'], $einfo);
+
+                    ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
+                        "order_type" => 'XSQRD',
+                        "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//出库单号
+                        "order_id" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'],
+                        "order_status" => $einfo['status'], "before_status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status']
+                    ]);
+
+                    //【库存】
+                    $stock = Db::name("good_stock")
+                        ->field('id,wait_out_stock,usable_stock,total_stock,updatetime')
+                        ->where([
+                            "is_del" => 0,
+                            'spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'],
+                            "wsm_code" => $order_out_infos[$value['outCode']]['wsm_code'],
+                        ])->find();
+                    if ($stock == false) throw new Exception($value['outCode'] . '未找到库存数据');
+                    else {
+                        if ($order_out_infos[$value['outCode']]['send_num'] > $stock['wait_out_stock']) throw new Exception($value['outCode'] . '超出库存数量');
+
+                        $stock['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
+                        $stock['total_stock'] = $stock['wait_out_stock'] + $stock['usable_stock'];
+                        $stock['updatetime'] = date("Y-m-d H:i:s");
+
+                        $stock_rs = Db::name("good_stock")
+                            ->where('id', $stock['id'])
+                            ->update($stock);
+                        if ($stock_rs == false) throw new Exception($value['outCode'] . '库存更新失败');
+
+                        $good_data[] = [
+                            'good_log_code' => $value['outCode'],
+                            'stock_id' => $stock['id'],
+                            'type' => 2,
+                            'stock' => $order_out_infos[$value['outCode']]['send_num'],
+                            'stock_name' => 'wait_out_stock'
+                        ];
+
+                    }
+
+
+                } else throw new Exception($value['outCode'] . '发货失败');
+                Cache::store("redis")->handler()->lPush("SENDOUT",$value['outCode']);
+            }
+
+            if (!empty($good_data)) GoodLog::LogAdd(['id' => $createrid, 'nickname' => $creater], $good_data, "CKD");
+
+            Db::commit();
+
+            return app_show(0, '发货成功');
+
+        } catch (Exception $exception) {
+            Db::rollback();
+            return error_show(1004, $exception->getMessage());
+        }
+
+
+    }
+
+
+
+
+}

+ 41 - 41
app/abutment/logic/Account.php

@@ -192,55 +192,45 @@ class Account
             $db = new SupplierUserModel();
 
             $res = $db
-                ->field('uid,status')
+                ->field('uid')
                 ->where([
                     'is_del' => $db::$is_del_normal,
                     'mobile' => $param['mobile'],
                 ])->findOrEmpty();
 
-            if ($res->isEmpty()) {
-                //新增账号
-                $password = get_encryption_password(Config::get('app.default_password'));
-                $res->uid = $db->insertGetId([
-                    'nickname' => $param['nickname'],//姓名
-                    'mobile' => $param['mobile'],//手机号
-                    'email' => $param['email'],//邮箱
-                    'password' => $password['password'],//密码密文
-                    'salt' => $password['salt'],//盐值
-                    'status' => $db::$status_normal,
-                    'is_del' => $db::$is_del_normal,
-                    'createrid' => $user['data']['user_id'] ?? 0,
-                    'creater' => $user['data']['nickname'] ?? '',
-                ]);
-
-                $res->status = $db::$status_normal;
-
-            }
-
-            $relation = SupplierRelationUserModel::where([
+            if (!$res->isEmpty()) throw new Exception('该手机号已存在');
+
+            //新增账号
+            $password = get_encryption_password(Config::get('app.default_password'));
+            $uid = $db->insertGetId([
+                'nickname' => $param['nickname'],//姓名
+                'mobile' => $param['mobile'],//手机号
+                'email' => $param['email'],//邮箱
+                'password' => $password['password'],//密码密文
+                'salt' => $password['salt'],//盐值
+                'status' => $db::$status_normal,
                 'is_del' => $db::$is_del_normal,
-                'uid' => $res->uid
-            ])->whereIn('supplierNo', $param['supplierNo'])
-                ->column('id', 'supplierNo');
+                'createrid' => $user['data']['user_id'] ?? 0,
+                'creater' => $user['data']['nickname'] ?? '',
+            ]);
 
             $insert_data = [];
             foreach ($param['supplierNo'] as $supplierNo) {
 
-                if (isset($relation[$supplierNo])) continue;
-                else {
-                    $insert_data[] = [
-                        'uid' => $res->uid,
-                        'supplierNo' => $supplierNo,
-                        'supplierName' => $supplierName[$supplierNo] ?? '',
-                        'status' => $res->status,
-                        'is_del' => $db::$is_del_normal,
-                        'createrid' => $user['data']['user_id'] ?? 0,
-                        'creater' => $user['data']['nickname'] ?? '',
-                    ];
-                }
+                $insert_data[] = [
+                    'uid' => $uid,
+                    'supplierNo' => $supplierNo,
+                    'supplierName' => $supplierName[$supplierNo] ?? '',
+                    'status' => $db::$status_normal,
+                    'is_del' => $db::$is_del_normal,
+                    'createrid' => $user['data']['user_id'] ?? 0,
+                    'creater' => $user['data']['nickname'] ?? '',
+                ];
             }
 
-            if ($insert_data) Db::connect('mysql_sys')->name('supplier_relation_user')->insertAll($insert_data);
+            if ($insert_data) Db::connect('mysql_sys')
+                ->name('supplier_relation_user')
+                ->insertAll($insert_data);
 
             Db::connect('mysql_sys')->commit();
             return json_show(0, '操作成功');
@@ -263,12 +253,22 @@ class Account
             $db = new SupplierUserModel();
 
             $res = $db
-                ->field('uid')
+                ->field('uid,mobile')
                 ->where(['uid' => $param['uid'], 'is_del' => $db::$is_del_normal])
                 ->findOrEmpty()
-                ->isEmpty();
-
-            if ($res) return json_show(1004, '该账号不存在');
+                ->toArray();
+
+            if (empty($res)) return json_show(1004, '该账号不存在');
+
+            if ($res['mobile'] != $param['mobile']) {
+                $temp = $db
+                    ->field('uid')
+                    ->where(['mobile' => $param['mobile'], 'is_del' => $db::$is_del_normal])
+                    ->where('uid', '<>', $param['uid'])
+                    ->findOrEmpty()
+                    ->isEmpty();
+                if (!$temp) throw new Exception('要修改的手机号已存在');
+            }
 
             $db
                 ->where('uid', $param['uid'])

+ 4 - 0
app/abutment/route/app.php

@@ -29,5 +29,9 @@ route::rule('getOrderList', 'abutment/Order/getList');//列表
 route::rule('getOrderInfo', 'abutment/Order/info');//详情
 route::rule('changeOrderStatus', 'abutment/Order/status');//订单确认
 route::rule('addOrderIn', 'abutment/Order/add');//订单批量入库
+route::rule('saleOutList', 'abutment/Sale/saleout');//发货单列表
+route::rule('saleOutInfo', 'abutment/Sale/saleOutInfo');//发货单详情
+route::rule('outSend', 'abutment/Sale/outSend');//发货单库管发货
+route::rule('outSendBatchByImport', 'abutment/Sale/saleOutInfo');//发货单库管批量发货