Parcourir la source

Merge branch 'dev_wf' of wugg/phpstock into version1.5

wufeng il y a 2 ans
Parent
commit
0fc10e7e7f

+ 135 - 0
app/abutment/controller/Filing.php

@@ -0,0 +1,135 @@
+<?php
+
+namespace app\abutment\controller;
+
+use think\facade\Db;
+use think\facade\Validate;
+use app\abutment\logic\Filing as FilingLogic;
+
+class Filing extends HomeBaseController
+{
+
+    //列表
+    public function getList()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '', 'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => ''], 'post');
+
+        $param['supplierNo'] = $this->request->user['supplierNo'];
+
+        return FilingLogic::list($param);
+    }
+
+    //添加
+    public function add()
+    {
+        $param = $this->request->only(['customerCode','companyName', 'num', 'is_determine_price', 'price' => 0, 'service_proportion', 'expect_service', 'cgd_charge' => 0, 'brand_id', 'preservation_day', 'delivery_day', 'make_day', 'tax', 'unit_id', 'cat_id', 'spec_list' => [], 'good_name', 'origin_place', 'delivery_place', 'weight', 'supply_area', 'pay_way', 'gold_weight', 'noble_metal', 'config', 'other_config', 'remark', 'cost_desc', 'good_img'], 'post');
+
+        $val = Validate::rule([
+            'customerCode|业务公司' => 'require|max:255',
+            'companyName|客户名称' => 'require|max:255',
+            'num|销售数量' => 'require|number|gt:0|lt:999999999',
+            'is_determine_price|是否确定售价' => 'require|number|in:1,0',
+            'price|销售价' => 'requireIf:is_determine_price,1|float|max:99999999.99',
+            'service_proportion|服务费比例' => 'require|number|between:0,100',
+            'expect_service|期望服务费' => 'require|float|max:99999999.99',
+            'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
+            'brand_id|品牌' => 'require|number|gt:0',
+            'preservation_day|有效期' => 'require|number|max:999999999',
+            'delivery_day|物流时间' => 'require|number|max:999999999',
+            'make_day|生产工期' => 'require|number|max:999999999',
+            'tax|税点' => 'require|number|between:0,100',
+            'unit_id|单位' => 'require|number|gt:0',
+            'cat_id|分类' => 'require|number|gt:0',
+            'spec_list|规格类型' => 'array|max:100',
+            'good_name|商品名称' => 'require|max:255',
+            'origin_place|产地' => 'require|array|length:3',
+            'delivery_place|发货地' => 'require|array|length:3',
+            'weight|总重量' => 'require|float|max:99999999.99',
+            'supply_area|供货区域' => 'require|number|in:1,2',
+            'pay_way|付款方式' => 'require|number|in:1,2,3',
+            'gold_weight|贵金属重量' => 'float|max:99999999.99',
+            'noble_metal|贵金属类型' => 'number|in:1,2,3',
+            'config|配置要求' => 'require|max:255',
+            'other_config|其他配置要求' => 'require|max:255',
+            'remark|采购备注' => 'require|max:255',
+            'cost_desc|工艺说明' => 'max:255',
+            'good_img|商品图片' => 'require|max:255',
+
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        $val2 = Validate::rule([
+            'spec_id|规格id' => 'require|number|gt:0',
+            'spec_value_id|规格值id' => 'require|number|gt:0',
+        ]);
+
+        $all_spec = Db::name('specs')
+            ->whereIn('id', array_column($param['spec_list'], 'spec_id'))
+            ->column('spec_name', 'id');
+
+        $all_spec_value = Db::name('spec_value')
+            ->whereIn('id', array_column($param['spec_list'], 'spec_value_id'))
+            ->column('spec_value', 'id');
+
+        foreach ($param['spec_list'] as &$spec_list) {
+            if (!$val2->check($spec_list)) return json_show(1004, $val2->getError());
+            $spec_list['spec_name'] = $all_spec[$spec_list['spec_id']] ?? '';
+            $spec_list['spec_value_name'] = $all_spec_value[$spec_list['spec_value_id']] ?? '';
+        }
+
+        $param['supplierNo']= $this->request->user['supplierNo'];
+        $param['supplierName']= $this->request->user['supplierName'];
+
+        return FilingLogic::add($param);
+
+    }
+
+    //详情
+    public function detail()
+    {
+        $param = $this->request->only(['id'], 'post');
+        $param['supplierNo'] = $this->request->user['supplierNo'];
+        return FilingLogic::detail($param);
+    }
+
+    //取消转单
+    public function cancel()
+    {
+        $param = $this->request->only(['id'], 'post');
+        $param['supplierNo'] = $this->request->user['supplierNo'];
+        return FilingLogic::cancel($param);
+    }
+
+    //转单
+    public function transfer()
+    {
+
+        $param = $this->request->only(['id', 'addr_list'], 'post');
+
+        $val = Validate::rule([
+            'id' => 'require|number|gt:0',
+            'addr_list|收货地址' => 'require|array|max:100',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        $val2 = Validate::rule([
+            'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
+            'contactor|联系人' => 'require|max:255',
+            'mobile|联系电话' => 'require|mobile',
+            'addr_code|收货省市区编码' => 'require|array|length:3',
+            'addr|详细地址' => 'require|max:255',
+        ]);
+
+
+        foreach ($param['addr_list'] as $addr_list) {
+            if (!$val2->check($addr_list)) return json_show(1004, $val2->getError());
+        }
+
+        $param['supplierNo'] = $this->request->user['supplierNo'];
+        return FilingLogic::transfer($param);
+    }
+
+
+}

+ 182 - 0
app/abutment/logic/Filing.php

@@ -0,0 +1,182 @@
+<?php
+
+namespace app\abutment\logic;
+
+use think\Exception;
+use think\facade\Db;
+
+class Filing
+{
+    //列表
+    public static function list(array $data = [])
+    {
+
+        $where = [['is_del', '=', '0']];
+        if ($data['cat_id'] != '') $where[] = ['cat_id', '=', $data['cat_id']];
+        if ($data['start_date'] != '' && $data['end_date'] != '') $where[] = ['addtime', 'between', [$data['start_date'], $data['end_date']]];
+        if ($data['filingCode'] != '') $where[] = ['filingCode', 'like', '%' . $data['filingCode'] . '%'];
+        if ($data['status'] != '') $where[] = ['status', '=', $data['status']];
+        if ($data['good_name'] != '') $where[] = ['good_name', 'like', '%' . $data['good_name'] . '%'];
+        if ($data['companyName'] != '') $where[] = ['companyName', 'like', '%' . $data['companyName'] . '%'];
+        if ($data['companyCode'] != '') $where[] = ['companyCode', 'like', '%' . $data['companyCode'] . '%'];
+        if ($data['orderCode'] != '') $where[] = ['orderCode', 'like', '%' . $data['orderCode'] . '%'];
+        if ($data['supplierNo'] != '') $where[] = ['supplierNo', '=', $data['supplierNo']];
+
+        $count = Db::name('filing')
+            ->where($where)
+            ->count('id');
+
+        $list = Db::name('filing')
+            ->field('id,filingCode,cat_id,good_name,num,good_img,price,expect_service,companyName,companyCode,status,addtime,"" catinfo,orderCode')
+            ->where($where)
+            ->page($data['page'], $data['size'])
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+
+        $all_cat = [];
+        foreach ($list as &$value) {
+            if (!isset($all_cat[$value['cat_id']])) {
+                $value['catinfo'] = $all_cat[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
+
+            }
+        }
+
+        return json_show(0, '获取报备单列表成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //添加
+    public static function add(array $data = [])
+    {
+
+        if ($data['is_determine_price'] == 1) $data['cgd_charge'] = bcadd($data['price'], $data['expect_service'], 2);//确定售价时,采购价=售价+服务费
+        else $data['price'] = bcsub($data['cgd_charge'], $data['expect_service'], 2);//不确定售价时,售价=采购价-服务费
+
+        $customerName = Db::name('business')
+            ->where(['companyNo' => $data['customerCode']])
+            ->value('company', '');
+        if ($customerName == '') return json_show(1004, '该业务公司不存在');
+
+        $rs = Db::name('filing')
+            ->strict(false)
+            ->insert(array_merge($data, [
+                'customerName' => $customerName,
+                'filingCode' => makeNo('BM'),
+                'service_charge' => $data['expect_service'],//服务费与期望服务费一致
+                'specinfo' => json_encode($data['spec_list']),
+                'send_way' => 2,
+                'cert_fee' => 0,
+                'pakge_fee' => 0,
+                'cost_fee' => 0,
+                'mark_fee' => 0,
+                'demo_fee' => 0,
+                'open_fee' => 0,
+                'delivery_fee' => 0,
+                'is_gold_price' => 0,
+                'is_diff' => 0,
+                'apply_id' => request()->user['uid'],
+                'apply_name' => request()->user['nickname'],
+                'status' => 0,
+                'is_del' => 0,
+                'addtime' => date('Y-m-d H:i:s'),
+                'updatetime' => date('Y-m-d H:i:s'),
+            ]));
+
+        return $rs ? json_show(0, '创建报备单成功') : json_show(1004, '创建报备单失败');
+
+    }
+
+    //详情
+    public static function detail(array $data = [])
+    {
+        $rs = Db::name('filing')
+            ->where(['is_del' => 0])
+            ->where($data)
+            ->withAttr('specinfo', function ($val) {
+                return json_decode($val);
+            })
+            ->findOrEmpty();
+        return json_show(0, '获取报备单详情成功', $rs);
+    }
+
+    //审核
+    public static function status(array $data = [])
+    {
+
+        $rs = Db::name('filing')
+            ->field('id,status')
+            ->where(['is_del' => 0, 'id' => $data['id']])
+            ->whereIn('status', [0, 2])
+            ->findOrEmpty();
+        if (empty($rs)) return json_show(1005, '该报备单不存在或不允许审核');
+
+        $companyName = Db::name('customer_info')
+            ->where(['is_del' => 0, 'companyNo' => $data['companyCode']])
+            ->value('companyName', '');
+        if ($companyName == '') return json_show(1005, '该客户不存在');
+
+        $res = Db::name('filing')
+            ->where(['is_del' => 0, 'id' => $data['id']])
+            ->whereIn('status', [0, 2])
+            ->update(array_merge($data, [
+                'companyName' => $companyName,
+                'updatetime' => date('Y-m-d H:i:s')
+            ]));
+        return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
+
+
+    }
+
+    //取消转单
+    public static function cancel(array $data = [])
+    {
+
+        $rs = Db::name('filing')
+            ->field('id,status')
+            ->where(['is_del' => 0, 'id' => $data['id'], 'status' => 2, 'supplierNo' => $data['supplierNo']])
+            ->findOrEmpty();
+        if (empty($rs)) return json_show(1005, '该报备单不存在或不是待转单状态');
+
+        $res = Db::name('filing')
+            ->where(['is_del' => 0, 'id' => $data['id'], 'status' => 2])
+            ->update(['status' => 5, 'updatetime' => date('Y-m-d H:i:s')]);
+        return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
+
+
+    }
+
+    //转单
+    public static function transfer(array $data = [])
+    {
+        $rs = Db::name('filing')
+            ->field(true)
+            ->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
+            ->findOrEmpty();
+        if (empty($rs)) json_show(1005, '该报备单不存在或不允许转单');
+
+        $date = date('Y-m-d H:i:s');
+
+        Db::startTrans();
+
+        try {
+
+            Db::name('filing')
+                ->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
+                ->update(['status' => 3, 'updatetime' => $date]);
+
+
+            Db::commit();
+            return json_show(0, '转单成功');
+        } catch (Exception $exception) {
+            Db::rollback();
+            Db::name('filing')
+                ->where(['is_del' => 0, 'id' => $data['id'], 'supplierNo' => $data['supplierNo'], 'status' => 2])
+                ->update(['status' => 4, 'updatetime' => $date, 'reason' => $exception->getMessage()]);
+            return json_show(1005, $exception->getMessage());
+        }
+
+    }
+
+
+}

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

@@ -68,3 +68,10 @@ route::rule('consultFeadback', 'abutment/Consult/feadback');//反馈商品添加
 route::rule('consultFeadEdit', 'abutment/Consult/feededit');//反馈商品编辑
 
 
+//报备单
+route::rule('filingList', 'Filing/getList');//获取列表
+route::rule('filingAdd', 'Filing/add');//创建
+route::rule('filingDetail', 'Filing/detail');//详情
+route::rule('filingCancel', 'Filing/cancel');//取消
+
+

+ 45 - 0
app/admin/controller/Filing.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\abutment\logic\Filing as FilingLogic;
+use think\facade\Validate;
+
+//报备单
+class Filing extends Base
+{
+    //列表
+    public function getList()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '', 'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => ''], 'post');
+
+        return FilingLogic::list($param);
+    }
+
+    //详情
+    public function detail()
+    {
+        $id = $this->request->post('id/d', 0);
+        return FilingLogic::detail($id);
+    }
+
+    //审核
+    public function status()
+    {
+        $param = $this->request->only(['id', 'status', 'companyCode', 'plat_code' => '', 'service_charge', 'service_proportion'], 'post');
+
+        $val = Validate::rule([
+            'id' => 'require|number|gt:0',
+            'status|状态' => 'require|number|in:1,2',
+            'companyCode|客户' => 'require|length:18',
+            'service_charge|服务费' => 'require|float|max:99999999.99',
+            'service_proportion|服务费比例' => 'require|number|between:0,100',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return FilingLogic::status($param);
+    }
+
+
+}

+ 6 - 1
app/admin/route/app.php

@@ -635,4 +635,9 @@ route::rule('addDataShare', 'admin/DataShare/addDataShare');//新建共享规则
 route::rule('getDataShareDetail', 'admin/DataShare/getDataShareDetail');//获取共享规则详情
 route::rule('editDataShare', 'admin/DataShare/editDataShare');//修改共享规则
 route::rule('deleteDataShare', 'admin/DataShare/deleteDataShare');//删除共享规则
-route::rule('statusDataShare', 'admin/DataShare/statusDataShare');//启/禁用共享规则
+route::rule('statusDataShare', 'admin/DataShare/statusDataShare');//启/禁用共享规则
+
+//报备单
+route::rule('filingList', 'admin/Filing/getList');//列表
+route::rule('filingDetail', 'admin/Filing/detail');//详情
+route::rule('filingStatus', 'admin/Filing/status');//审核