new-admin-api/app/controller/admin/supplier/Supplier.php

103 lines
3.2 KiB
PHP

<?php
namespace app\controller\admin\supplier;
use app\services\supplier\SystemSupplierServices;
use crmeb\basic\BaseController;
use think\App;
use think\exception\ValidateException;
class Supplier extends BaseController{
public function __construct(App $app, SystemSupplierServices $services){
parent::__construct($app);
$this->services = $services;
}
/**
* Common: 账号添加
* Author: wu-hui
* Time: 2024/01/17 11:43
* @return mixed
*/
public function editInfo(){
// 参数获取
$data = $this->checkParam();
if((int)$data['supplierId'] > 0){
// 编辑账号信息
$this->services->editInfo((array)$data);
}else{
// 添加账号
$this->services->create((array)$data);
}
return app('json')->success('添加成功');
}
/**
* Common: 添加|编辑 账号参数获取
* Author: wu-hui
* Time: 2024/01/17 10:56
* @return array
*/
private function checkParam():array{
// 接收表单参数
$supplierId = (int)$this->request->param('id');
$accountInfo = $this->request->params([
'supplier_name',
'detailed_address',
'name',
['phone',''],
'email',
'sort',
'is_show',
'is_examine',
'mark',
['invite_agent_id',''],
['invite_uid',''],
]);
$accountPassword = $this->request->params([
'supplier_account',
'supplier_password',
]);
// 数据判断
$nameIsHave = $this->services->isHave('supplier_name',$accountInfo['supplier_name'],$supplierId);
if($nameIsHave) throw new ValidateException('供应商名称已经存在,请勿重复添加!');
if (!empty($accountInfo['phone']) && isPhone($accountInfo['phone'])) throw new ValidateException('请输入正确的手机号!');
$accountIsHas = $this->services->accountIsHas($accountPassword['supplier_account'],$supplierId);
if($accountIsHas) throw new ValidateException('账号已存在,请勿重复添加!');
return compact('supplierId','accountInfo','accountPassword');
}
/**
* Common: 获取列表
* Author: wu-hui
* Time: 2024/01/17 14:29
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(){
$search = $this->request->params(['supplier_name','name','phone','is_show']);
[$page, $limit] = $this->getPage();
$field = 'id,supplier_name,avatar,name,phone,is_show,add_time,sort,add_time,invite_uid,invite_agent_id';
$data = $this->services->supplierList($search, $page, $limit, $field);
return app('json')->success($data);
}
/**
* Common: 获取单条供应商信息
* Author: wu-hui
* Time: 2024/01/29 11:40
* @param $id
* @return mixed
*/
public function supplierInfo($id){
$info = $this->services->getSingleInfo(['id'=>$id]);
return app('json')->success($info);
}
}