wugg 8 mēneši atpakaļ
vecāks
revīzija
7ab58bf449

+ 192 - 0
app/admin/controller/Brand.php

@@ -0,0 +1,192 @@
+<?php
+
+
+namespace app\admin\controller;
+
+
+use app\user\model\AccountItem;use think\App;use think\facade\Validate;
+class Brand extends Base{
+
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->model=new \app\admin\model\Brand();
+    }
+    /**
+     * 列出品牌管理列表
+     *
+     * 根据请求参数分页查询品牌管理信息,支持根据品牌名称、状态、创建时间范围进行过滤。
+     * 返回品牌的分页列表,包含每条品牌信息的详细数据。
+     *
+     * @param string $param 搜索条件,包括页码、每页数量、品牌名称、状态、时间范围等。
+     * @return \think\Response|\think\response\Json 返回查询结果的分页对象或JSON响应。
+     * @throws \think\db\exception\DbException 如果数据库查询出错,则抛出异常。
+     */
+    public function list()
+    {
+        // 获取请求参数,包括页码、每页数量、品牌名称、状态和时间范围,并进行trim操作。
+        $param = $this->request->param(['page' => 1, 'size' => 10, 'brand_name' => '', 'status' => '', "start" => "", "end" => ""], "post", "trim");
+
+        // 定义初始查询条件,排除已删除的记录。
+        $where = [["is_del", "=", 0]];
+
+        // 如果品牌名称不为空,则添加到查询条件中,进行模糊搜索。
+        if ($param['brand_name'] != "") $where[] = ["brand_name", "like", "%{$param['brand_name']}%"];
+
+        // 如果状态不为空,则添加到查询条件中,进行精确查询。
+        if ($param['status'] !== "") $where[] = ["status", "=", $param['status']];
+
+        // 如果开始时间不为空,则添加到查询条件中,查询大于等于开始时间的记录。
+        if ($param['start'] != "") $where[] = ["addtime", ">=", startTime($param['start'])];
+
+        // 如果结束时间不为空,则添加到查询条件中,查询小于结束时间的记录。
+        if ($param['end'] != "") $where[] = ["addtime", "<", endTime($param['end'])];
+
+        // 根据查询条件进行查询,并按id降序排序,分页获取数据。
+        $list = $this->model->where($where)
+            ->order("id desc")
+            ->paginate(["page" => $param['page'], "list_rows" => $param['size']]);
+
+        // 遍历查询结果,补充每个品牌的创建者所属公司的名称。
+        $list->each(function (&$item) {
+            $userinfo = AccountItem::with(['ItemName'])->where(["account_id" => $item['createrid']])->findOrEmpty();
+            $item['company_name'] = $userinfo->depart_name ?? "";
+        });
+
+        // 返回成功响应,包含品牌列表数据和总条数。
+        return success("获取成功", ["list" => $list->items(), "count" => $list->total()]);
+    }
+    /**
+     * 添加品牌
+     *
+     * 根据请求参数添加新的品牌信息。
+     * 返回添加成功或失败的消息。
+     *
+     * @param string $param 添加品牌信息的请求参数,包括品牌名称、logo URL、创建者ID、创建者名称等。
+     * @return \think\Response|\think\response\Json 返回添加成功或失败的消息。
+     */
+    public function create()
+    {
+        $param = $this->request->param(['brand_name' => '', 'logo_url' => '', 'is_del' => '0'], "post", "trim");
+        $valid=Validate::rule([
+            'brand_name|品牌名称'=>'require|max:255|unique:\app\admin\model\Brand,is_del',
+            'logo_url|品牌logo'=>'url'
+        ]);
+        if(!$valid->check($param)){
+            return error($valid->getError());
+        }
+        $data=[
+            'brand_name'=>$param['brand_name'],
+            'logo_url'=>$param['logo_url'],
+            'createrid'=>$this->uid,
+            'creater'=>$this->uname,
+        ];
+        $save=$this->model->save($data);
+        if($save){
+            return success("添加成功");
+        }else{
+            return error("添加失败");
+        }
+    }
+    /**
+     * 修改品牌
+     * @param string $param 修改品牌信息的请求参数,包括品牌ID、品牌名称、logo URL、状态等。
+    * @return \think\Response|\think\response\Json|void
+     */
+    public function save()
+    {
+        $param = $this->request->param(['id' => '', 'brand_name' => '', 'logo_url' => '', 'is_del' => '0'], "post", "trim");
+        $valid=Validate::rule([
+            'id|品牌id'=>'require|int',
+            'brand_name|品牌名称'=>'require|max:255|unique:\app\admin\model\Brand,is_del',
+            'logo_url|品牌logo'=>'url'
+        ]);
+        if(!$valid->check($param)){
+            return error($valid->getError());
+        }
+        $info = $this->model->findOrEmpty($param['id']);
+        if ($info->isEmpty()) {
+            return error("未找到该品牌");
+        }
+            $info->brand_name = $param['brand_name'];
+            $info->logo_url = $param['logo_url'];
+            $info->status=0;
+            $save = $info->save();
+            if ($save) {
+                return success("修改成功");
+            } else {
+                return error("修改失败");
+            }
+
+    }
+    /** 删除品牌
+    * @param string $param 删除品牌信息的请求参数,包括品牌ID。
+    * @return \think\Response|\think\response\Json|void
+     */
+    public function delete()
+    {
+        $param = $this->request->param(['id' => '', 'is_del' => '0'], "post", "trim");
+        $valid=Validate::rule([
+            'id|品牌id'=>'require|int',
+        ]);
+        if(!$valid->check($param)){
+            return error($valid->getError());
+        }
+        $info = $this->model->findOrEmpty($param['id']);
+        if ($info->isEmpty()) {
+            return error("未找到该品牌");
+        }
+        if($info->is_del==1){
+            return error("该品牌已被删除");
+        }
+        if($info->status==1){
+            return error("该品牌已被使用,无法删除");
+        }
+        $info->is_del = 1;
+        $save = $info->save();
+        if ($save) {
+            return success("删除成功");
+        } else {
+            return error("删除失败");
+        }
+    }
+    /** 品牌状态
+    * @param string $param 品牌状态的请求参数,包括品牌ID、状态。
+    */
+    public function status()
+    {
+        $param = $this->request->param(['id' => '', 'status' => '0'], "post", "trim");
+        $valid=Validate::rule([
+            'id|品牌id'=>'require|int',
+            'status|状态'=>'require|in:0,1'
+        ]);
+        if(!$valid->check($param)){
+            return error($valid->getError());
+        }
+        $info = $this->model->findOrEmpty($param['id']);
+        if ($info->isEmpty()) {
+            return error("未找到该品牌");
+        }
+        if($info->status==$param['status']){
+            return error("该品牌状态已为".\app\admin\model\Brand::$statusCn[$param['status']]);
+        }
+        $info->status = $param['status'];
+        $save = $info->save();
+        if($save==false)return error(\app\admin\model\Brand::$statusCn[$param['status']]."失败");
+        return success(\app\admin\model\Brand::$statusCn[$param['status']]."成功");
+    }
+    /** 获取品牌列表
+    * @param string $param 获取品牌列表的请求参数,包括每页条数、品牌名称。
+    * @return \think\Response|\think\response\Json|void
+    */
+    public function getBrandList()
+    {
+        $param = $this->request->param(['size' => 100,"brand_name"=>""], "post", "trim");
+        $where=[["is_del","=",0]];
+        if($param['brand_name']!=''){
+            $where[]=["brand_name","like","%".$param['brand_name']."%"];
+        }
+        $list = $this->model->where($where)->field("id,brand_name,status,length(brand_name) len_name")
+        ->order("len_name asc")->limit($param['size'])->select();
+        return success("获取成功", $list);
+    }
+}

+ 237 - 0
app/admin/controller/BrandAuth.php

@@ -0,0 +1,237 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: wugg
+ * @DateTime : 2024-06-28 16:01
+ * @Description : 品牌授权
+ * @Version : 1.0
+ */
+
+namespace app\admin\controller;
+
+use app\admin\model\BrandBook;
+use think\App;
+use think\facade\Validate;
+class BrandAuth extends Base{
+
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->model=new \app\admin\model\BrandBook();
+    }
+    /**
+     * 添加品牌授权
+     * @param \think\Request $request
+    * @return \think\Response|\think\response\Json|void
+     */
+    public function create(){
+    	$param = $this->request->param([
+    		'brand_book',
+    		'gyscode',
+    		'brand_id',
+    		'is_del'=>0,
+    		'remark',
+    		'long',
+    		'status'=>0,
+    		'starttime'=>"",
+    		'endtime'=>''],'post','trim');
+        $valid= Validate::rule([
+        	'brand_book|授权书图片'=>'max:255',
+        	'gyscode|供应商编号'=>'require|max:255',
+        	'brand_id|品牌id'=>'require|number|gt:0|unique:app\admin\model\BrandBook,gyscode^is_del',
+        	'long|授权类型'=>'require|number|in:0,1',
+        	'status|状态'=>'require|number|in:0,1',
+        	'starttime|开始日期'=>'require|date|dateFormat:Y-m-d H:i:s',
+        	'endtime|结束日期'=>'requireIf:long,1|date|dateFormat:Y-m-d H:i:s',
+        	]);
+        if($valid->check($param)==false) return error($valid->getError());
+        $data=[
+            "brand_book"=>$param['brand_book'],
+        	"gyscode"=>$param['gyscode'],
+        	"gysname"=>\app\user\model\supplier::where('code',$param['gyscode'])->value('name'),
+        	"brand_id"=>$param['brand_id'],
+        	"remark"=>$param['remark'],
+        	"long"=>$param['long'],
+        	"status"=>$param['status'],
+        	"starttime"=>$param['starttime'],
+        	"endtime"=>$param['long']==1?"":$param['endtime'],
+        	"createrid"=>$this->uid,
+        	"creater"=>$this->uname,
+        	];
+        $create=$this->model->create($data);
+        if($create==false)return error('添加失败');
+        return success("添加成功");
+    }
+    /**
+     * 品牌授权列表
+     * @param $param page size gyscode name
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DbException
+     */
+    public function list(){
+        $param = $this->request->param([
+            'page'=>1,
+            'size'=>10,
+            'gyscode'=>'',
+            'name'=>'',
+        ],'post','trim');
+        $where=[['is_del','=',0]];
+        if($param['gyscode']!=''){
+            $where[]=['gyscode','like','%'.$param['gyscode'].'%'];
+        }
+        if($param['name']!=''){
+            $where[]=['name','like','%'.$param['name'].'%'];
+        }
+        $list= $this->model->with(["brandInfo"])->where($where)->paginate(["list_rows"=>$param['size'],
+        "page"=>$param['page']]);
+        return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
+    }
+    /**
+     * 品牌授权详情
+     * @param $param id
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\DbException
+    * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function info(){
+        $id = $this->request->post('id/d');
+        $info=$this->model->with(["brandInfo"])->findOrEmpty($id);
+        if($info->isEmpty()){
+            return error('未找到对应数据');
+        }
+        return success('获取成功',$info);
+
+    }
+    /**
+     * 品牌授权状态
+     * @param $param id 主键id status 状态
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\DbException
+    * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function status(){
+        $param = $this->request->param([
+            'id',
+            'status',
+        ],'post','intval');
+        $valid= Validate::rule([
+            'id|主键id'=>'require|number|gt:0',
+            'status|状态'=>'require|number|in:0,1',
+        ]);
+        if($valid->check($param)==false) return error($valid->getError());
+        $info=$this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            return error('未找到对应数据');
+        }
+        $info->status=$param['status'];
+        $save=$info->save();
+        if($save==false)return error(BrandBook::$statusCn[$param['status']].'失败');
+        return success(BrandBook::$statusCn[$param['status']].'成功');
+
+    }
+    /**
+     * 品牌授权删除
+     * @param $param id
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\DbException
+    * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function delete(){
+        $id=$this->request->post('id/d');
+        $info = $this->model->findOrEmpty($id);
+        if($info->isEmpty()){
+            return error('未找到对应数据');
+        }
+        $info->is_del=1;
+        $save=$info->save();
+        if($save==false)return error('删除失败');
+        return success('删除成功');
+
+    }
+    /**
+     * 品牌授权编辑
+     * @param id 主键id
+     * @param brand_book 授权书图片
+     * @param gyscode 供应商编号
+     * @param brand_id 品牌id
+     * @param is_del 删除状态
+     * @param remark 备注
+     * @param long 授权类型
+     * @param status 状态
+     * @param starttime 开始日期
+     * @param endtime 结束日期
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\DbException
+    * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function edit(){
+        $param = $this->request->param([
+        	'id',
+    		'brand_book',
+    		'gyscode',
+    		'brand_id',
+    		'is_del'=>0,
+    		'remark',
+    		'long',
+    		'status',
+    		'starttime'=>date('Y-m-d H:i:s'),
+    		'endtime'=>''],'post','trim');
+        $valid= Validate::rule([
+        	'id|主键id'=>'require|number|gt:0',
+        	'brand_book|授权书图片'=>'url',
+        	'gyscode|供应商编号'=>'require|max:255',
+        	'brand_id|品牌id'=>'require|number|gt:0|unique:app\admin\model\BrandBook,gyscode^is_del',
+        	'long|授权类型'=>'require|number|in:0,1',
+        	'status|状态'=>'require|number|in:0,1',
+        	'starttime|开始日期'=>'require|date|dateFormat:Y-m-d H:i:s',
+        	'endtime|结束日期'=>'requireIf:long,1|date|dateFormat:Y-m-d H:i:s',
+        	]);
+        if($valid->check($param)==false) return error($valid->getError());
+        $info=$this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            return error('未找到对应数据');
+        }
+        $info->brand_book=$param['brand_book'];
+        $info->gyscode=$param['gyscode'];
+        $info->gysname=\app\user\model\supplier::where('code',$param['gyscode'])->value('name');
+        $info->brand_id=$param['brand_id'];
+        $info->remark=$param['remark'];
+        $info->long=$param['long'];
+        $info->status=$param['status'];
+        $info->starttime=$param['starttime'];
+        $info->endtime=$param['long']==1?'':$param['endtime'];
+        $save=$info->save();
+        if($save==false)return error('修改失败');
+        return success('修改成功');
+    }
+    /**
+     * 品牌授权查询
+     * @param brand_id 品牌id
+     * @param gyscode 供应商编号
+     * @param is_del 删除状态
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\DbException
+    * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function query(){
+    	$param =$this->request->param(['brand_id'=>'','gyscode'=>'','is_del'=>0],'post','trim');
+    	$valid = Validate::rule(['brand_id|品牌id'=>'require|number|gt:0','gyscode|供应商编号'=>'require']);
+    	if($valid->check($param)==false) return error($valid->getError());
+    	$where=[["is_del","=",0]];
+    	if($param['brand_id']!=''){
+    		$where[]=["brand_id","=",$param['brand_id']];
+    	}
+    	if($param['gyscode']!=''){
+    		$where[]=["gyscode","=",$param['gyscode']];
+    	}
+    	$info =  $this->model->with(["brandInfo"])->where($where)->findOrEmpty();
+    	if($info->isEmpty()){
+    		return error('未找到对应数据');
+    	}
+    	return success('获取成功',$info);
+   }
+}

+ 3 - 13
app/admin/model/Base.php

@@ -10,17 +10,7 @@ use think\db\Builder;use think\Model;
  */
 class Base extends Model
 {
-    /**
- * @var array|string[]
- */
-     protected static function boot()
-    {
-        parent::boot();
-
-        // 应用全局作用域:未删除记录
-        static::addGlobalScope('isDel', function (Builder $builder) {
-            $builder->where('is_del', 0);
-        });
-    }
-  }
+    public static $statusCn = ["禁用","启用"];
+    public static $deleteCn = ["已删除","正常"];
+}
 

+ 2 - 1
app/admin/model/Brand.php

@@ -14,6 +14,7 @@ class Brand extends Base
         'is_del'       =>'tinyint',//
         'addtime'       =>'datetime',//
         'updatetime'       =>'datetime',//
-
     ];
+    protected $createTime='addtime';
+    protected $updateTime='updatetime';
 }

+ 7 - 1
app/admin/model/BrandBook.php

@@ -21,6 +21,12 @@ class BrandBook extends Base
         'is_del'       =>'tinyint',//
         'addtime'       =>'datetime',//
         'updatetime'       =>'datetime',//
-
     ];
+    protected $createTime='addtime';
+    protected $updateTime='updatetime';
+
+    public function brandInfo()
+    {
+        return $this->belongsTo(Brand::class,'brand_id','id')->bind(['brand_name']);
+    }
 }

+ 16 - 1
app/admin/route/api.php

@@ -23,4 +23,19 @@ route::rule('getDataGroupDetail', 'admin/UserGroup/info');//获取用户组详
 route::rule('editDataGroup', 'admin/UserGroup/save');//编辑用户组详情
 route::rule('deleteDataGroup', 'admin/UserGroup/delete');//删除用户组
 route::rule('statusDataGroup', 'admin/UserGroup/status');//启/禁用用户组
-route::rule('getDataGroupListAll', 'admin/UserGroup/getGroupAll');//获取用户组列表(全部)
+route::rule('getDataGroupListAll', 'admin/UserGroup/getGroupAll');//获取用户组列表(全部)
+//品牌
+Route::rule('brandcreate', 'admin/Brand/create');//品牌添加
+Route::rule('brandlist', 'admin/Brand/list');//品牌列表
+Route::rule('brandedit', 'admin/Brand/save');//品牌编辑
+Route::rule('brandstatus', 'admin/Brand/status');//品牌启/禁用
+Route::rule('branddel', 'admin/Brand/delete');//品牌删除
+Route::rule('brandquery', 'admin/Brand/getBrandList');//品牌查询
+//品牌授权
+Route::rule('keepbcreate', 'admin/BrandAuth/create');//品牌权限添加
+Route::rule('keepblist', 'admin/BrandAuth/list');//品牌权限列表
+Route::rule('keepbinfo', 'admin/BrandAuth/info');//品牌权限详情
+Route::rule('keepbedit', 'admin/BrandAuth/edit');//品牌权限编辑
+Route::rule('keepbstatus', 'admin/BrandAuth/status');//品牌权限启/禁用
+Route::rule('keepbdelete', 'admin/BrandAuth/delete');//品牌权限删除
+Route::rule('keepbquery', 'admin/BrandAuth/query');//品牌权限查询

+ 1 - 2
app/bug/model/WorkAction.php

@@ -19,8 +19,7 @@ class WorkAction extends Base
         'createTime'       =>'datetime',//
         'updateTime'       =>'datetime',//
         'delete_time'       =>'datetime',//
-
-];
+    ];
     protected $updateTime='updateTime';
     protected $createTime='createTime';
     protected $deleteTime = 'delete_time';

+ 141 - 0
app/user/controller/Business.php

@@ -0,0 +1,141 @@
+<?php
+
+
+namespace app\user\controller;
+
+
+use think\App;use think\facade\Cache;use think\facade\Validate;
+class Business extends Base{
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->model=new \app\user\model\Business();
+    }
+
+    public function list(){
+            $param = $this->request->param([
+                    'page' => 1,
+                    'size' => 10,
+                    'company' => '',
+                    'status' => '',
+                    'createrid' => '',
+                    'start' => '',
+                    'end' => '',
+                    'company_name' => '',
+                ], 'post', 'trim');
+            $where = [["is_del","=",0]];
+            if($param['company']!='')$where[]=['company','like','%'.$param['company'].'%'];
+            if($param['status']!='')$where[]=['status','=',$param['status']];
+            if($param['createrid']!='')$where[]=['createrid','=',$param['createrid']];
+            if($param['start']!='')$where[]=['create_time','>=',startTime($param['start'])];
+            if($param['end']!='')$where[]=['create_time','<=',endTime($param['end'])];
+            $list= $this->model->where($where)->order('id desc')->paginate(["list_rows"=>$param['size'],
+            "page"=>$param['page']]);
+            return success('获取成功',["list"=>$list->items(),"count"=>$list->total()]);
+    }
+
+    public function create(){
+        $param = $this->request->param(["company"=>"","inv_addr"=>"","mobile"=>"","inv_code"=>"","inv_bank"=>"",'is_del'=>'0',
+        "inv_bankNo"=>"","license_img"=>"","inv_time"=>"","inv_legaler"=>"","type"=>"","contactor"=>"","addr"=>"","inv_scope"=>""
+        ,"invoice_title"=>""],"post","trim");
+        $valid =Validate::rule([
+            'company|业务公司名称' => 'require|max:255|unique:app\user\model\Business,is_del',
+            'inv_addr|公司地址' => 'require|max:255',
+            'mobile|公司联系方式' => 'require|max:255',
+            'inv_code|公司纳税编号' => 'require|max:255',
+            'inv_bank|开户行' => 'require|max:255',
+            'inv_bankNo|银行账户' => 'require|max:255',
+            'license_img|营业执照' => 'require|url',
+            'inv_time|成立日期' => 'require|max:255',
+            'inv_legaler|法人' => 'require|max:255',
+            'type|类型' => 'require|max:255',
+            'contactor|联系人' => 'require|max:255',
+            'addr|地址' => 'require|max:255',
+            'inv_scope|经营范围' => 'require|max:255',
+            "invoice_title|发票抬头"=>"require|max:255"
+        ]);
+        if(!$valid->check($param)){
+            return error($valid->getError());
+        }
+        $data = [
+            'company' => $param['company'],
+            'companyNo' =>makeNo('GS'),
+            'inv_code' =>$param['inv_code'],
+            'type' => $param['type'],
+            'inv_legaler' => $param['inv_legaler'],
+            'inv_time' => $param['inv_time'],
+            'inv_addr' => $param['inv_addr'],
+            'inv_bank' => $param['inv_bank'],
+            'inv_bankNo' => $param['inv_bankNo'],
+            'invoice_title' => $param['invoice_title'],
+            'contactor' => $param['contactor'],
+            'mobile' => $param['mobile'],
+            'addr' => $param['addr'],
+            'creater' => $this->uname,
+            'createrid' => $this->uid,
+            'inv_scope' => $param['inv_scope'],
+            'license_img' =>$param['license_img'],
+        ];
+
+        $model = $this->model->create($data);
+        if($model->isEmpty())return error('添加失败');
+            $headquarters = new \app\user\model\Headquarters();
+            $headquarters->create([
+                'code'=>$model->companyNo,
+                'name'=>$param['company'],
+                'type'=>1,
+                'company_type'=>$param['type'],
+                'invoice_title'=>$param['invoice_title'],
+                'invoice_people'=>$param['inv_legaler'],
+                'invoice_addr'=>$param['inv_addr'],
+                'invoice_mobile'=>$param['mobile'],
+                'invoice_code'=>$param['inv_code'],
+                'invoice_bank'=>$param['inv_bank'],
+                'invoice_bankNo'=>$param['inv_bankNo'],
+                'invoice_img'=>$param['license_img'],
+                'remark'=>"",
+                'status'=>1,
+                'is_del'=>0,
+                'creater'=>$this->uname,
+                'createrid'=>$this->uid,
+            ]);
+//        Cache::store('redis')->handler()->lpush('companycopy',json_encode($data,JSON_UNESCAPED_UNICODE));
+        return success('添加成功');
+    }
+
+    public function save(){
+        $param = $this->request->param(["id"=>"","inv_addr"=>"","inv_code"=>"","inv_bank"=>"",'is_del'=>'0',
+            "inv_bankNo"=>"" ,"invoice_title"=>""],"post","trim");
+        $valid =Validate::rule([
+            'id|id' => 'require|int',
+            'inv_addr|公司地址' => 'require|max:255',
+            'inv_code|公司纳税编号' => 'require|max:255',
+            'inv_bank|开户行' => 'require|max:255',
+            'inv_bankNo|银行账户' => 'require|max:255',
+            'invoice_title|发票抬头' => 'require|max:255'
+        ]);
+        if(!$valid->check($param)) return error($valid->getError());
+        $model = $this->model->findOrEmpty($param['id']);
+        if($model->isEmpty())return error('数据不存在');
+        $model->inv_addr = $param['inv_addr'];
+        $model->inv_code = $param['inv_code'];
+        $model->inv_bank = $param['inv_bank'];
+        $model->inv_bankNo = $param['inv_bankNo'];
+        $model->invoice_title = $param['invoice_title'];
+        if($model->save()){
+            $headquarters = new \app\user\model\Headquarters();
+            $headquarters->update([
+                'invoice_title'=>$param['invoice_title'],
+                'invoice_people'=>$param['inv_legaler'],
+                'invoice_addr'=>$param['inv_addr'],
+                'invoice_mobile'=>$param['mobile'],
+                'invoice_code'=>$param['inv_code'],
+                'invoice_bank'=>$param['inv_bank'],
+                'invoice_bankNo'=>$param['inv_bankNo'],
+                'updater'=>$this->uname,
+                'updaterid'=>$this->uid,
+            ],['code'=>$model->companyNo]);
+           }
+//        Cache::store('redis')->handler()->lpush('companycopy',json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
+        return success('保存成功');
+    }
+}

+ 56 - 0
app/user/controller/Company.php

@@ -0,0 +1,56 @@
+<?php
+
+
+namespace app\user\controller;
+
+
+use think\App;use think\facade\Validate;
+class Company extends Base{
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->model=new \app\user\model\Headquarters();
+    }
+    /**
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DbException
+     */
+    public function list(){
+        $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' =>
+         '', 'account_id' => '', 'type' => ''], 'post');
+        $condition = [['is_del', '=', 0]];
+        if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
+        if ($post['name'] != '') $condition[] = ['name', 'like', "%{$post['name']}%"];
+        if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
+        if ($post['account_id'] != '') $condition[] = ['code', 'in', function ($query) use ($post) {
+            return $query->name('account_company')->where(['account_id'=>$post['account_id'],"is_del"=>0,'status'=>1])
+            ->column('companyCode');
+        }];
+        if ($post['type'] != '') $condition[] = ['type', '=', $post['type']];
+        $list = $this->model->field('id,code,name,type,status,addtime,relation_code')->where($condition)->order('id', 'desc')->paginate( ['page' => $post['page'], 'list_rows'
+         => $post['size']]);
+        return success('获取成功', ["list"=>$list->items(),"count"=>$list->total()]);
+    }
+    /**
+    * @return \think\Response|\think\response\Json
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\DbException
+    * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function query(){
+        $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'size' => 100, 'account_id' => '',
+         'type' => ''], 'post');
+        $condition = [['is_del', '=', 0]];
+        if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
+        if ($post['name'] != '') $condition[] =['name', 'like', "%{$post['name']}%"];
+        if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
+        if ($post['account_id'] != '') $condition[] = ['code', 'in', function ($query) use ($post) {
+            return $query->name('account_company')->where(['account_id'=>$post['account_id'],"is_del"=>0,'status'=>1])
+            ->column('companyCode');
+        }];
+        if ($post['type'] != '') $condition[] = ['type', '=', $post['type']];
+        $list = $this->model->field('id,code,name,type,status,addtime,relation_code,length(name) len_name')->where
+        ($condition)->order('len_name', 'asc')->select();
+        return success('获取成功', $list);
+    }
+
+}

+ 14 - 0
app/user/model/Headquarters.php

@@ -29,4 +29,18 @@ class Headquarters extends Base
         'updatetime'       =>'datetime',//修改时间
         'relation_code'       =>'char',//关联编码(目前只有供应商升级为业务公司时有用,存储业务公司编码)
     ];
+    protected $createTime = 'addtime';
+    protected $updateTime = 'updatetime';
+
+    public function companyInfo(){
+        return $this->belongsTo(Business::class,'code','companyNo');
+    }
+
+    public function supplierInfo(){
+        return $this->belongsTo(Supplier::class,'code','code');
+    }
+
+    public function customerInfo(){
+        return $this->belongsTo(CustomerInfo::class,'code','companyNo');
+    }
 }