Prechádzať zdrojové kódy

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

wufeng 2 rokov pred
rodič
commit
aa9b762a90

+ 2 - 0
app/abutment/common.php

@@ -0,0 +1,2 @@
+<?php
+

+ 8 - 0
app/abutment/config/common.php

@@ -0,0 +1,8 @@
+<?php
+
+return [
+
+
+
+
+];

+ 6 - 0
app/abutment/config/redis_key.php

@@ -0,0 +1,6 @@
+<?php
+
+return [
+    //用户信息
+    'user_info_token' => 'user_info_token_',
+];

+ 78 - 0
app/abutment/config/validate_rules.php

@@ -0,0 +1,78 @@
+<?php
+
+return [
+
+    //通用-关键字
+    'keyword' => [
+        'keyword|关键字' => 'chsDash|max:100',
+    ],
+
+    //通用
+    'common' => [
+        'keyword|关键字' => 'chsDash|max:100',
+        'page|页码' => 'require|number|gt:0',
+        'size|每页数量' => 'require|number|elt:100',
+    ],
+
+    //登录
+    'login' => [
+        'mobile|手机号' => 'require|number|length:11|mobile',
+        'password|密码' => 'require',
+    ],
+
+    //修改密码
+    'changePassword' => [
+        'old_password|旧密码' => 'require|min:6|max:200',
+        'new_password|新密码' => 'require|min:6|max:200',
+        'confirm_password|确认密码' => 'require|confirm:new_password|min:6|max:200',
+    ],
+
+    //添加供应商账号
+    'addAccount' => [
+        'nickname|姓名' => 'require|max:255',
+        'mobile|手机号' => 'require|number|length:11|mobile',
+        'email|邮箱' => 'email',
+    ],
+
+    //修改供应商账号
+    'editAccount' => [
+        'nickname|姓名' => 'require|max:255',
+        'mobile|手机号' => 'require|number|length:11|mobile',
+        'email|邮箱' => 'email',
+        'old_mobile|原始手机号' => 'require|number|length:11|mobile',
+    ],
+
+    //启/禁用 供应商账号
+    'statusAccount' => [
+        'mobile|手机号' => 'require|number|length:11|mobile',
+        'status|状态' => 'require|number|in:' . \app\abutment\model\SupplierUser::$status_normal . ',' . \app\abutment\model\SupplierUser::$status_disabled,
+    ],
+
+    //获取分类列表
+    'getCatList' => [
+        'keyword|关键字' => 'chsDash|max:100',
+        'pid|父级分类id' => 'require|number|egt:0',
+    ],
+
+    //获取规格值列表
+    'getSpecsValueByTitleList' => [
+        'spec_id|规格类型id' => 'require|number|gt:0',
+    ],
+
+    //获取省市县列表
+    'getAreaList' => [
+        'level' => 'number|in:1,2,3',
+        'pid_code' => 'requireIf:level,2|requireIf:level,3|number|length:6',
+    ],
+
+
+    //创建商品上线申请
+    'GoodUpCreate' => [
+        'spuCodes|商品编码' => 'require|array|max:10',
+        'online_reason|上线原因' => 'require|max:255',
+        'online_remark|上线备注' => 'require|max:255',
+        'platform_id|平台id' => 'require|number|gt:0',
+    ],
+
+
+];

+ 31 - 0
app/abutment/controller/Account.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace app\abutment\controller;
+
+use app\abutment\logic\Account as AccountLogic;
+use app\BaseController;
+use think\facade\Config;
+use think\facade\Validate;
+
+
+//供应商账号
+class Account extends BaseController
+{
+
+    //供应商账号登录
+    public function login()
+    {
+
+        $param = $this->request->filter('trim')->only(['mobile', 'password'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.login'));
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::login($param);
+    }
+
+
+
+
+}

+ 376 - 0
app/abutment/controller/Good.php

@@ -0,0 +1,376 @@
+<?php
+
+namespace app\abutment\controller;
+
+use app\abutment\validate\Good as GoodValidate;
+use app\BaseController;
+use app\abutment\logic\Good as GoodLogic;
+use think\facade\Db;
+
+//商品模块
+class Good extends BaseController
+{
+    //获取商品列表
+    public function list()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
+
+        validate(GoodValidate::class)->scene('list')->check($param);
+
+        return GoodLogic::list($param);
+
+    }
+
+    //创建商品
+    public function createGood()
+    {
+        $data = [
+            'good_name',//商品名称
+            'cat_id',//分类
+            'brand_id',//品牌
+            'good_unit',//单位
+            'moq',//起订量
+            'customized',//定制工期
+            'tax',//税点
+            'good_size',//商品尺寸
+            'companyNo',//业务公司编码
+            'is_auth',//是否有销售权限
+            'auth_img' => '',//销售授权图片
+            'after_sales',//售后说明
+            'craft_desc' => '',//工艺说明
+            'good_remark',//商品备注
+            'weight',//商品重量
+            'packing_way',//包装方式
+            'packing_size',//装箱尺寸
+            'packing_spec',//装箱规格
+            'packing_weight',//装箱重量
+            'packing_list',//包装清单,
+            'good_bar' => '',//商品条形码
+            'supply_area',//供货区域,
+            'delivery_place',//发货地,
+            'origin_place',//产地',
+            'delivery_day',//物流时间,
+            'lead_time' => 0,//供货周期
+            'cgd_gold_price' => 0,//供应商采购金价
+            'sample_day' => 0,//调样周期
+            'sample_fee' => 0,//调样费用
+            'stock_moq',//库存品备库起订数量
+            'is_diff' => '',//是否有工差'
+            'good_img',//商品详情主图
+            'config' => '',//配置'
+            'other_config' => '',//其他配置
+            'good_thumb_img',//商品缩略图
+            'good_info_img',//商品详情图
+            'cert_fee' => 0.00,//证书费
+            'packing_fee' => 0.00,//包装费
+            'cost_fee' => 0.00,//工艺费
+            'mark_fee' => 0.00,//加标费
+            'demo_fee' => 0.00,//打样费
+            'open_fee' => 0.00,//开模费
+            'noble_metal' => 0,//贵金属种类
+            'noble_weight' => 0,//贵金属重量
+            'is_gold_price' => 0,//是否使用实时金价
+            'market_price' => 0,//市场价
+            'nake_price' => 0,//含税成本价
+            'speclist' => [],//规格列表
+            'good_ladder' => [],//阶梯成本列表
+            'is_support_barter' => 1,//是否可退货
+        ];
+
+        $param = $this->request->filter('trim')->only($data, 'post');
+        validate(GoodValidate::class)->scene('create')->check($param);
+
+        $good_name = $this->request->filter('trim')->post('good_name');
+        $cat_id = $this->request->filter('trim')->post('cat_id/d');
+        $cat = Db::name('cat')->field('id')->where(['id' => $cat_id, 'is_del' => 0])->findOrEmpty();
+        if (empty($cat)) return json_show(1004, '分类不存在');
+        $brandid = $this->request->filter('trim')->post('brand_id/d');
+        $brand = Db::name('brand')->field('id')->where(['id' => $brandid, 'is_del' => 0])->findOrEmpty();
+        if (empty($brand)) return json_show(1004, '品牌不存在');
+        $unit = $this->request->filter('trim')->post('good_unit/d');
+        $unit_info = Db::name('unit')->field('id')->where(['id' => $unit, 'is_del' => 0])->findOrEmpty();
+        if (empty($unit_info)) return json_show(1004, '单位不存在');
+        $good_type = 2; // 非定制
+        $moq = $this->request->filter('trim')->post('moq/d', 0);
+        $customized = $this->request->filter('trim')->post('customized/d', 0);
+        $is_exclusive = 2;//定制类型,2常规
+        $tax = $this->request->filter('trim')->post('tax/d');
+        $supplierNo = $this->request->supplier['supplierNo'];
+        $good_size = $this->request->filter('trim')->post('good_size');
+        $companyNo = $this->request->filter('trim')->post('companyNo');
+        $company = Db::name('business')->field('id')->where(['companyNo' => $companyNo, 'is_del' => 0])->findOrEmpty();
+        if (empty($company)) return json_show(1004, '业务公司不存在');
+        $is_auth = $this->request->filter('trim')->post('is_auth/d');
+        $auth_img = $this->request->filter('trim')->post('auth_img', '');
+
+        $after_sales = $this->request->filter('trim')->post('after_sales');
+        $craft_desc = $this->request->filter('trim')->post('craft_desc', '');
+
+        $good_remark = $this->request->filter('trim')->post('good_remark');
+        $weight = $this->request->filter('trim,floatval')->post('weight');
+        $packing_way = $this->request->filter('trim')->post('packing_way');
+        $packing_size = $this->request->filter('trim')->post('packing_size');
+        $packing_spec = $this->request->filter('trim')->post('packing_spec');
+        $packing_weight = $this->request->filter('trim,floatval')->post('packing_weight');
+        $packing_list = $this->request->filter('trim')->post('packing_list');
+        $good_bar = $this->request->filter('trim')->post('good_bar', '');
+        $supply_area = $this->request->filter('trim')->post('supply_area/d');
+        $delivery_place = $this->request->filter('trim')->post('delivery_place');//发货地
+        $origin_place = $this->request->filter('trim')->post('origin_place');//产地
+
+        $province = Db::name('province')
+            ->whereIn('province_code', [$delivery_place[0], $origin_place[0]])
+            ->column('id', 'province_code');
+
+        if (empty($province[$delivery_place[0]])) return json_show(1004, '发货地数据不规范,省份编码不存在');
+        if (empty($province[$origin_place[0]])) return json_show(1004, '产地数据不规范,省份编码不存在');
+        $city = Db::name('city')
+            ->where(function ($query) use ($delivery_place) {
+                return $query->where(['city_code' => $delivery_place[1], 'province_code' => $delivery_place[0]]);
+            })->whereOr(function ($query) use ($origin_place) {
+                return $query->where(['city_code' => $origin_place[1], 'province_code' => $origin_place[0]]);
+            })
+            ->column('id', 'city_code');
+        if (empty($city[$delivery_place[1]])) return json_show(1004, '发货地数据不规范,城市编码不存在');
+        if (empty($city[$origin_place[1]])) return json_show(1004, '产地数据不规范,城市编码不存在');
+
+        $area = Db::name('area')
+            ->where(function ($query) use ($delivery_place) {
+                return $query->where(['area_code' => $delivery_place[2], 'city_code' => $delivery_place[1]]);
+            })->whereOr(function ($query) use ($origin_place) {
+                return $query->where(['area_code' => $origin_place[2], 'city_code' => $origin_place[1]]);
+            })
+            ->column('id', 'area_code');
+
+        if (empty($area[$delivery_place[2]])) return json_show(1004, '发货地数据不规范,县区编码不存在');
+        if (empty($area[$origin_place[2]])) return json_show(1004, '产地数据不规范,县区编码不存在');
+
+        $delivery_day = $this->request->filter('trim')->post('delivery_day/d');
+        $lead_time = $this->request->filter('trim')->post('lead_time/d', 0);
+        $cgd_gold_price = $this->request->filter('trim,floatval')->post('cgd_gold_price', 0);
+        $sample_day = $this->request->filter('trim')->post('sample_day/d', 0);
+        $sample_fee = $this->request->filter('trim,floatval')->post('sample_fee', 0);
+        $is_stock = 0;//0非库存品
+        $stock_moq = $this->request->filter('trim')->post('stock_moq/d', 0);
+        $is_diff = $this->request->filter('trim')->post('is_diff/d', 0);
+        $good_img = $this->request->filter('trim')->post('good_img');
+        $config = $this->request->filter('trim')->post('config', '');
+        $other_config = $this->request->filter('trim')->post('other_config', '');
+        $good_thumb_img = $this->request->filter('trim')->post('good_thumb_img');
+        $good_info_img = $this->request->filter('trim')->post('good_info_img');
+        $cert_fee = $this->request->filter('trim,floatval')->post('cert_fee', 0);
+        $packing_fee = $this->request->filter('trim,floatval')->post('packing_fee', 0);
+        $cost_fee = $this->request->filter('trim,floatval')->post('cost_fee', 0);
+        $mark_fee = $this->request->filter('trim,floatval')->post('mark_fee', 0);
+        $demo_fee = $this->request->filter('trim,floatval')->post('demo_fee', 0);
+        $open_fee = $this->request->filter('trim,floatval')->post('open_fee', 0);
+        $noble_weight = $this->request->filter('trim,floatval')->post('noble_weight', 0);
+        $market_price = $this->request->filter('trim,floatval')->post('market_price', 0);
+        $is_gold_price = $this->request->filter('trim')->post('is_gold_price/d', 0);
+        $noble_metal = $this->request->filter('trim')->post('noble_metal/d', 0);
+        $nake_price = $this->request->filter('trim,floatval')->post('nake_price', 0);
+        $speclist = $this->request->filter('trim')->post('speclist', []);
+        $good_ladder = $this->request->filter('trim')->post('good_ladder', []);
+        $is_support_barter = $this->request->filter('trim')->post('is_support_barter/d', 1);
+        $spucode = makeNo("SKU");
+        $data = [
+            "spuCode" => $spucode,
+            "good_code" => '',
+            "good_name" => $good_name,
+            "cat_id" => $cat_id,
+            'brand_id' => $brandid,
+            "good_unit" => $unit,
+            "good_type" => $good_type,
+            "moq" => $moq,
+            "is_exclusive" => $is_exclusive,
+            "customized" => $customized,
+            "companyNo" => $companyNo,
+            "tax" => $tax,
+            "supplierNo" => $supplierNo,
+            "good_size" => $good_size,
+            "is_auth" => $is_auth,
+            "is_stock" => $is_stock,
+            "auth_img" => $auth_img,
+            "after_sales" => $after_sales,
+            "craft_desc" => $craft_desc,
+            "good_remark" => $good_remark,
+            "weight" => $weight,
+            "packing_way" => $packing_way,
+            "packing_size" => $packing_size,
+            "packing_spec" => $packing_spec,
+            "packing_list" => $packing_list,
+            "packing_weight" => $packing_weight,
+            "good_bar" => $good_bar,
+            "supply_area" => $supply_area,
+            "delivery_place" => implode(',', $delivery_place),
+            "origin_place" => implode(',', $origin_place),
+            "delivery_day" => $delivery_day,
+            "lead_time" => $lead_time,
+            "sample_day" => $sample_day,
+            "sample_fee" => $sample_fee,
+            "good_img" => implode(',', $good_img),
+            "good_thumb_img" => $good_thumb_img,
+            "good_info_img" => implode(',', $good_info_img),
+            "cert_fee" => $cert_fee,
+            "packing_fee" => $packing_fee,
+            "cost_fee" => $cost_fee,
+            "mark_fee" => $mark_fee,
+            "demo_fee" => $demo_fee,
+            "open_fee" => $open_fee,
+            "noble_metal" => $noble_metal,
+            "cgd_gold_price" => $cgd_gold_price,
+            "noble_weight" => $noble_weight,
+            "is_gold_price" => $is_gold_price,
+            "market_price" => $market_price,
+            "nake_price" => $nake_price,
+            "is_diff" => $is_diff,
+            "config" => $config,
+            "other_config" => $other_config,
+            "field_change" => '',
+            "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
+            "is_online" => 0,
+            "stock_moq" => $stock_moq,
+            "status" => 1,//1审核通过
+            "createrid" => request()->supplier['personid'],
+            "creater" => request()->supplier['person'],
+            "addtime" => date("Y-m-d H:i:s"),
+            "updatetime" => date("Y-m-d H:i:s"),
+            'is_support_barter' => $is_support_barter
+        ];
+        return GoodLogic::createGood($spucode, $data, $speclist, $good_ladder);
+
+    }
+
+    //修改商品基础信息
+    public function updateGoodBasicsInfo()
+    {
+        $param = $this->request->filter('trim')->only([
+            'spuCode',//商品spuCode
+            'good_name',//商品名称
+            'cat_id',//分类id
+            'brand_id',//商品品牌id
+            'companyNo',//业务公司编码
+            'good_unit',//商品单位
+            'after_sales',//售后说明
+            'craft_desc',//工艺说明
+            'good_remark',//商品备注
+            'good_size',//商品尺寸
+            'weight',//商品重量
+            'packing_way',//包装方式
+            'packing_size',//装箱尺寸
+            'packing_spec',//装箱规格
+            'packing_list',//包装清单
+            'packing_weight',//装箱重量
+            'good_bar',//商品条形码
+            'supply_area',//供货区域
+            'delivery_place',//发货地
+            'origin_place',//产地
+            'delivery_day',//物流时间
+            'lead_time',//供货周期
+            'sample_day',//调样周期
+            'good_img',//商品详情主图
+            'good_thumb_img',//商品缩略图
+            'good_info_img',//商品详情图
+            'config',//配置
+            'other_config',//其他配置
+        ], 'post');
+
+        validate(GoodValidate::class)->scene('UpdateGoodBasicsInfo')->check($param);
+
+        if (isset($param['cat_id'])) {
+            $cat = Db::name('cat')->field('id')->where(['id' => $param['cat_id'], 'is_del' => 0])->findOrEmpty();
+            if (empty($cat)) return json_show(1004, '分类不存在');
+        }
+
+        if (isset($param['brand_id'])) {
+            $brand = Db::name('brand')->field('id')->where(['id' => $param['brand_id'], 'is_del' => 0])->findOrEmpty();
+            if (empty($brand)) return json_show(1004, '品牌不存在');
+        }
+
+        if (isset($param['good_unit'])) {
+            $unit_info = Db::name('unit')->field('id')->where(['id' => $param['good_unit'], 'is_del' => 0])->findOrEmpty();
+            if (empty($unit_info)) return json_show(1004, '单位不存在');
+        }
+
+        if (isset($param['companyNo'])) {
+            $company = Db::name('business')->field('id')->where(['companyNo' => $param['companyNo'], 'is_del' => 0])->findOrEmpty();
+            if (empty($company)) return json_show(1004, '业务公司不存在');
+        }
+
+        if (isset($param['delivery_place']) || isset($param['origin_place'])) {
+
+            $province = Db::name('province')
+                ->whereIn('province_code', [$param['delivery_place'][0], $param['origin_place'][0]])
+                ->column('id', 'province_code');
+            if (empty($province[$param['delivery_place'][0]])) return json_show(1004, '发货地数据不规范,省份编码不存在');
+            if (empty($province[$param['origin_place'][0]])) return json_show(1004, '产地数据不规范,省份编码不存在');
+
+
+            $city = Db::name('city')
+                ->where(function ($query) use ($param) {
+                    return $query->where(['city_code' => $param['delivery_place'][1], 'province_code' => $param['delivery_place'][0]]);
+                })->whereOr(function ($query) use ($param) {
+                    return $query->where(['city_code' => $param['origin_place'][1], 'province_code' => $param['origin_place'][0]]);
+                })->column('id', 'city_code');
+            if (empty($city[$param['delivery_place'][1]])) return json_show(1004, '发货地数据不规范,城市编码不存在');
+            if (empty($city[$param['origin_place'][1]])) return json_show(1004, '产地数据不规范,城市编码不存在');
+
+            $area = Db::name('area')
+                ->where(function ($query) use ($param) {
+                    return $query->where(['area_code' => $param['delivery_place'][2], 'city_code' => $param['delivery_place'][1]]);
+                })->whereOr(function ($query) use ($param) {
+                    return $query->where(['area_code' => $param['origin_place'][2], 'city_code' => $param['origin_place'][1]]);
+                })->column('id', 'area_code');
+            if (empty($area[$param['delivery_place'][2]])) return json_show(1004, '发货地数据不规范,县区编码不存在');
+            if (empty($area[$param['origin_place'][2]])) return json_show(1004, '产地数据不规范,县区编码不存在');
+
+        }
+
+        return GoodLogic::updateGoodBasicsInfo($param['spuCode'], $param);
+
+    }
+
+    //修改商品价格信息
+    public function updateGoodPriceInfo()
+    {
+        $param = $this->request->filter('trim')->only([
+            'spuCode',//商品spuCode
+            'tax',//税点
+            'sample_fee',//调样费有
+            'cert_fee' => 0.00,//证书费
+            'packing_fee' => 0.00,//包装费
+            'cost_fee' => 0.00,//工艺费
+            'mark_fee' => 0.00,//加标费
+            'demo_fee' => 0.00,//打样费
+            'open_fee' => 0.00,//开模费
+            'noble_metal' => 0,//贵金属种类
+            'noble_weight' => 0,//贵金属重量
+            'is_gold_price' => 0,//是否使用实时金价
+            'cgd_gold_price' => 0,//供应商采购金价
+            'market_price' => 0,//市场价
+            'nake_price' => 0,//含税成本价
+//            'speclist' => [],//规格列表
+//            'good_ladder' => [],//阶梯成本列表
+            'is_support_barter' => 1,//是否可退货
+        ], 'post');
+
+        validate(GoodValidate::class)->scene('updateGoodPriceInfo')->check($param);
+
+        //规格,阶梯成本,如何修改?
+        return GoodLogic::updateGoodPriceInfo($param['spuCode'], $param);
+
+    }
+
+    //获取商品详情
+    public function read()
+    {
+
+        $param = $this->request->filter('trim')->only(['spuCode'], 'post');
+
+        validate(GoodValidate::class)->scene('read')->check($param);
+
+        return GoodLogic::read($param['spuCode']);
+    }
+
+
+}

+ 39 - 0
app/abutment/controller/GoodUp.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace app\abutment\controller;
+
+use app\abutment\logic\GoodUp as GoodUpLogic;
+use app\BaseController;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+//商品上线模块
+class GoodUp extends BaseController
+{
+    //申请商品上线
+    public function create()
+    {
+        $param = $this->request->filter('trim')->only(['spuCodes', 'online_reason', 'online_remark' => '', 'platform_id'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.GoodUpCreate'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return GoodUpLogic::create($param);
+    }
+
+    //商品上线列表
+    public function list()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.common'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return GoodUpLogic::list($param);
+    }
+
+
+}

+ 130 - 0
app/abutment/controller/Index.php

@@ -0,0 +1,130 @@
+<?php
+
+namespace app\abutment\controller;
+
+use app\abutment\logic\Index as IndexLogic;
+use app\BaseController;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+
+class Index extends BaseController
+{
+    //获取token
+    public function login()
+    {
+
+        $param = $this->request->filter('trim')->only(['username', 'password'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.login'));
+
+        if(!$val->check($param)) return json_show(1004, $val->getError());
+
+        return IndexLogic::login($param);
+    }
+
+    //获取上线平台列表
+    public function getPlatformList()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.common'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getPlatformList($param['keyword'], $param['page'], $param['size']);
+
+    }
+
+    //获取分类列表
+    public function getCatList()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => '', 'pid' => 0], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.getCatList'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getCatList($param['keyword'], $param['pid']);
+    }
+
+    //获取品牌列表
+    public function getBrandList()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.common'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getBrandList($param['keyword'], $param['page'], $param['size']);
+    }
+
+    //获取单位列表
+    public function getUnitList()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.common'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getUnitList($param['keyword'], $param['page'], $param['size']);
+
+    }
+
+    //获取规格标题列表
+    public function getSpecsTitleList()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => ''], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.keyword'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getSpecsTitleList($param['keyword']);
+
+    }
+
+    //获取规格值列表
+    public function getSpecsValueByTitleList()
+    {
+        $param = $this->request->filter('trim')->only(['spec_id'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.getSpecsValueByTitleList'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getSpecsValueByTitleList($param['spec_id']);
+
+    }
+
+    //获取省市区列表
+    public function getAreaList()
+    {
+        $param = $this->request->filter('trim')->only(['level' => 1, 'pid_code' => ''], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.getAreaList'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getAreaList($param['level'], $param['pid_code']);
+    }
+
+    //获取业务公司编码
+    public function getCompanyNoList()
+    {
+        $param = $this->request->filter('trim')->only(['keyword' => ''], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.keyword'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return IndexLogic::getCompanyNoList($param['keyword']);
+    }
+
+
+
+
+}

+ 353 - 0
app/abutment/logic/Account.php

@@ -0,0 +1,353 @@
+<?php
+
+namespace app\abutment\logic;
+
+use app\abutment\model\SupplierUser as SupplierUserModel;
+use app\abutment\model\SupplierRelationUser as SupplierRelationUserModel;
+use app\abutment\model\SupplierUser;
+use think\Exception;
+use think\facade\Cache;
+use think\facade\Config;
+use think\facade\Db;
+use think\helper\Str;
+
+
+//供应商账号管理
+class Account
+{
+
+    //登录
+    public static function login(array $param = [])
+    {
+
+        $db = new SupplierUserModel();
+
+        $res = $db->where([
+            'is_del' => $db::$is_del_normal,
+            'mobile' => $param['mobile']
+        ])
+            ->findOrEmpty()
+            ->toArray();
+
+        if (empty($res)) return json_show(1004, '该账号不存在');
+        if ($res['status'] == $db::$status_disabled) return json_show(1004, '该账号已禁用');
+
+        $password = get_encryption_password($param['password'], $res['salt']);
+        if ($password['password'] != $res['password']) return json_show(1004, '密码错误');
+
+        //更新token
+        $token = Str::random(40, -1);
+        $expire_time = date('Y-m-d H:i:s', time() + mt_rand(3600, 7200));
+
+        $rs = $db
+            ->where($db->getPk(), $res[$db->getPk()])
+            ->save(['token' => $token, 'expire_time' => $expire_time]);
+
+        if (!$rs) throw new Exception('更新账号token信息失败');
+
+        $list = SupplierRelationUserModel::field('id,supplierNo,supplierName')
+            ->where([
+                'is_del' => $db::$is_del_normal,
+                'uid' => $res['uid'],
+            ])
+            ->select()
+            ->toArray();
+
+        $info = [
+            'uid' => $res['uid'],
+            'nickname' => $res['nickname'],
+            'mobile' => $res['mobile'],
+            'email' => $res['email'],
+            'token' => $token,
+            'expire_time' => $expire_time,
+            'supplier_list' => $list,
+        ];
+
+        Cache::set(Config::get('redis_key.user_info_token') . $token, json_encode($info), $expire_time);
+
+        return json_show(0, '登录成功', $info);
+
+
+    }
+
+    //获取供应商下普通账号列表
+    public static function geAccounttList(array $param = [])
+    {
+
+        $db = new SupplierRelationUserModel();
+
+        $rs = $db
+            ->alias('a')
+            ->leftJoin('supplier_user b', 'b.uid=a.uid AND b.is_del=0')
+            ->where([
+                'a.is_del' => $db::$is_del_normal,
+                'a.supplierNo' => $param['supplierNo'],
+            ]);
+
+        if ($param['keyword'] != '') $rs->whereLike('b.nickname|b.mobile', '%' . $param['keyword'] . '%');
+
+        $count = $rs->count('a.id');
+
+        $list = $rs
+            ->field('a.id,b.uid,b.nickname,b.mobile,b.email,a.status')
+            ->order('a.addtime', 'desc')
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+
+        return json_show(0, '获取成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //修改密码
+    public static function changePassword(array $param = [])
+    {
+
+        $db = new SupplierUserModel();
+
+        $res = $db
+            ->where([
+                'uid' => $param['uid'],
+                'is_del' => $db::$is_del_normal,
+            ])
+            ->field('uid,password,salt,status,is_del')
+            ->findOrEmpty()
+            ->toArray();
+
+        if (empty($res)) return json_show(1004, '该账号不存在');
+        if ($res['status'] == $db::$status_disabled) return json_show(1004, '该账号已禁用');
+
+        $old_password = get_encryption_password($param['old_password'], $res['salt']);
+        if ($old_password['password'] != $res['password']) return json_show(1004, '密码错误');
+
+        //更新密码
+        $password = get_encryption_password($param['new_password']);
+
+        $rs = $db
+            ->where($db->getPk(), $res[$db->getPk()])
+            ->save(['password' => $password['password'], 'salt' => $password['salt']]);
+
+        return $rs ? json_show(0, '修改密码成功') : json_show(1005, '修改密码失败');
+
+    }
+
+    //获取账号信息
+    public static function readAccount(array $param = [])
+    {
+        $res = SupplierUser::field('uid,nickname,mobile,email')
+            ->where([
+                'uid' => $param['uid'],
+                'is_del' => SupplierUser::$is_del_normal,
+            ])
+            ->append(['supplier_list'])
+            ->withAttr('supplier_list', function ($val, $data) {
+
+                return SupplierRelationUserModel::field('id,supplierNo,supplierName,status,addtime')
+                    ->where([
+                        'is_del' => SupplierUser::$is_del_normal,
+                        'uid' => $data['uid']
+                    ])
+                    ->select()
+                    ->toArray();
+            })
+            ->findOrEmpty()
+            ->toArray();
+
+        return json_show(0, '获取账号信息成功', $res);
+
+    }
+
+    //添加供应商账号
+    public static function addAccount(array $param = [])
+    {
+
+        Db::connect('mysql_sys')->startTrans();
+
+        try {
+
+            $db = new SupplierUserModel();
+
+            $res = $db
+                ->field('uid,status')
+                ->where([
+                    'is_del' => $db::$is_del_normal,
+                    'mobile' => $param['mobile'],
+                ])->findOrEmpty();
+
+            $is_insert = true;
+            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,
+                ]);
+
+                $res->status = $db::$status_normal;
+
+            } else {
+
+                $rs = SupplierRelationUserModel::field('id')
+                    ->where([
+                        'is_del' => $db::$is_del_normal,
+                        'uid' => $res->uid,
+                        'supplierNo' => $param['supplierNo'],
+                    ])->findOrEmpty()
+                    ->isEmpty();
+
+                if (!$rs) $is_insert = false;//该关联关系已存在,无需新增
+
+            }
+
+            if ($is_insert) {
+                SupplierRelationUserModel::create([
+                    'uid' => $res->uid,
+                    'supplierNo' => $param['supplierNo'],
+                    'supplierName' => $param['supplierName'],
+                    'status' => $res->status,
+                    'is_del' => $db::$is_del_normal,
+                ])->save();
+            }
+
+            Db::connect('mysql_sys')->commit();
+            return json_show(0, '操作成功');
+        } catch (Exception $exception) {
+            Db::connect('mysql_sys')->rollback();
+            return json_show(1005, '操作失败' . $exception->getMessage());
+        }
+
+    }
+
+    //修改供应商账号
+    public static function editAccount(array $param = [])
+    {
+
+        Db::connect('mysql_sys')->startTrans();
+
+        try {
+
+            $db = new SupplierUserModel();
+
+            $res = $db
+                ->where('is_del', $db::$is_del_normal)
+                ->whereIn('mobile', [$param['mobile'], $param['old_mobile']])
+                ->column('uid,status', 'mobile');
+
+            $is_insert = true;
+            if (!isset($res[$param['mobile']])) {
+                //新增账号
+                $password = get_encryption_password(Config::get('app.default_password'));
+                $res[$param['mobile']]['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,
+                ]);
+
+                $res[$param['mobile']]['status'] = $db::$status_normal;
+
+            } else {
+
+                $rs = SupplierRelationUserModel::field('id')
+                    ->where([
+                        'is_del' => $db::$is_del_normal,
+                        'uid' => $res[$param['mobile']]['uid'],
+                        'supplierNo' => $param['supplierNo'],
+                    ])->findOrEmpty()
+                    ->isEmpty();
+
+                if (!$rs) $is_insert = false;//该关联关系已存在,无需新增
+
+            }
+
+            if ($is_insert) {
+                SupplierRelationUserModel::create([
+                    'uid' => $res[$param['mobile']]['uid'],
+                    'supplierNo' => $param['supplierNo'],
+                    'supplierName' => $param['supplierName'],
+                    'status' => $res[$param['mobile']]['status'],
+                    'is_del' => $db::$is_del_normal,
+                ])->save();
+            }
+            //把旧的账号的关联关系解除
+            SupplierRelationUserModel::where([
+                'is_del' => $db::$is_del_normal,
+                'uid' => $res[$param['old_mobile']]['uid'],
+                'supplierNo' => $param['supplierNo'],
+            ])->save(['is_del' => $db::$is_del_deleted]);
+
+            Db::connect('mysql_sys')->commit();
+            return json_show(0, '操作成功');
+        } catch (Exception $exception) {
+            Db::connect('mysql_sys')->rollback();
+            return json_show(1005, '操作失败,' . $exception->getMessage());
+        }
+
+    }
+
+    //修改供应商账号状态
+    public static function statusAccount(array $param = [])
+    {
+
+        Db::connect('mysql_sys')->startTrans();
+
+        try {
+
+            $db = new SupplierUserModel();
+
+            $res = $db
+                ->field('uid')
+                ->where([
+                    'is_del' => $db::$is_del_normal,
+                    'mobile' => $param['mobile'],
+                ])->findOrEmpty();
+
+            if (!$res->isEmpty()) {
+
+                $rs = SupplierRelationUserModel::field('id')->where([
+                    'is_del' => $db::$is_del_normal,
+                    'uid' => $res->uid,
+                    'supplierNo' => $param['supplierNo'],
+                ])
+                    ->where('status', '<>', $param['status'])
+                    ->findOrEmpty();
+
+                if ($rs->isEmpty()) throw new Exception('当前供应商账号未与当前供应商绑定或重复操作');
+                else SupplierRelationUserModel::where('id', $rs->id)->save(['status' => $param['status']]);
+
+            } else throw new Exception('当前供应商账号不存在');
+
+            Db::connect('mysql_sys')->commit();
+            return json_show(0, '操作成功');
+        } catch (Exception $exception) {
+            Db::connect('mysql_sys')->rollback();
+            return json_show(1005, '操作失败,' . $exception->getMessage());
+        }
+
+    }
+
+    //删除供应商账号
+    public static function deleteAccount(array $param = [])
+    {
+
+        $where = [['is_del', '=', SupplierUserModel::$is_del_normal]];
+
+        if (isset($param['supplierNo']) && $param['supplierNo'] != '') $where[] = ['supplierNo', '=', $param['supplierNo']];
+        if (isset($param['id']) && $param['id'] != '') $where[] = ['id', '=', $param['id']];
+
+        $res = SupplierRelationUserModel::where($where)
+            ->save(['is_del' => SupplierUserModel::$is_del_deleted]);
+
+        return $res ? json_show(0, '操作成功') : json_show(1005, '操作失败');
+
+    }
+
+}

+ 190 - 0
app/abutment/logic/Good.php

@@ -0,0 +1,190 @@
+<?php
+
+
+namespace app\abutment\logic;
+
+use think\Exception;
+use think\facade\Db;
+
+class Good
+{
+    //获取商品列表
+    public static function list(array $param = [])
+    {
+        $db = Db::name('good_basic')
+            ->alias('a')
+            ->where(['a.supplierNo' => request()->supplier['supplierNo'], 'a.is_del' => 0]);
+//            ->where('createrid', request()->user['id'])//创建人都取的是供应商的负责人,后面商品的创建人会转化成订单的采购员
+
+        if ($param['keyword'] != '') $db->whereLike('spuCode|good_name', '%' . $param['keyword'] . '%');
+
+        $count = $db->count('id');
+
+        $list = $db
+            ->field('a.id,a.spuCode,a.good_thumb_img,a.good_name,a.cat_id,"" cat_name,a.brand_id,b.brand_name,a.companyNo,c.company,a.addtime')
+            ->leftJoin('brand b', 'b.id=a.brand_id')
+            ->leftJoin('business c', 'c.companyNo=a.companyNo')
+            ->withAttr('cat_name', function ($val, $data) {
+                return made($data['cat_id']);
+            })
+            ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //创建商品
+    public static function createGood(string $spucode = '', array $data = [], array $speclist = [], array $good_ladder = [])
+    {
+
+        Db::startTrans();
+        try {
+
+            $in = Db::name("good_basic")->insertGetId($data);
+            if ($in) {
+//                if ($speclist !== "" && !empty($speclist)) {
+                $temp = [];
+
+                foreach ($speclist as $value) {
+                    $lemp = [];
+                    $lemp['spuCode'] = $spucode;
+                    $lemp['spec_id'] = $value['spec_id'];
+                    $lemp['spec_value_id'] = $value['spec_value_id'];
+                    $lemp['addtime'] = date("Y-m-d H:i:s");
+                    $lemp['updatetime'] = date("Y-m-d H:i:s");
+                    $temp[] = $lemp;
+                }
+
+                if ($temp) Db::name("good_spec")->insertAll($temp);
+//                }
+//                $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
+//                $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
+                $top_cat_id = made($data['cat_id']);//获取所有分类
+                $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
+                if ($good_ladder !== "" && !empty($good_ladder)) {
+                    $temp = [];
+
+                    foreach ($good_ladder as $value) {
+                        $lemp = [];
+                        $lemp['spuCode'] = $spucode;
+                        $lemp['min_num'] = $value['min_num'];
+                        $lemp['nake_fee'] = $value['nake_fee'];
+                        $lemp['cost_fee'] = $value['cost_fee'];
+                        $lemp['delivery_fee'] = $value['delivery_fee'];
+                        $lemp['cert_fee'] = $value['cert_fee'];
+                        $lemp['mark_fee'] = $value['mark_fee'];
+                        $lemp['package_fee'] = $value['package_fee'];
+                        $lemp['other_fee'] = $value['other_fee'];
+                        if ($data['is_gold_price'] == 1 && $top_cat_id == 6) {
+
+                            //$data['is_gold_price']==1 表示启用实时金价,cat_id==6表示贵金属
+                            $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
+                            //$lemp['nake_total'] = $data['noble_weight'] * $gold['price'] + $value['cost_fee'] * $data['noble_weight'] + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
+                            //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
+                            //成本总计启用实时金价时,采用供应商实时金价
+                            $lemp['nake_total'] = $data['noble_weight'] * $gold['price'] + $value['cost_fee'] * $data['noble_weight'] + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
+
+                        } else $lemp['nake_total'] = $value['nake_fee'] + $value['delivery_fee'] + $value['cert_fee'] + $value['mark_fee'] + $value['package_fee'] + $value['other_fee'];
+
+//                        $lemp['creater_id'] = $createrid;
+//                        $lemp['creater'] = $creater;
+                        $lemp['is_del'] = 0;
+                        $lemp['addtime'] = date("Y-m-d H:i:s");
+                        $lemp['updatetime'] = date("Y-m-d H:i:s");
+                        $temp[] = $lemp;
+                    }
+                    $count = Db::name("good_nake")->insertAll($temp);
+                    if ($count == 0) throw new Exception('商品规格值创建失败');
+                }
+
+                Db::commit();
+                return json_show(0, "商品创建成功", ['spuCode' => $spucode]);
+
+            } else throw new Exception('商品创建失败');
+        } catch (Exception $e) {
+            Db::rollback();
+            return json_show(1004, $e->getMessage());
+        }
+    }
+
+    //修改商品基础信息
+    public static function updateGoodBasicsInfo(string $spuCode = '', array $data = [])
+    {
+        $res = Db::name("good_basic")
+            ->field('id')
+            ->where('is_del', 0)
+            ->where('spuCode', $spuCode)
+            ->find();
+
+        if (empty($res)) return json_show(1005, '该条商品数据不存在');
+
+        if (isset($data['delivery_place'])) $data['delivery_place'] = implode(',', $data['delivery_place']);
+        if (isset($data['origin_place'])) $data['origin_place'] = implode(',', $data['origin_place']);
+        if (isset($data['good_img'])) $data['good_img'] = implode(',', $data['good_img']);
+        if (isset($data['good_info_img'])) $data['good_info_img'] = implode(',', $data['good_info_img']);
+        $data['updatetime'] = date('Y-m-d H:i:s');
+
+        $rs = Db::name('good_basic')
+            ->where('id', $res['id'])
+            ->update($data);
+
+        return $rs ? json_show(0, '修改商品基础信息成功') : json_show(1005, '修改商品基础信息失败');
+
+    }
+
+    //修改商品价格信息
+    public static function updateGoodPriceInfo(string $spuCode = '', array $data = [])
+    {
+        $res = Db::name("good_basic")
+            ->field('id')
+            ->where('is_del', 0)
+            ->where('spuCode', $spuCode)
+            ->find();
+
+        if (empty($res)) return json_show(1005, '该条商品数据不存在');
+
+        //校验该商品是否上线,上线的话不允许修改价格相关信息
+        $rs = Db::name('good_platform')
+            ->field('id')
+            ->where(['is_del' => 0, 'spuCode' => $spuCode, 'exam_status' => 6])
+            ->findOrEmpty();
+
+        if (!empty($rs)) return json_show(1005, '不允许修改上线中的商品价格信息');
+
+
+        $data['updatetime'] = date("Y-m-d H:i:s");
+//        "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
+
+        $rs = Db::name('good_basic')
+            ->strict(false)
+            ->where('id', $res['id'])
+            ->update($data);
+
+        return $rs ? json_show(0, '修改商品价格信息成功') : json_show(1005, '修改商品价格信息失败');
+
+    }
+
+    //获取商品详情
+    public static function read(string $spuCode = '')
+    {
+        $res = Db::name("good_basic")
+            ->withoutField('good_code,createrid,creater,field_change')
+            ->where('is_del', 0)
+            ->where('spuCode', $spuCode)
+            ->withAttr('good_img', function ($val) {
+                return explode(',', $val);
+            })
+            ->withAttr('good_info_img', function ($val) {
+                return explode(',', $val);
+            })
+            ->findOrEmpty();
+
+        return json_show(0, '获取商品详情成功', $res);
+
+    }
+
+
+}

+ 158 - 0
app/abutment/logic/GoodUp.php

@@ -0,0 +1,158 @@
+<?php
+
+namespace app\abutment\logic;
+
+use app\admin\model\ActionLog;
+use app\admin\model\ProcessOrder;
+use think\Exception;
+use think\exception\ValidateException;
+use think\facade\Db;
+
+//商品上线模块
+class GoodUp
+{
+
+    //申请商品上线
+    public static function create(array $data = [])
+    {
+        //校验平台是否存在
+        $rs = Db::name('platform')
+            ->field('id,platform_type')
+            ->where(['id' => $data['platform_id'], 'is_del' => 0])
+            ->findOrEmpty();
+        if (empty($rs)) throw new ValidateException('该平台id不存在');
+
+
+        //校验是否存在已上线商品
+        $res = Db::name('good_platform')
+            ->where(['platform_code' => $data['platform_id'], 'is_del' => 0])
+            ->where('exam_status', '<=', 6)
+            ->whereIn('spuCode', $data['spuCodes'])
+            ->column('spuCode');
+
+        if (!empty($res)) return json_show(1005, '以下商品编码已存在该平台的上线申请', $res);
+
+        //校验商品数据
+        $good_data = Db::name('good_basic')
+            ->field('id,spuCode')
+            ->where('is_del', 0)
+            ->whereIn('spuCode', $data['spuCodes'])
+            ->select()
+            ->toArray();
+
+        if (empty($good_data)) return json_show(1005, '未找到商品数据');
+
+        if ($rs['platform_type'] == 1) return \app\youzan\logic\Goodup::create([
+            'platform_id' => $data['platform_id'],
+            'online_reason' => $data['online_reason'],
+            'online_remark' => $data['online_remark'],
+            'good_data' => $good_data,
+            'createrid' => request()->user['user_id'],
+            'creater' => request()->user['nickname'],
+        ]);
+
+        $spuCode_count = Db::name("good_nake")
+            ->where(["is_del" => 0])
+            ->whereIn('spuCode', $data['spuCodes'])
+            ->group('spuCode')
+            ->column('count(`id`) total', 'spuCode');
+
+        $i = 0;
+        Db::startTrans();
+        try {
+            foreach ($good_data as $value) {
+
+                //改变编码规则,将原来的skuCode后两位换成序列号
+                //str_pad字符串填充
+                $skuCode = makeNo("SN");
+                $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
+                $tmp = [
+                    "spuCode" => $value['spuCode'],
+                    "skuCode" => $skuCode,
+                    "platform_code" => $data['platform_id'],
+                    "online_reason" => $data['online_reason'],
+                    "online_remark" => $data['online_remark'],
+                    "exam_status" => $spuCode_count[$value['spuCode']] > 0 ? 2 : 1,
+                    "is_online" => 0,
+                    "status" => 1,
+                    "is_del" => 0,
+                    "creater" => $value['creater'],
+                    "createrid" => $value['createrid'],
+                    "addtime" => date("Y-m-d H:i:s"),
+                    "updatetime" => date("Y-m-d H:i:s")
+                ];
+                $i++;
+                //修改状态,添加待办
+                $create = Db::name("good_platform")->insertGetId($tmp);
+                if ($create > 0) {
+                    ActionLog::logAdd(['id' => request()->user['user_id'], 'nickname' => request()->user['nickname']], [
+                        "order_code" => $skuCode,//咨询单详情编号
+                        "status" => $tmp['exam_status'],//这里的status是之前的值
+                        "action_remark" => '',//备注
+                        "action_type" => "create"//新建create,编辑edit,更改状态status
+                    ], "SPSX", $tmp['exam_status'], $tmp);
+
+                    ProcessOrder::AddProcess(['id' => request()->user['user_id'], 'nickname' => request()->user['nickname']], [
+                        "order_type" => 'SPSX',
+                        "order_code" => $skuCode,//咨询单详情编号
+                        "order_id" => $create,
+                        "order_status" => $tmp['exam_status'], "before_status" => $tmp['exam_status']
+                    ]);
+                    $iso = Db::name("good")
+                        ->field('id')
+                        ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
+                        ->find();
+                    if ($iso == false) {
+                        unset($value['id']);
+
+                        $value['addtime'] = date("Y-m-d H:i:s");
+                        $value['updatetime'] = date("Y-m-d H:i:s");
+                    } else {
+                        $value['id'] = $iso['id'];
+                        $value['updatetime'] = date("Y-m-d H:i:s");
+                    }
+                    $up = Db::name("good")->save($value);
+                    if (!$up) throw new Exception('提交失败');
+                } else  throw new Exception('提交失败');
+            }
+
+            Db::commit();
+            return json_show(0, "提交商品上线申请成功");
+        } catch (Exception $e) {
+            Db::rollback();
+            throw new ValidateException('提交商品上线申请失败,' . $e->getMessage());
+        }
+
+    }
+
+    //列表
+    public static function list(array $param = [])
+    {
+
+        $db = Db::name('good_platform')
+            ->alias('a')
+            ->leftJoin('good_basic b', 'b.spuCode=a.spuCode AND b.is_del=0')
+            ->leftJoin('platform p', 'p.id=a.platform_code AND p.is_del=0')
+            ->leftJoin('brand c', 'c.id=b.brand_id AND c.is_del=0')
+            ->leftJoin('business d', 'd.companyNo=b.companyNo AND d.is_del=0')
+            ->where(['a.createrid' => request()->user['user_id'], 'a.is_del' => 0]);
+
+        if ($param['keyword'] != '') $db->whereLike('a.spuCode|b.good_name', '%' . $param['keyword'] . '%');
+
+        $count = $db->count('a.id');
+
+        $list = $db
+            ->field('a.id,a.spuCode,a.skuCode,b.good_thumb_img,b.good_name,p.platform_name,a.exam_status,b.cat_id,"" cat_name,b.is_stock,c.brand_name,b.companyNo,d.company,a.plat_code,a.creater,a.addtime')
+            ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
+            ->page($param['page'], $param['size'])
+            ->withAttr('cat_name', function ($val, $da) {
+                return implode('/', array_column(made($da['cat_id']), 'name'));
+            })
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
+    }
+
+
+}

+ 204 - 0
app/abutment/logic/Index.php

@@ -0,0 +1,204 @@
+<?php
+
+namespace app\abutment\logic;
+
+use think\facade\Config;
+use think\facade\Db;
+
+class Index
+{
+
+    //获取token
+    public static function login(array $param = [])
+    {
+        $res = curl_request(Config::get('common.login_domain'), $param);
+        $res = json_decode($res, true);
+
+        if (!isset($res['code']) || $res['code'] != 0) return json_show($res['code'], $res['message']);
+
+        //查询该用户所关联的供应商
+        $list = Db::name('abutment_user_supplier')
+            ->alias('a')
+            ->field('a.id,a.supplierNo,b.supplier,b.clientID')
+            ->leftJoin('abutment_supplier_development b', 'b.supplierNo=a.supplierNo AND b.is_del=0')
+            ->where(['a.is_del' => 0, 'a.uid' => $res['data']['userinfo']['user_id']])
+            ->select()
+            ->toArray();
+
+        return json_show(0, '获取token成功', ['token' => $res['data']['token'], 'list' => $list]);
+
+    }
+
+
+    //获取上线平台列表
+    public static function getPlatformList(string $keyword = '', int $page = 1, int $size = 15)
+    {
+
+        $db = Db::name('platform')->where('is_del', 0);
+
+        if ($keyword != '') $db->whereLike('platform_name', '%' . $keyword . '%');
+
+        $count = $db->count('id');
+
+        $list = $db
+            ->field('id platform_id,platform_code,platform_name,platform_type')
+            ->order('id')
+            ->page($page, $size)
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //获取分类列表
+    public static function getCatList(string $keyword = '', int $pid = 0)
+    {
+
+        $db = Db::name('cat')->where(['is_del' => 0, 'pid' => $pid]);
+
+        if ($keyword != '') $db->whereLike('cat_name', '%' . $keyword . '%');
+
+        $count = $db->count('id');
+
+        $list = $db
+            ->field('id cat_id,cat_name,level')
+            ->order('id')
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //获取品牌列表
+    public static function getBrandList(string $keyword = '', int $page = 1, int $size = 15)
+    {
+
+        $db = Db::name('brand')->where('is_del', 0);
+
+        if ($keyword != '') $db->whereLike('brand_name', '%' . $keyword . '%');
+
+        $count = $db->count('id');
+
+        $list = $db
+            ->field('id brand_id,brand_name')
+            ->order('id')
+            ->page($page, $size)
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //获取单位列表
+    public static function getUnitList(string $keyword = '', int $page = 1, int $size = 15)
+    {
+
+        $db = Db::name('unit')->where('is_del', 0);
+
+        if ($keyword != '') $db->whereLike('unit', '%' . $keyword . '%');
+
+        $count = $db->count('id');
+
+        $list = $db
+            ->field('id unit_id,unit unit_name')
+            ->order('id')
+            ->page($page, $size)
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //获取规格标题列表
+    public static function getSpecsTitleList(string $keyword = '')
+    {
+
+        $db = Db::name('specs')->where('is_del', 0);
+
+        if ($keyword != '') $db->whereLike('spec_name', '%' . $keyword . '%');
+
+        $list = $db
+            ->field('id spec_id,spec_name')
+            ->order('addtime', 'desc')
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', $list);
+
+    }
+
+    //获取规格值列表
+    public static function getSpecsValueByTitleList(int $spec_id = 0)
+    {
+
+        $db = Db::name('spec_value')->where('is_del', 0);
+
+        if ($spec_id != '') $db->where('spec_id', $spec_id);
+
+        $list = $db
+            ->field('id spec_value_id,spec_id ,spec_value')
+            ->order('id')
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', $list);
+
+    }
+
+    //获取省市区列表
+    public static function getAreaList(int $level = 1, string $pid_code = '')
+    {
+
+        switch ($level) {
+            case 1:
+                $list = Db::name('province')
+                    ->field('province_code,name')
+                    ->order('id')
+                    ->select()
+                    ->toArray();
+                break;
+            case 2:
+                $list = Db::name('city')
+                    ->field('city_code,name')
+                    ->where('province_code', $pid_code)
+                    ->order('id')
+                    ->select()
+                    ->toArray();
+                break;
+            case 3:
+                $list = Db::name('area')
+                    ->field('area_code,name')
+                    ->where('city_code', $pid_code)
+                    ->order('id')
+                    ->select()
+                    ->toArray();
+                break;
+        }
+
+        return json_show(0, '获取成功', $list);
+    }
+
+    //获取业务公司编码
+    public static function getCompanyNoList(string $keyword = '')
+    {
+
+        $db = Db::name('business')->where('is_del', 0);
+
+        if ($keyword != '') $db->whereLike('company|companyNo', '%' . $keyword . '%');
+
+        $list = $db
+            ->field('companyNo,company')
+            ->order('id')
+            ->select()
+            ->toArray();
+
+        return json_show(0, '请求成功', $list);
+
+    }
+
+
+}

+ 7 - 0
app/abutment/middleware.php

@@ -0,0 +1,7 @@
+<?php
+
+//中间件定义
+
+return [
+    app\abutment\middleware\apiMiddleware::class,
+];

+ 147 - 0
app/abutment/middleware/apiMiddleware.php

@@ -0,0 +1,147 @@
+<?php
+
+namespace app\abutment\middleware;
+
+use think\Exception;
+use think\exception\ValidateException;
+use think\facade\Cache;
+use think\facade\Config;
+use think\facade\Db;
+use think\facade\Validate;
+use think\Response;
+use app\abutment\model\RequestLog as RequestLogModel;
+
+//中间件
+class apiMiddleware
+{
+
+    //白名单
+    private $white_list = ['login'];
+
+    //请求入口
+    public function handle($request, \Closure $next)
+    {
+
+        //请求的唯一标识
+        $request->request_id = date('YmdHis') . mt_rand(100000, 999999);
+
+        //1.接收参数
+        $param = $request->post();
+
+//        $header = $request->header();
+
+        //判断白名单
+        if (!in_array(strtolower(request()->pathinfo()), $this->white_list)) {
+
+//            2.校验相关参数
+//            $this->checkParam($param);
+
+//            $this->checkHeader($header);
+
+            //4.获取供应商的开发信息
+//            $request->supplier = $this->getSupplierInfoByClientID($header['clientid']);
+
+            //获取用户信息
+            $request->user = $this->getUserInfo($param);
+
+//            if (!isset($user['code']) || $user['code'] != 0) throw new ValidateException($user['message']);
+
+//            $request->user = array_merge($user['data'], ['token' => $header['token']]);
+            //user_id , nickname
+            //5.校验签名
+//            $this->checkSign($header, $request->supplier['clientSecret']);
+        }
+
+        //3.记录日志
+        RequestLogModel::add($request->request_id, [], $param);
+
+        return $next($request);
+
+    }
+
+
+    //请求结束的回调
+    public function end(Response $response)
+    {
+        //只做记录,不做输出
+        RequestLogModel::where('request_id', request()->request_id)->save(['response' => $response->getContent()]);
+    }
+
+
+    //校验相关参数
+    private function checkHeader(array $header = [])
+    {
+        $val = Validate::rule([
+            'clientid' => 'require',
+            'timestamp|时间戳' => 'require|number|length:10',
+            'randomstring|随机字符串' => 'require|alphaNum|length:20',
+            'sign|签名' => 'require',
+            'token' => 'require|length:40|alphaNum',
+        ]);
+
+        if (!$val->check($header)) throw new ValidateException('请求基础参数有误:' . $val->getError());
+
+    }
+
+
+    //获取供应商的信息
+    private function getSupplierInfoByClientID(string $clientID = '')
+    {
+        $key = Config::get('config.redis_key.supplier_info');
+
+        $key .= $clientID;
+
+        $data = Cache::get($key);
+
+        if (!$data) {
+
+            $data = Db::name('abutment_supplier_development')
+                ->alias('a')
+                ->field('a.id,a.supplierNo,a.supplier,a.clientID,a.clientSecret,s.person,s.personid')
+                ->leftJoin('supplier s', 's.code=a.supplierNo AND s.is_del=0')
+                ->where(['a.clientID' => $clientID, 'a.is_del' => 0])
+                ->findOrEmpty();
+
+            Cache::set($key, $data, 3600 * 24);
+        }
+
+        return $data;
+    }
+
+
+    //校验签名
+    private function checkSign(array $header = [], string $clientSecret = '')
+    {
+
+        $str = substr($header['randomstring'], 0, 10) . $header['clientid'] . $header['timestamp'] . $header['token'] . substr($header['randomstring'], 10) . $clientSecret;
+
+        //签名 = crypt(随机字符串前10位 . clientID .时间戳 . token . 随机字符串后10位 . $clientSecret, 时间戳);
+//        $sign = crypt($str, $header['timestamp']);
+        $sign = md5($str);//暂时使用md5,上线以后用crypt
+
+        if ($sign != $header['sign']) throw new ValidateException('签名错误');
+
+    }
+
+    //获取用户信息
+    public function getUserInfo(array $param = [])
+    {
+        $val = Validate::rule([
+            'token|用户token' => 'require|length:40|alphaNum',
+            'supplierNo|供应商编码' => 'require|length:18|alphaNum',
+        ]);
+        if (!$val->check($param)) throw new ValidateException('参数错误,' . $val->getError());
+
+        $data = Cache::get(Config::get('redis_key.user_info_token') . $param['token']);
+        $data = json_decode($data, true);
+
+        if (!$data) throw new Exception('token已过期');
+
+        $supplierNames = array_column($data['supplier_list'], 'supplierName', 'supplierNo');
+
+        if(!isset($supplierNames[$param['supplierNo']])) throw new Exception('你尚未绑定当前供应商');
+
+        return array_merge($data, ['supplierNo' => $param['supplierNo'], 'supplierName' => $supplierNames[$param['supplierNo']]]);
+    }
+
+}

+ 34 - 0
app/abutment/model/RequestLog.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\abutment\model;
+
+use think\Model;
+
+//请求记录日志表
+class RequestLog extends Model
+{
+
+    protected $table = 'wsm_abutment_request_log';
+    protected $pk = 'id';
+    protected $autoWriteTimestamp = 'datetime';
+
+    // 定义时间戳字段名
+    protected $createTime = 'addtime';
+    protected $updateTime = 'updatetime';
+
+    public static function add(string $request_id = '', array $header = [], array $param = [])
+    {
+
+        return self::create([
+            'request_id' => $request_id,
+            'ipaddr' => request()->ip(),
+            'action' => request()->pathinfo(),
+            'header' => json_encode($header, JSON_UNESCAPED_UNICODE),
+            'param' => json_encode($param, JSON_UNESCAPED_UNICODE),
+            'client_id' => $header['clientid'] ?? '',
+            'uid' => ''
+        ])->save();
+    }
+
+
+}

+ 22 - 0
app/abutment/model/SupplierRelationUser.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace app\abutment\model;
+
+use think\Model;
+
+//供应商账号关联
+class SupplierRelationUser extends Model
+{
+    protected $table = 'sys_supplier_relation_user';
+    protected $pk = 'id';
+    protected $autoWriteTimestamp = false;
+    protected $connection = 'mysql_sys';
+
+    public static $is_del_normal = 0;//未删除
+    public static $is_del_deleted = 1;//已删除
+
+    public static $status_normal = 1;//状态,启用
+    public static $status_disabled = 0;//状态,禁用
+
+
+}

+ 24 - 0
app/abutment/model/SupplierUser.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace app\abutment\model;
+
+use think\Model;
+
+//供应商账号
+class SupplierUser extends Model
+{
+    protected $table = 'sys_supplier_user';
+    protected $pk = 'uid';
+    protected $autoWriteTimestamp = false;
+    protected $connection = 'mysql_sys';
+
+    public static $is_del_normal = 0;//未删除
+    public static $is_del_deleted = 1;//已删除
+
+    public static $status_normal = 1;//状态,启用
+    public static $status_disabled = 0;//状态,禁用
+
+//    public static $type_default = 1;//类型,联系人账号
+//    public static $type_ordinary = 2;//类型,普通账号
+
+}

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

@@ -0,0 +1,31 @@
+<?php
+
+use think\facade\Route;
+
+//账号
+route::rule('login', 'abutment/Account/login');//供应商登录
+
+
+//基础信息
+route::rule('getPlatformList', 'abutment/Index/getPlatformList');//推广平台列表
+route::rule('getCatList', 'abutment/Index/getCatList');//获取分类列表
+route::rule('getBrandList', 'abutment/Index/getBrandList');//获取品牌列表
+route::rule('getUnitList', 'abutment/Index/getUnitList');//获取单位列表
+route::rule('getSpecsTitleList', 'abutment/Index/getSpecsTitleList');//获取规格类型列表
+route::rule('getSpecsValueByTitleList', 'abutment/Index/getSpecsValueByTitleList');//获取规格值列表
+route::rule('getAreaList', 'abutment/Index/getAreaList');//获取省市区列表
+route::rule('getCompanyNoList', 'abutment/Index/getCompanyNoList');//获取业务公司编码
+
+
+//商品模块
+route::rule('getGoodList', 'abutment/Good/list');//商品列表
+route::rule('createGood', 'abutment/Good/createGood');//创建商品
+route::rule('updateGoodBasicsInfo', 'abutment/Good/updateGoodBasicsInfo');//修改商品基础信息
+route::rule('updateGoodPriceInfo', 'abutment/Good/updateGoodPriceInfo');//修改商品价格信息
+route::rule('getGoodDetail', 'abutment/Good/read');//获取商品详情
+
+//商品上线模块
+route::rule('createGoodUp', 'abutment/GoodUp/create');//申请商品上线
+route::rule('getGoodUpList', 'abutment/GoodUp/list');//商品上线列表
+
+

+ 131 - 0
app/abutment/validate/Good.php

@@ -0,0 +1,131 @@
+<?php
+
+
+namespace app\abutment\validate;
+
+
+use think\Validate;
+
+//商品模块的验证器
+class Good extends Validate
+{
+
+    //验证规则
+    protected $rule = [
+        'page|页码' => 'require|number|gt:0',
+        'size|每页条数' => 'require|number|gt:0|max:100',
+        'keyword|关键字' => 'max:10',
+        'good_name|商品名称' => 'require|max:255',
+        'spuCode|商品编码' => 'require|alphaNum|length:19',
+        'cat_id|分类' => 'require|number|gt:0',
+        'brand_id|品牌' => 'require|number|gt:0',
+        'good_unit|单位' => 'require|number|gt:0',
+        'moq|起订量' => 'number|gt:0',
+        'customized|定制工期' => 'number|gt:0|max:10000',
+        'tax|税点' => 'require|number|egt:0|max:100',
+        'good_size|商品尺寸' => 'require|max:255',
+        'companyNo|业务公司编码' => 'require|max:255',
+        'is_auth|是否有销售权限' => 'require|number|in:0,1',
+        'auth_img|销售授权图片' => 'max:255',
+        'after_sales|售后说明' => 'require|max:10000',
+        'craft_desc|工艺说明' => 'max:10000',
+        'good_remark|商品备注' => 'require|max:10000',
+        'weight|商品重量' => 'require|float|max:999999999999.999',
+        'packing_way|包装方式' => 'require|max:255',
+        'packing_size|装箱尺寸' => 'require|max:255',
+        'packing_spec|装箱规格' => 'require|max:255',
+        'packing_weight|装箱重量' => 'require|float|max:9999999999999.99',
+        'packing_list|包装清单' => 'require|max:255',
+        'good_bar|商品条形码' => 'max:255',
+        'supply_area|供货区域' => 'require|number|in:1,2',
+        'delivery_place|发货地' => 'require|array|length:3',
+        'origin_place|产地' => 'require|array|length:3',
+        'delivery_day|物流时间' => 'require|number|gt:0|max:10000',
+        'lead_time|供货周期' => 'number|gt:0|max:10000',
+        'cgd_gold_price|供应商采购金价' => 'float|max:9999999.99',
+        'sample_day|调样周期' => 'number|max:9999999',
+        'sample_fee|调样费用' => 'float|max:99999999.99',
+        'stock_moq|备库起订数量' => 'number|max:9999999',//库存品备库起订量不能为零
+        'is_diff|是否有工差' => 'number|in:1,0',
+        'good_img|商品详情主图' => 'require|array|max:20',
+        'config|配置' => 'max:255',
+        'other_config|其他配置' => 'max:255',
+        'good_thumb_img|商品缩略图' => 'require|max:255',
+        'good_info_img|商品详情图' => 'require|array|max:20',
+        'cert_fee|证书费' => 'float|max:99999999.99',
+        'packing_fee|包装费' => 'float|max:99999999.99',
+        'cost_fee|工艺费' => 'float|max:99999999.99',
+        'mark_fee|加标费' => 'float|max:99999999.99',
+        'demo_fee|打样费' => 'float|max:99999999.99',
+        'open_fee|开模费' => 'float|max:99999999.99',
+        'noble_metal|贵金属种类' => 'number|between:0,3',
+        'noble_weight|贵金属重量' => 'float|max:9999999.999',
+        'is_gold_price|是否使用实时金价' => 'number|in:0,1',
+        'market_price|市场价' => 'float|max:99999999.99',
+        'nake_price|含税成本价' => 'float|max:99999999.99',
+        'speclist|规格列表' => 'array|max:99999999',
+        'good_ladder|阶梯成本列表' => 'array|max:99999999',
+        'is_support_barter|是否可退货' => 'number|in:0,1',
+    ];
+
+    //验证场景
+    protected $scene = [
+        'list' => ['page', 'size', 'keyword'],//列表
+    ];
+
+    //创建商品场景下,移除以下字段
+    public function sceneCreate()
+    {
+        return $this
+            ->remove('page', true)
+            ->remove('size', true)
+            ->remove('id', true)
+            ->remove('spuCode', true)
+            ->remove('keyword', true);
+    }
+
+    //修改商品基础信息场景下,移除以下字段
+    public function sceneUpdateGoodBasicsInfo()
+    {
+        return $this
+            ->only(['spuCode', 'good_name', 'cat_id', 'brand_id', 'companyNo', 'good_unit', 'after_sales', 'craft_desc', 'good_remark', 'good_size', 'weight', 'packing_way', 'packing_size', 'packing_spec', 'packing_list', 'packing_weight', 'good_bar', 'supply_area', 'delivery_place', 'origin_place', 'delivery_day', 'lead_time', 'sample_day', 'good_img', 'good_thumb_img', 'good_info_img', 'config', 'other_config'])
+            ->remove('good_name', 'require')
+            ->remove('cat_id', 'require')
+            ->remove('brand_id', 'require')
+            ->remove('companyNo', 'require')
+            ->remove('good_unit', 'require')
+            ->remove('after_sales', 'require')
+            ->remove('good_remark', 'require')
+            ->remove('good_size', 'require')
+            ->remove('weight', 'require')
+            ->remove('packing_way', 'require')
+            ->remove('packing_size', 'require')
+            ->remove('packing_spec', 'require')
+            ->remove('packing_list', 'require')
+            ->remove('packing_weight', 'require')
+            ->remove('supply_area', 'require')
+            ->remove('delivery_place', 'require')
+            ->remove('origin_place', 'require')
+            ->remove('delivery_day', 'require')
+            ->remove('good_img', 'require')
+            ->remove('good_thumb_img', 'require')
+            ->remove('good_info_img', 'require');
+    }
+
+
+    //修改商品价格信息场景下,只校验以下字段
+    public function sceneUpdateGoodPriceInfo()
+    {
+        return $this
+            ->only(['spuCode', 'tax', 'sample_fee', 'cert_fee', 'packing_fee', 'cost_fee', 'mark_fee', 'demo_fee', 'open_fee', 'noble_metal', 'noble_weight', 'is_gold_price', 'cgd_gold_price', 'market_price', 'nake_price', 'speclist', 'good_ladder', 'is_support_barter'])
+            ->remove('tax', 'require');
+    }
+
+    //获取商品详情
+    public function sceneRead()
+    {
+        return $this->only(['spuCode']);
+    }
+
+
+}

+ 128 - 0
app/admin/controller/Account.php

@@ -0,0 +1,128 @@
+<?php
+
+
+namespace app\admin\controller;
+
+//采销端管理供应商账号
+use app\abutment\logic\Account as AccountLogic;
+use think\facade\Config;
+use think\facade\Validate;
+
+class Account extends Base
+{
+
+    //获取供应商下普通账号列表
+    public function geAccounttList()
+    {
+
+        $param = $this->request->filter('trim')->only(['supplierNo', 'keyword' => '', 'page' => 1, 'size' => 15], 'post');
+
+        $val = Validate::rule([
+            'supplierNo|供应商编码' => 'require|alphaNum|length:18',
+            'keyword|关键字' => 'chsDash|max:100',
+            'page|页码' => 'require|number|gt:0',
+            'size|每页数量' => 'require|number|elt:100',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::geAccounttList($param);
+    }
+
+    //修改密码
+    public function changePassword()
+    {
+        $param = $this->request->filter('trim')->only(['uid', 'old_password', 'new_password', 'confirm_password'], 'post');
+
+        $val = Validate::rule([
+            'uid|用户ID' => 'require|number|gt:0',
+            'old_password|旧密码' => 'require|min:6|max:200',
+            'new_password|新密码' => 'require|min:6|max:200',
+            'confirm_password|确认密码' => 'require|confirm:new_password|min:6|max:200',
+        ])->message(['confirm_password.confirm' => '确认密码和新密码不一致']);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::changePassword($param);
+    }
+
+    //读取账号信息
+    public function readAccount()
+    {
+        $param = $this->request->filter('trim')->only(['uid'], 'post');
+
+        $val = Validate::rule(['uid|用户ID' => 'require|number|gt:0']);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::readAccount($param);
+    }
+
+    //添加供应商账号
+    public function addAccount()
+    {
+
+        $param = $this->request->filter('trim')->only(['supplierNo', 'supplierName', 'nickname', 'mobile', 'email' => ''], 'post');
+
+        $val = Validate::rule([
+            'nickname|姓名' => 'require|max:255',
+            'mobile|手机号' => 'require|number|length:11|mobile',
+            'email|邮箱' => 'email',
+            'supplierNo|供应商编码' => 'require|alphaNum|length:18',
+            'supplierName|供应商名称' => 'require|max:255',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::addAccount($param);
+
+    }
+
+    //修改供应商账号
+    public function editAccount()
+    {
+
+        $param = $this->request->filter('trim')->only(['old_mobile', 'nickname', 'mobile', 'email'=>'','supplierNo','supplierName'], 'post');
+
+        $val = Validate::rule([
+            'nickname|姓名' => 'require|max:255',
+            'mobile|手机号' => 'require|number|length:11|mobile',
+            'email|邮箱' => 'email',
+            'old_mobile|原始手机号' => 'require|number|length:11|mobile',
+            'supplierNo|供应商编码' => 'require|alphaNum|length:18',
+            'supplierName|供应商名称' => 'require|max:255',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::editAccount($param);
+
+    }
+
+    //启/禁用 供应商账号
+    public function statusAccount()
+    {
+        $param = $this->request->filter('trim')->only(['supplierNo','mobile', 'status'], 'post');
+
+        $val = Validate::rule([
+            'supplierNo|供应商编码' => 'require|alphaNum|length:18',
+            'mobile|手机号' => 'require|number|length:11|mobile',
+            'status|状态' => 'require|number|in:' . \app\abutment\model\SupplierUser::$status_normal . ',' . \app\abutment\model\SupplierUser::$status_disabled,
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        return AccountLogic::statusAccount($param);
+
+    }
+
+    //删除供应商账号
+    public function deleteAccount()
+    {
+        $id = $this->request->filter('trim')->post('id/d', 0);
+
+        return AccountLogic::deleteAccount(['id' => $id]);
+
+    }
+
+}

+ 536 - 397
app/admin/controller/Suppler.php

@@ -2,25 +2,32 @@
 
 namespace app\admin\controller;
 
+use app\abutment\logic\Account;
+use app\abutment\model\SupplierUser;
 use app\admin\common\Ocr;
 use app\admin\model\ChangeLog;
-use app\BaseController;
 use think\App;
+use think\facade\Config;
 use think\facade\Db;
+use think\facade\Validate;
+
 
 //供应商
-class Suppler extends BaseController
+class Suppler extends Base
 {
     public $post = "";
+
     public function __construct(App $app)
     {
         parent::__construct($app);
-        $this->post=$this->request->post();
+        $this->post = $this->request->post();
     }
-    public function create(){
-        $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
-        if($name==""){
-            return error_show(1002,"参数name不能为空");
+
+    public function create()
+    {
+        $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
+        if ($name == "") {
+            return error_show(1002, "参数name不能为空");
         }
         $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
         if (!empty($rename)) {
@@ -28,219 +35,233 @@ class Suppler extends BaseController
         }
 
 
-        $tr=makeNo("QS");
-        $source= isset($this->post['source']) && $this->post['source']!==""? intval($this->post['source']) :"";
-        if($source===""){
-            return error_show(1002,"供应商来源不能为空");
-        }
-        $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
-        if($token==''){
-            return error_show(105,"参数token不能为空");
-        }
-        $user =GetUserInfo($token);
-        if(empty($user)||$user['code']!=0){
-            return error_show(1002,"创建人数据不存在");
-        }
-        $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
-        $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-        $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
-        if($personid==""){
-            return error_show(1002,"参数personid不能为空");
-        }
-        $to= GetInfoById($token,['id'=>$personid]);
-        if(empty($to)||$to['code']!=0){
-            return app_show(1002,"负责人信息不存在");
-        }
-        $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
-        $type = isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']) :"";
-        if($type===""){
-            return error_show(1002,"申请类型不能为空");
-        }
-        $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? intval($this->post['coop_state']):"";
-        if($coop_state===""){
-            return error_show(1002,"参数coop_state不能为空");
-        }
-        $category = isset($this->post['category']) && $this->post['category'] !==""? intval($this->post['category']):"";
-        if($category===""){
-            return error_show(1002,"参数category不能为空");
-        }
-        $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? intval($this->post['delivery_way']):"";
-        if($delivery_way===""){
-            return error_show(1002,"参数delivery_way不能为空");
-        }
-        $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
-        if($level===""){
-            return error_show(1002,"参数level不能为空");
-        }
-        $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? intval($this->post['supplier_type']):"";
-        if($supplier_type===""){
-            return error_show(1002,"参数supplier_type不能为空");
-        }
-        $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? intval($this->post['pay_type']):"";
-        if($pay_type===""){
-            return error_show(1002,"参数pay_type不能为空");
-        }
-        $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
-
-       // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
-       // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
-        $nature = isset($this->post['nature']) && $this->post['nature']!==""? intval($this->post['nature']) :"";
-        $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
-        $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? intval($this->post['ticket_type']) :"";
-        $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
-        $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
-        $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
-        $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
-        $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
-        $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
-        $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
-        $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
-        $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
-        $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
-        $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
-       // $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"1";
+        $tr = makeNo("QS");
+        $source = isset($this->post['source']) && $this->post['source'] !== "" ? intval($this->post['source']) : "";
+        if ($source === "") {
+            return error_show(1002, "供应商来源不能为空");
+        }
+        $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
+        if ($token == '') {
+            return error_show(105, "参数token不能为空");
+        }
+        $user = GetUserInfo($token);
+        if (empty($user) || $user['code'] != 0) {
+            return error_show(1002, "创建人数据不存在");
+        }
+        $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
+        $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
+        $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
+        if ($personid == "") {
+            return error_show(1002, "参数personid不能为空");
+        }
+        $to = GetInfoById($token, ['id' => $personid]);
+        if (empty($to) || $to['code'] != 0) {
+            return app_show(1002, "负责人信息不存在");
+        }
+        $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
+        $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "";
+        if ($type === "") {
+            return error_show(1002, "申请类型不能为空");
+        }
+        $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? intval($this->post['coop_state']) : "";
+        if ($coop_state === "") {
+            return error_show(1002, "参数coop_state不能为空");
+        }
+        $category = isset($this->post['category']) && $this->post['category'] !== "" ? intval($this->post['category']) : "";
+        if ($category === "") {
+            return error_show(1002, "参数category不能为空");
+        }
+        $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? intval($this->post['delivery_way']) : "";
+        if ($delivery_way === "") {
+            return error_show(1002, "参数delivery_way不能为空");
+        }
+        $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
+        if ($level === "") {
+            return error_show(1002, "参数level不能为空");
+        }
+        $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? intval($this->post['supplier_type']) : "";
+        if ($supplier_type === "") {
+            return error_show(1002, "参数supplier_type不能为空");
+        }
+        $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? intval($this->post['pay_type']) : "";
+        if ($pay_type === "") {
+            return error_show(1002, "参数pay_type不能为空");
+        }
+        $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
+
+        // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
+        // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
+        $nature = isset($this->post['nature']) && $this->post['nature'] !== "" ? intval($this->post['nature']) : "";
+        $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
+        $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? intval($this->post['ticket_type']) : "";
+        $legaler = isset($this->post['legaler']) && $this->post['legaler'] !== "" ? trim($this->post['legaler']) : "";
+        $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
+        $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
+        $capital = isset($this->post['capital']) && $this->post['capital'] !== "" ? intval($this->post['capital']) : "";
+        $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
+        $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
+        $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
+        $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
+        $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
+        $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
+        $scope = isset($this->post['scope']) && $this->post['scope'] !== "" ? trim($this->post['scope']) : "";
+        // $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"1";
         //$registertime= isset($this->post['registertime']) && $this->post['registertime']!==""?
         // $this->post['registertime'] :"";
-        $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
-        $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
-        if($contactor==""){
-            return error_show(1002,"参数contactor不能为空");
+        $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
+        $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
+        if ($contactor == "") {
+            return error_show(1002, "参数contactor不能为空");
         }
-        $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
-        if($mobile==""){
-            return error_show(1002,"参数mobile不能为空");
+        $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
+        if ($mobile == "") {
+            return error_show(1002, "参数mobile不能为空");
         }
-        $telephone = isset($this->post['telephone']) && $this->post['telephone'] !=="" ? trim($this->post['telephone']):"";
-        $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
-        if($position==""){
-            return error_show(1002,"参数position不能为空");
+        $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
+        $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
+        if ($position == "") {
+            return error_show(1002, "参数position不能为空");
         }
-        $email= isset($this->post['email']) && $this->post['email']!==""?trim($this->post['email']) :"";
+        $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
         Db::startTrans();
-        try{
-            $data=[
-                "name"=>$name,
-                "source"=>$source,
-                "coop_state"=>$coop_state,
-                "category"=>$category,
-                "delivery_way"=>$delivery_way,
-                "level"=>$level,
-                "supplier_type"=>$supplier_type,
-                "pay_type"=>$pay_type,
-                "registercode"=>$registercode,
-                "capital"=>$capital,
-                "product_category"=>$product_category,
-                "is_payment"=>$is_payment,
-                "notice_mark"=>$notice_mark,
-                "agreement"=>$agreement,
-                "warehouse"=>$warehouse,
-                "pay_day"=>$pay_day,
-                "scope"=>$scope,
-                "code"=>$tr,
-                "type"=>$type,
-                "nature"=>$nature,
-                "legaler"=>$legaler,
-                "addr"=>$addr,
-                "status"=>1,
-                "is_del"=>0,
-                "remark"=>'',
-                "ticket_type"=>$ticket_type,
-                "addtime"=>date('Y-m-d H:i:s'),
-                "updatetime"=>date("Y-m-d H:i:s"),
-                "is_platform"=>$is_platform,
-                "prove_img"=>$prove_img,
-                "license_img"=>$supplier_img,
-                "creater"=>$creater,
-                "createrid"=>$createrid,
-                "registertime"=>date('Y-m-d H:i:s'),
-                "person"=>$person,
-                "personid"=>$personid,
+        try {
+            $data = [
+                "name" => $name,
+                "source" => $source,
+                "coop_state" => $coop_state,
+                "category" => $category,
+                "delivery_way" => $delivery_way,
+                "level" => $level,
+                "supplier_type" => $supplier_type,
+                "pay_type" => $pay_type,
+                "registercode" => $registercode,
+                "capital" => $capital,
+                "product_category" => $product_category,
+                "is_payment" => $is_payment,
+                "notice_mark" => $notice_mark,
+                "agreement" => $agreement,
+                "warehouse" => $warehouse,
+                "pay_day" => $pay_day,
+                "scope" => $scope,
+                "code" => $tr,
+                "type" => $type,
+                "nature" => $nature,
+                "legaler" => $legaler,
+                "addr" => $addr,
+                "status" => 1,
+                "is_del" => 0,
+                "remark" => '',
+                "ticket_type" => $ticket_type,
+                "addtime" => date('Y-m-d H:i:s'),
+                "updatetime" => date("Y-m-d H:i:s"),
+                "is_platform" => $is_platform,
+                "prove_img" => $prove_img,
+                "license_img" => $supplier_img,
+                "creater" => $creater,
+                "createrid" => $createrid,
+                "registertime" => date('Y-m-d H:i:s'),
+                "person" => $person,
+                "personid" => $personid,
 
             ];
-            if($supplier_img!==""){
-                $ocr=new Ocr();
-                $datwa =  $ocr->query("",$supplier_img);
-                if($datwa['code']==0 && isset($datwa['data']['result'])){
-                        $license = $datwa['data']['result'];
-                        $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
-                        $data['addr']= isset($license['address'])?$license['address']:"";
-                        $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
-                        $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
-                        $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
-                        $data['nature']= isset($license['type'])?$license['type']:"";
-                        $data['registercode']= isset($license['registration_number'])?$license['registration_number']:"";
-                        $data['ocr_status']=1;
-                        if($name!=$license['name']){
-                            $data['remark']="企业名称与营业执照不匹配";
-                            $data['status']=0;
-                            $data['ocr_status']=1;
-                        }
-                        if($registercode!=$license['registration_number'] && $registercode!=""){
-                            $data['remark'].="企业名称与营业执照不匹配";
-                            $data['status']=0;
-                            $data['ocr_status']=1;
-                        }
-                }else{
-                    $data['remark']="营业执照识别失败";
-                    $data['status']=0;
-                    $data['ocr_status']=2;
+            if ($supplier_img !== "") {
+                $ocr = new Ocr();
+                $datwa = $ocr->query("", $supplier_img);
+                if ($datwa['code'] == 0 && isset($datwa['data']['result'])) {
+                    $license = $datwa['data']['result'];
+                    $data['legaler'] = isset($license['legal_representative']) ? $license['legal_representative'] : "";
+                    $data['addr'] = isset($license['address']) ? $license['address'] : "";
+                    $data['registertime'] = isset($license['found_date']) ? $license['found_date'] : "";
+                    $data['scope'] = isset($license['business_scope']) ? $license['business_scope'] : "";
+                    $data['capital'] = isset($license['registered_capital']) ? $license['registered_capital'] : "";
+                    $data['nature'] = isset($license['type']) ? $license['type'] : "";
+                    $data['registercode'] = isset($license['registration_number']) ? $license['registration_number'] : "";
+                    $data['ocr_status'] = 1;
+                    if ($name != $license['name']) {
+                        $data['remark'] = "企业名称与营业执照不匹配";
+                        $data['status'] = 0;
+                        $data['ocr_status'] = 1;
+                    }
+                    if ($registercode != $license['registration_number'] && $registercode != "") {
+                        $data['remark'] .= "企业名称与营业执照不匹配";
+                        $data['status'] = 0;
+                        $data['ocr_status'] = 1;
+                    }
+                } else {
+                    $data['remark'] = "营业执照识别失败";
+                    $data['status'] = 0;
+                    $data['ocr_status'] = 2;
                 }
             }
-            $join = Db::name('supplier')->insert($data,true);
-            if($join>0){
-                    $temp = [];
-                    $temp['code']=$tr;
-                    $temp['contactor'] =$contactor;
-                    $temp['mobile'] = $mobile;
-                    $temp['position'] = $position;
-                    $temp['telephone'] =$telephone;
-                    $temp['email'] =$email;
-                    $temp['is_del'] = 0;
-                    $temp['addtime'] = date("Y-m-d H:i:s");
-                    $temp['updatetime'] = date("Y-m-d H:i:s");
+            $join = Db::name('supplier')->insert($data, true);
+            if ($join > 0) {
+                $temp = [];
+                $temp['code'] = $tr;
+                $temp['contactor'] = $contactor;
+                $temp['mobile'] = $mobile;
+                $temp['position'] = $position;
+                $temp['telephone'] = $telephone;
+                $temp['email'] = $email;
+                $temp['is_del'] = 0;
+                $temp['addtime'] = date("Y-m-d H:i:s");
+                $temp['updatetime'] = date("Y-m-d H:i:s");
                 $vp = Db::name('supplier_contact')->insert($temp);
                 if ($vp == "") {
                     Db::rollback();
                     return error_show(1002, "添加失败");
                 }
+
+                //维护联系人账号
+                $res = Account::addAccount([
+                    'mobile' => $mobile,
+                    'nickname' => $contactor,
+                    'email' => $email,
+                    'supplierNo' => $tr,
+                    'supplierName' => $name,
+                ]);
+
+                if ($res->getData()['code'] != 0) throw new \Exception('添加联系人账号关联关系失败');
+
                 Db::commit();
-                return error_show(0,"添加成功",["id"=>$join]) ;
-            }else{
+                return app_show(0, "添加成功", ["id" => $join]);
+            } else {
                 Db::rollback();
-                return error_show(1002,"添加失败");
+                return error_show(1002, "添加失败");
             }
-        }catch (\Exception $e) {
+        } catch (\Exception $e) {
             Db::rollback();
             return error_show(1003, $e->getMessage());
         }
     }
-    public function list(){
-        $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 =[['s.is_del',"=",0]];
-        $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
-        if($name !==""){
-            $where[]=["s.name","like","%$name%"];
-        }
-        $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
-        if($creater !==""){
-            $where[] = ["s.creater","like","%$creater%"];
-        }
-        $person = isset($this->post['person']) && $this->post['person'] !=="" ? trim($this->post['person']):"";
-        if($person !==""){
-            $where[] = ["s.person","like","%$person%"];
-        }
-        $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
-        if($status!==""){
-            $where[]= ["s.status","=",$status];
-        }
-        $ocr_status = isset($this->post['ocr_status']) && $this->post['ocr_status'] !=="" ? intval($this->post['ocr_status']):"";
-        if($ocr_status!==""){
-            $where[]= ["s.ocr_status","=",$ocr_status];
-        }
-        $start = isset($this->post['start']) && $this->post['start'] !== "" ?  $this->post['start']:"";
-        if($start!==""){
-            $where[]=['s.addtime',">=",$start];
+
+    public function list()
+    {
+        $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 = [['s.is_del', "=", 0]];
+        $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
+        if ($name !== "") {
+            $where[] = ["s.name", "like", "%$name%"];
+        }
+        $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
+        if ($creater !== "") {
+            $where[] = ["s.creater", "like", "%$creater%"];
+        }
+        $person = isset($this->post['person']) && $this->post['person'] !== "" ? trim($this->post['person']) : "";
+        if ($person !== "") {
+            $where[] = ["s.person", "like", "%$person%"];
+        }
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
+        if ($status !== "") {
+            $where[] = ["s.status", "=", $status];
+        }
+        $ocr_status = isset($this->post['ocr_status']) && $this->post['ocr_status'] !== "" ? intval($this->post['ocr_status']) : "";
+        if ($ocr_status !== "") {
+            $where[] = ["s.ocr_status", "=", $ocr_status];
+        }
+        $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
+        if ($start !== "") {
+            $where[] = ['s.addtime', ">=", $start];
         }
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
         if ($company_name !== "") $where[] = ["s.createrid", 'in', get_company_item_user_by_name($company_name)];
@@ -272,201 +293,203 @@ class Suppler extends BaseController
             ->field('s.*,u.itemid')
             ->leftJoin("depart_user u", "u.uid=s.createrid AND u.is_del=0")
             ->where($where)
-            ->page($page,$size)
+            ->page($page, $size)
             ->order("addtime desc")
             ->select()
             ->toArray();
 
         $all_codes = Db::name('supplier_contact')
             ->whereIn('code', array_column($list, 'code'))
-            ->column("id,contactor,mobile",'code');
+            ->column("id,contactor,mobile", 'code');
 
-        foreach ($list as &$value){
-            $value['contactor']=isset($all_codes[$value['code']]['contactor'])?$all_codes[$value['code']]['contactor']:'';
-            $value['mobile']=isset($all_codes[$value['code']]['mobile'])?$all_codes[$value['code']]['mobile']:'';
+        foreach ($list as &$value) {
+            $value['contactor'] = isset($all_codes[$value['code']]['contactor']) ? $all_codes[$value['code']]['contactor'] : '';
+            $value['mobile'] = isset($all_codes[$value['code']]['mobile']) ? $all_codes[$value['code']]['mobile'] : '';
             $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
         }
-        return app_show("0","获取成功",['list'=>$list,'count'=>$count]);
+        return app_show("0", "获取成功", ['list' => $list, 'count' => $count]);
     }
-    public function edit(){
-        $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
-        if($token==''){
-            return error_show(105,"参数token不能为空");
+
+    public function edit()
+    {
+        $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
+        if ($token == '') {
+            return error_show(105, "参数token不能为空");
         }
-        $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
-        if($id==""){
-            return error_show(1002,"参数id不能为空");
+        $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
+        if ($id == "") {
+            return error_show(1002, "参数id不能为空");
         }
-        $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find();
-        if($info==""){
-            return error_show(1002,"未找到数据");
+        $info = Db::name("supplier")->where(['id' => $id, 'is_del' => 0])->find();
+        if ($info == "") {
+            return error_show(1002, "未找到数据");
         }
-        if($info['status']==1){
-            return error_show(1002,"状态是启用状态,无法编辑");
+        if ($info['status'] == 1) {
+            return error_show(1002, "状态是启用状态,无法编辑");
         }
-        $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
-        if($source==""){
-            return error_show(1002,"供应商来源不能为空");
+        $source = isset($this->post['source']) && $this->post['source'] !== "" ? trim($this->post['source']) : "";
+        if ($source == "") {
+            return error_show(1002, "供应商来源不能为空");
         }
-        $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
-        if($type==""){
-            return error_show(1002,"申请类型不能为空");
+        $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
+        if ($type == "") {
+            return error_show(1002, "申请类型不能为空");
         }
-        $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
-        if($coop_state==""){
-            return error_show(1002,"参数coop_state不能为空");
+        $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? trim($this->post['coop_state']) : "";
+        if ($coop_state == "") {
+            return error_show(1002, "参数coop_state不能为空");
         }
-        $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
-        if($category==""){
-            return error_show(1002,"参数category不能为空");
+        $category = isset($this->post['category']) && $this->post['category'] !== "" ? trim($this->post['category']) : "";
+        if ($category == "") {
+            return error_show(1002, "参数category不能为空");
         }
-        $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
-        if($delivery_way==""){
-            return error_show(1002,"参数delivery_way不能为空");
+        $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? trim($this->post['delivery_way']) : "";
+        if ($delivery_way == "") {
+            return error_show(1002, "参数delivery_way不能为空");
         }
-        $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
-        if($level==""){
-            return error_show(1002,"参数level不能为空");
+        $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
+        if ($level == "") {
+            return error_show(1002, "参数level不能为空");
         }
-        $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
-        if($supplier_type==""){
-            return error_show(1002,"参数supplier_type不能为空");
+        $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? trim($this->post['supplier_type']) : "";
+        if ($supplier_type == "") {
+            return error_show(1002, "参数supplier_type不能为空");
         }
-        $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
-        if($pay_type==""){
-            return error_show(1002,"参数pay_type不能为空");
+        $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? trim($this->post['pay_type']) : "";
+        if ($pay_type == "") {
+            return error_show(1002, "参数pay_type不能为空");
         }
-        $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
+        $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
 
-        $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
-        if($personid==""){
-            return error_show(1002,"参数personid不能为空");
+        $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
+        if ($personid == "") {
+            return error_show(1002, "参数personid不能为空");
         }
-        $to= GetInfoById($token,['id'=>$personid]);
-        if(empty($to)||$to['code']!=0){
-            return app_show(1002,"负责人信息不存在");
+        $to = GetInfoById($token, ['id' => $personid]);
+        if (empty($to) || $to['code'] != 0) {
+            return app_show(1002, "负责人信息不存在");
         }
-        $telephone = isset($this->post['telephone']) && $this->post['telephone'] !=="" ? trim($this->post['telephone']):"";
-        $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
-        $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
-        if($name==""){
-            return error_show(1002,"数据标题不能为空");
+        $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
+        $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
+        $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
+        if ($name == "") {
+            return error_show(1002, "数据标题不能为空");
         }
-        $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->where([["id","<>",$id]])->find();
+        $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->where([["id", "<>", $id]])->find();
 
-        if ($rename!=false) {
+        if ($rename != false) {
             return error_show(1002, "公司名称已存在");
         }
 //        $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
-        $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
-        $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
+        $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
+        $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? trim($this->post['ticket_type']) : "";
 //        $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
 //        $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
-        $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
+        $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
 //        $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
-        $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
-        $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
-        $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
-        $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
-        $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
-        $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
+        $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
+        $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
+        $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
+        $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
+        $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
+        $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
 //        $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
 ////        $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
 //        $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
-        $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
-        $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
-        if($contactor==""){
-            return error_show(1002,"参数contactor不能为空");
+        $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
+        $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
+        if ($contactor == "") {
+            return error_show(1002, "参数contactor不能为空");
         }
-        $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
-        if($mobile==""){
-            return error_show(1002,"参数mobile不能为空");
+        $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
+        if ($mobile == "") {
+            return error_show(1002, "参数mobile不能为空");
         }
-        $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
-        if($position==""){
-            return error_show(1002,"参数position不能为空");
+        $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
+        if ($position == "") {
+            return error_show(1002, "参数position不能为空");
         }
-        $email = isset($this->post['email']) && $this->post['email'] !=="" ? trim($this->post['email']):"";
+        $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
 
 //        if($registercode==""){
 //            return error_show(1002,"参数registercode不能为空");
 //        }
         Db::startTrans();
-        try{
-            $data=[
-                "id"=>$id,
-                "source"=>$source,
-                "name"=>$name,
-                "coop_state"=>$coop_state,
-                "category"=>$category,
-                "delivery_way"=>$delivery_way,
-                "level"=>$level,
-                "supplier_type"=>$supplier_type,
-                "pay_type"=>$pay_type,
-                "registercode"=>$registercode,
-                "product_category"=>$product_category,
-                "is_payment"=>$is_payment,
-                "notice_mark"=>$notice_mark,
-                "agreement"=>$agreement,
-                "warehouse"=>$warehouse,
-                "pay_day"=>$pay_day,
-                "type"=>$type,
-                "license_img"=>$supplier_img,
-                "is_del"=>0,
-               // "status"=>$info['license_img']==$supplier_img ? $info['status']:0,
-                "ticket_type"=>$ticket_type,
-                "updatetime"=>date("Y-m-d H:i:s"),
-                "is_platform"=>$is_platform,
-                "prove_img"=>$prove_img,
-                "person"=>$person,
-                "personid"=>$personid,
-                "remark"=>""
+        try {
+            $data = [
+                "id" => $id,
+                "source" => $source,
+                "name" => $name,
+                "coop_state" => $coop_state,
+                "category" => $category,
+                "delivery_way" => $delivery_way,
+                "level" => $level,
+                "supplier_type" => $supplier_type,
+                "pay_type" => $pay_type,
+                "registercode" => $registercode,
+                "product_category" => $product_category,
+                "is_payment" => $is_payment,
+                "notice_mark" => $notice_mark,
+                "agreement" => $agreement,
+                "warehouse" => $warehouse,
+                "pay_day" => $pay_day,
+                "type" => $type,
+                "license_img" => $supplier_img,
+                "is_del" => 0,
+                // "status"=>$info['license_img']==$supplier_img ? $info['status']:0,
+                "ticket_type" => $ticket_type,
+                "updatetime" => date("Y-m-d H:i:s"),
+                "is_platform" => $is_platform,
+                "prove_img" => $prove_img,
+                "person" => $person,
+                "personid" => $personid,
+                "remark" => ""
             ];
-            if($supplier_img!=="" &&$info['license_img']!=$supplier_img){
-                $ocr=new Ocr();
-                $dataw =  $ocr->query("",$supplier_img);
+            if ($supplier_img !== "" && $info['license_img'] != $supplier_img) {
+                $ocr = new Ocr();
+                $dataw = $ocr->query("", $supplier_img);
 
-                if($dataw['code']==0 && isset($dataw['data']['result'])){
+                if ($dataw['code'] == 0 && isset($dataw['data']['result'])) {
                     $license = $dataw['data']['result'];
-                    $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
-                    $data['addr']= isset($license['address'])?$license['address']:"";
-                    $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
-                    $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
-                    $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
-                    $data['nature']= isset($license['type'])?$license['type']:"";
-                    $data['registercode']=isset($license['registration_number'])? $license['registration_number']:"";//12356
-                    $data['ocr_status']=1;
-                    if($name!=$license['name']){
-                        $data['remark']="企业名称与营业执照不匹配";
-                        $data['ocr_status']=1;
+                    $data['legaler'] = isset($license['legal_representative']) ? $license['legal_representative'] : "";
+                    $data['addr'] = isset($license['address']) ? $license['address'] : "";
+                    $data['registertime'] = isset($license['found_date']) ? $license['found_date'] : "";
+                    $data['scope'] = isset($license['business_scope']) ? $license['business_scope'] : "";
+                    $data['capital'] = isset($license['registered_capital']) ? $license['registered_capital'] : "";
+                    $data['nature'] = isset($license['type']) ? $license['type'] : "";
+                    $data['registercode'] = isset($license['registration_number']) ? $license['registration_number'] : "";//12356
+                    $data['ocr_status'] = 1;
+                    if ($name != $license['name']) {
+                        $data['remark'] = "企业名称与营业执照不匹配";
+                        $data['ocr_status'] = 1;
                     }
-                    if($registercode!=$license['registration_number']&&$registercode!=''){
-                        $data['remark'].="企业名称与营业执照不匹配";
-                        $data['ocr_status']=1;
+                    if ($registercode != $license['registration_number'] && $registercode != '') {
+                        $data['remark'] .= "企业名称与营业执照不匹配";
+                        $data['ocr_status'] = 1;
                     }
-                }else{
-                    $data['remark']="营业执照识别失败";
-                    $data['ocr_status']=2;
+                } else {
+                    $data['remark'] = "营业执照识别失败";
+                    $data['ocr_status'] = 2;
                 }
             }
-            $ino = array_diff($data,$info);
-            $tem = json_encode($ino,JSON_UNESCAPED_UNICODE);
-            $jsp = json_encode($info,JSON_UNESCAPED_UNICODE);
-            $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
-            if($join){
-                ChangeLog::logAdd("1",$info['code'],$jsp,$tem,$this->post['token'],$this->post);
-                $item = Db::name('supplier_contact')->where(['code'=>$info['code']])->find();
-                    $temp = [];
-                isset($item['id']) && $item['id'] !== "" ? $temp['id'] =$item['id'] : '';
-                    $temp['code'] = $info['code'];
-                    $temp['contactor'] = $contactor;
-                    $temp['mobile'] = $mobile;
-                    $temp['position'] = $position;
-                    $temp['telephone'] = $telephone;
-                    $temp['email'] =$email;
-                    $temp['is_del'] = 0;
+            $ino = array_diff($data, $info);
+            $tem = json_encode($ino, JSON_UNESCAPED_UNICODE);
+            $jsp = json_encode($info, JSON_UNESCAPED_UNICODE);
+            $join = Db::name('supplier')->where(['id' => $id, 'is_del' => 0])->save($data);
+            if ($join) {
+                ChangeLog::logAdd("1", $info['code'], $jsp, $tem, $this->post['token'], $this->post);
+                $item = Db::name('supplier_contact')->where(['code' => $info['code']])->find();
+                $temp = [];
+                isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
+                $temp['code'] = $info['code'];
+                $temp['contactor'] = $contactor;
+                $temp['mobile'] = $mobile;
+                $temp['position'] = $position;
+                $temp['telephone'] = $telephone;
+                $temp['email'] = $email;
+                $temp['is_del'] = 0;
                 isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
-                    $temp['updatetime'] = date("Y-m-d H:i:s");
+                $temp['updatetime'] = date("Y-m-d H:i:s");
 //                    $st = array_diff($item,$temp);
 //                    $snm =json_encode($st);
                 $vp = Db::name('supplier_contact')->save($temp);
@@ -475,71 +498,187 @@ class Suppler extends BaseController
                     Db::rollback();
                     return error_show(1002, "更新失败");
                 }
+
+                //维护联系人账号
+                if ($item['mobile'] != $mobile) {
+                    $res = Account::editAccount([
+                        'old_mobile' => $item['mobile'],
+                        'mobile' => $mobile,
+                        'nickname' => $contactor,
+                        'email' => $email,
+                        'supplierNo' => $info['code'],
+                        'supplierName' => $info['name'],
+                    ]);
+
+                    if ($res->getData()['code']!=0) throw new \Exception('修改联系人的账号失败');
+                }
+
                 Db::commit();
-                return error_show(0,"编辑成功") ;
-            }else{
+                return app_show(0, "编辑成功");
+            } else {
                 Db::rollback();
-                return error_show(1002,"编辑失败");
+                return error_show(1002, "编辑失败");
             }
-        }catch (\Exception $e) {
+        } catch (\Exception $e) {
             Db::rollback();
             return error_show(1003, $e->getMessage());
         }
     }
-    public function info(){
-        $code = isset($this->post['code'])&& $this->post['code'] !=="" ? trim($this->post['code']) :"";
-        if($code ==""){
-            return error_show(1002,"参数code不能为空");
-        }
-        $info = Db::name('supplier')->where(['code'=>$code,'is_del'=>0])->find();
-        if($info==""){
-            return error_show(1002,"未找到数据");
-        }
-        $contact = Db::name("supplier_contact")->where(["code"=>$info['code'],"is_del"=>0])->find();
-        $info['contactor']=isset($contact['contactor'])? $contact['contactor']:"";
-        $info['mobile']=isset($contact['mobile'])? $contact['mobile']:"";
-        $info['position']=isset($contact['position'])? $contact['position']:"";
-        $info['email']=isset($contact['email'])? $contact['email']:"";
-        $info['telephone']=isset($contact['telephone'])? $contact['telephone']:"";
-        $info['supplier_img']=isset($info['license_img'])? $info['license_img']:"";
-        return app_show(0,"获取成功",$info);
+
+    public function info()
+    {
+        $code = isset($this->post['code']) && $this->post['code'] !== "" ? trim($this->post['code']) : "";
+        if ($code == "") {
+            return error_show(1002, "参数code不能为空");
+        }
+        $info = Db::name('supplier')->where(['code' => $code, 'is_del' => 0])->find();
+        if ($info == "") {
+            return error_show(1002, "未找到数据");
+        }
+        $contact = Db::name("supplier_contact")->where(["code" => $info['code'], "is_del" => 0])->find();
+        $info['contactor'] = isset($contact['contactor']) ? $contact['contactor'] : "";
+        $info['mobile'] = isset($contact['mobile']) ? $contact['mobile'] : "";
+        $info['position'] = isset($contact['position']) ? $contact['position'] : "";
+        $info['email'] = isset($contact['email']) ? $contact['email'] : "";
+        $info['telephone'] = isset($contact['telephone']) ? $contact['telephone'] : "";
+        $info['supplier_img'] = isset($info['license_img']) ? $info['license_img'] : "";
+        return app_show(0, "获取成功", $info);
     }
-    public function del(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
-        $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
-        if($sup==false){
-            return error_show(1002,"供应商信息不存在");
-        }
-        $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
-        $vam = array_diff($sup,$supp);
-        $vap = json_encode($vam);
-        if($supp){
-            ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
-            return error_show(0,"删除成功");
-        }else{
-            return error_show(1002,"删除失败");
+
+    //删除 供应商
+    public function del()
+    {
+        $id = $this->request->filter('trim')->post('id/d', 0);
+
+        $sup = Db::name("supplier")
+            ->where(['id' => $id, 'is_del' => 0])
+            ->find();
+        if (empty($sup)) return error_show(1005, '未找到对应数据');
+
+        Db::startTrans();
+        try {
+            //维护供应商表
+            $supp = ['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")];
+            Db::name("supplier")
+                ->where(['id' => $id, 'is_del' => 0])
+                ->update($supp);
+
+            $vam = array_intersect_key($sup, $supp);//比较两个数组的键名,并返回交集
+
+            ChangeLog::logAdd("1", $sup['code'], json_encode($sup, JSON_UNESCAPED_UNICODE), json_encode($vam, JSON_UNESCAPED_UNICODE), $this->post['token'], $this->post);
+
+            //维护联系人账号
+//            $res = SupplierUser::where('is_del', SupplierUser::$is_del_normal)
+//                ->where('type', SupplierUser::$type_default)
+//                ->whereFindInSet('supplierNos', $sup['code'])->save([
+//                    'is_del' => SupplierUser::$is_del_deleted,
+//                    'updatetime' => date('Y-m-d H:i:s')
+//                ]);
+            $res = Account::deleteAccount(['supplierNo' => $sup['code']]);
+            if ($res->getData()['code'] != 0) throw new \Exception('删除联系人账号失败');
+
+            Db::commit();
+            return app_show(0, '删除成功');
+        } catch (\Exception $exception) {
+            Db::rollback();
+            return error_show(1005, '删除失败' . $exception->getMessage());
         }
+
+
+//        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
+//        $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
+//        if($sup==false){
+//            return error_show(1002,"供应商信息不存在");
+//        }
+//        $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+//        $vam = array_diff($sup,$supp);
+//        $vap = json_encode($vam);
+//        if($supp){
+//            ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
+//
+//            //维护联系人账号
+//            $res = SupplierUser::where([
+//                'is_del' => SupplierUser::$is_del_normal,
+//                'status' => SupplierUser::$status_normal,
+//                'type' => SupplierUser::$type_default
+//            ])->whereFindInSet('supplierNos', $sup['code'])->save([
+//                'is_del' => SupplierUser::$is_del_deleted,
+//                'updatetime' => date('Y-m-d H:i:s')
+//            ]);
+//            if (!$res) return error_show('删除联系人账号失败');
+//
+//            return error_show(0,"删除成功");
+//        }else{
+//            return error_show(1002,"删除失败");
+//        }
     }
-    public function status(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
-        if($id==""){
-            return error_show(1002,"参数id不能为空");
-        }
-        $info =  Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
-        if(!$info){
-            return error_show(1002,"未找到对应数据");
-        }
-        $status =  isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
-        if($status===""){
-            return error_show(1002,"参数status不能为空");
-        }
-        if(!in_array($status,[0,1,2])){
-            return error_show(1002,"参数status无效");
-        }
-        $info['status']=$status;
-        $info['updatetime']=date("Y-m-d H:i:s");
-        $msg = $status==1?"启用":"禁用";
-        $update = Db::name("supplier")->save($info);
-        return  $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
+
+    //启/禁用 供应商
+    public function status()
+    {
+        $param = $this->request->filter('trim')->only(['id', 'status'], 'post');
+
+        $val = Validate::rule(['id' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1,2']);
+
+        if (!$val->check($param)) return error_show(1005, $val->getError());
+
+        $msg = $param['status'] == 1 ? "启用" : "禁用";
+
+        $info = Db::name("supplier")
+            ->alias('a')
+            ->field('a.id,a.code,a.status,b.mobile')
+            ->leftJoin('supplier_contact b','b.code=a.code')
+            ->where(['a.id' => $param['id'], 'a.is_del' => 0])
+            ->find();
+        if (empty($info)) return error_show(1005, '未找到对应数据');
+        if ($info['status'] == $param['status']) return error_show(1005, '不能重复' . $msg);
+
+        Db::startTrans();
+        try {
+            //维护供应商表
+            Db::name("supplier")
+                ->where('id', $param['id'])
+                ->where('status', '<>', $param['status'])
+                ->save([
+                    'status' => $param['status'],
+                    'updatetime' => date("Y-m-d H:i:s"),
+                ]);
+
+            //维护联系人账号
+            $res = Account::statusAccount([
+                'mobile' => $info['mobile'],
+                'status' => $param['status'],
+                'supplierNo' => $info['code'],
+            ]);
+            if ($res->getData()['code'] != 0) throw new \Exception($msg . '联系人账号失败');
+
+            Db::commit();
+            return app_show(0, $msg . '成功');
+        } catch (\Exception $exception) {
+            Db::rollback();
+            return error_show(1005, $exception->getMessage());
+        }
+
+//        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
+//        if($id==""){
+//            return error_show(1002,"参数id不能为空");
+//        }
+//        $info =  Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
+//        if(!$info){
+//            return error_show(1002,"未找到对应数据");
+//        }
+//        $status =  isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
+//        if($status===""){
+//            return error_show(1002,"参数status不能为空");
+//        }
+//        if(!in_array($status,[0,1,2])){
+//            return error_show(1002,"参数status无效");
+//        }
+//        $info['status']=$status;
+//        $info['updatetime']=date("Y-m-d H:i:s");
+//        $msg = $status==1?"启用":"禁用";
+//        $update = Db::name("supplier")->save($info);
+//        return  $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
+
     }
 }

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

@@ -607,3 +607,10 @@ Route::rule('bkreport','admin/Stat/bkReport');//
 Route::rule('standbooklist','admin/StandingBook/getList');//台账列表
 Route::rule('standbookdetail','admin/StandingBook/getDetail');//台账详情
 
+route::rule('geAccounttList', 'admin/Account/geAccounttList');//获取供应商下普通账号列表
+route::rule('changePassword', 'admin/Account/changePassword');//修改密码
+route::rule('readAccount', 'admin/Account/readAccount');//获取账号信息
+route::rule('addAccount', 'admin/Account/addAccount');//添加供应商账号
+route::rule('editAccount', 'admin/Account/editAccount');//修改供应商账号
+route::rule('statusAccount', 'admin/Account/statusAccount');//修改供应商账号状态
+route::rule('deleteAccount', 'admin/Account/deleteAccount');//删除供应商账号

+ 20 - 0
app/common.php

@@ -4,6 +4,8 @@
 use think\facade\Config;
 use think\facade\Db;
 use think\facade\Filesystem;
+use think\helper\Str;
+
 // 应用公共文件
 function app_show($code=0,$message="",$data=[]){
     $result = ['code'=>$code,"message"=>$message,"data"=>$data];
@@ -1182,4 +1184,22 @@ if (!function_exists('json_show')) {
     {
         return json(['code' => $code, 'message' => $message, 'data' => $data]);
     }
+}
+
+//获取加密后的密码密文
+/**
+ * @param $password string 密码明文
+ * @param $salt string 盐值(不传的话随机生成一个)
+ */
+if (!function_exists('get_encryption_password')) {
+
+    function get_encryption_password(string $password = '',string $salt=''):array
+    {
+        if($salt=='') $salt = Str::random(mt_rand(10, 30), -1);
+        return [
+            'password' => md5($salt . $password . $salt . $salt),
+            'salt' => $salt
+        ];
+    }
+
 }