feat:supplier

This commit is contained in:
LAPTOP-7SGDREK0\shiweijun
2025-01-22 17:53:00 +08:00
parent d231f343d3
commit 4e11fbaec8
5 changed files with 284 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace App\Service\Admin\Material;
use App\Exception\ErrException;
use App\Model\Supplier;
use App\Service\Admin\BaseService;
use Hyperf\Di\Annotation\Inject;
class SupplierService extends BaseService{
/**
* @var Supplier
*/
#[Inject]
protected Supplier $SupplierModel;
public function handle()
{
}
/**
* @return array
*/
public function list():array
{
$limit = (int)$this->request->input('limit', 10);
$name = (int)$this->request->input('query_name');
$list = $this->SupplierModel
->leftJoin('system_city','system_city.id','supplier.city_id')
->leftJoin('kitchen','kitchen.id','supplier.kitchen_id')
->where('supplier.is_del',1)
->when(!empty($name), function ($query) use ($name) {
$query->where('supplier.name', 'like', "$name%");
})
->paginate($limit,['supplier.*','system_city.title as city_name','kitchen.name as kitchen_name'])
->toArray();
return $this->return->success('success',$list);
}
/**
* @return array
*/
public function add():array
{
$name = $this->request->input('name');
$mobile = $this->request->input('mobile');
$address = $this->request->input('address');
$city_id = (int)$this->request->input('city_id');
$kitchen_id = (int)$this->request->input('kitchen_id');
$supplier = new Supplier();
$supplier->name = $name;
$supplier->mobile = $mobile;
$supplier->address = $address;
$supplier->city_id = $city_id;
$supplier->kitchen_id = $kitchen_id;
if (!$supplier->save()) throw new ErrException('供应商添加失败');
return $this->return->success();
}
public function edit():array
{
$id = (int)$this->request->input('id');
$name = $this->request->input('name');
$mobile = $this->request->input('mobile');
$address = $this->request->input('address');
$info = $this->SupplierModel->getInfoById($id);
if (empty($info)) throw new ErrException('数据不存在');
if(!empty($name)) $info->name = $name;
if(!empty($mobile)) $info->mobile = $mobile;
if(!empty($address)) $info->address = $address;
if (!$info->save()) throw new ErrException('供应商修改失败');
return $this->return->success();
}
/**
* @return array
*/
public function delete(): array
{
$id = (int)$this->request->input('id');
$info = $this->SupplierModel->getInfoById($id);
if (empty($info)) throw new ErrException('供应商不存在');
$info->is_del = 2;
if (!$info->save()) throw new ErrException('删除失败');
return $this->return->success();
}
}