Commit 25073c05 authored by 王源's avatar 王源 🎧

调整文件目录结构

parent 1b77f70a
<?php
/**
* Created by PhpStorm.
* UserInterface: 梁俊杰
* Date: 2019/11/18
* Time: 17:15
* Description:
*/
namespace Meibuyu\Micro;
interface CategoryInterface
{
/**
* 新增品类
* @param array $attribute
* @return bool
*/
public function add($attribute);
/**
* 更新品类
* @param array $attribute
* @param int $id
* @return bool
*/
public function update($attribute, $id);
public function delete($id);
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:44
* Description:
*/
namespace Meibuyu\Micro;
interface DepartmentInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:43
* Description:
*/
namespace Meibuyu\Micro;
interface FactoryInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/12/03
* Time: 16:08
* Description:
*/
namespace Meibuyu\Micro;
class Helper
{
/**
* 获取唯一编号
* @param string $prefix
* @return string
*/
public static function uid($prefix = '')
{
return uniqid($prefix);
}
/**
* 返回成功消息
* @param array|string $data 返回数据 默认空
* @param string $msg 消息,默认 Success
* @param int $code 成功代码,默认200
* @return array
*/
public static function success($data = '', $msg = 'success', $code = 200)
{
return self::response($data, $msg, $code);
}
/**
* 返回失败消息
* @param array|string $data 返回数据 默认空
* @param string $msg 消息,默认 Error
* @param int $code 失败代码,默认400
* @return array
*/
public static function fail($data = '', $msg = 'fail', $code = 400)
{
return self::response($data, $msg, $code);
}
/**
* 返回操作消息
* @param array|string $data 返回数据 默认空
* @param string $msg 消息,默认空
* @param int $code 操作代码,默认200
* @return array
*/
public static function response($data = '', $msg = '', $code = 200)
{
return ['data' => $data, 'msg' => $msg, 'code' => $code];
}
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:42
* Description:
*/
namespace Meibuyu\Micro;
interface LogisticsInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:42
* Description:
*/
namespace Meibuyu\Micro;
interface MaterialInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:41
* Description:
*/
namespace Meibuyu\Micro;
interface MessageInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:41
* Description:
*/
namespace Meibuyu\Micro;
interface PermissionInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:40
* Description:
*/
namespace Meibuyu\Micro;
interface ProductChildInterface
{
}
<?php
/**
* Created by PhpStorm.
* UserInterface: 梁俊杰
* Date: 2019/11/18
* Time: 17:15
* Description:
*/
namespace Meibuyu\Micro;
interface ProductInterface
{
/**
* 新增品类
* @param array $attribute
* @return bool
*/
public function add($attribute);
/**
* 更新品类
* @param array $attribute
* @param int $id
* @return bool
*/
public function update($attribute, $id);
public function delete($id);
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:39
* Description:
*/
namespace Meibuyu\Micro;
interface RoleInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 王源
* Date: 2020/1/9
* Time: 15:08
*/
namespace Meibuyu\Micro\Service;
use Exception;
use Hyperf\DbConnection\Model\Model;
use Meibuyu\Micro\Helper;
class BaseService
{
/**
* @var Model
*/
protected $model;
/**
* 查找一个数据
* @param $id
* @return Model | array
*/
public function find($id)
{
$model = $this->model->find($id);
if (!$model) {
return Helper::fail('', '数据不存在', 404);
}
return $model;
}
/**
* 获取一条数据
* @param $id
* @return array
*/
public function get($id)
{
$model = $this->find($id);
return Helper::success($model);
}
/**
* 插入一条数据
* @param array $data
* @return array
*/
public function insert(array $data)
{
try {
$res = $this->model->insert($data);
return Helper::success($res);
} catch (Exception $e) {
return Helper::fail('', $e->getMessage());
}
}
/**
* 新增一条数据
* @param array $data
* @return array
*/
public function create(array $data)
{
try {
$model = $this->model->newInstance($data);
$model->save();
return Helper::success($model);
} catch (Exception $e) {
return Helper::fail('', $e->getMessage());
}
}
/**
* 更新数据
* @param $id
* @param array $data
* @return array
*/
public function update($id, array $data)
{
try {
$model = $this->find($id);
$model->fill($data);
$model->save();
return Helper::success($model);
} catch (Exception $e) {
return Helper::fail('', $e->getMessage());
}
}
/**
* 删除数据
* @param $id
* @return array
*/
public function delete($id)
{
try {
$model = $this->find($id);
$res = $model->delete();
if ($res) {
return Helper::success($res, '删除成功');
} else {
return Helper::fail($res, '删除失败');
}
} catch (Exception $e) {
return Helper::fail('', $e->getMessage());
}
}
}
<?php
/**
* Created by PhpStorm.
* User: 王源
* Date: 2020/1/9
* Time: 15:07
*/
namespace Meibuyu\Micro\Service\Interfaces;
interface UserServiceInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:38
* Description:
*/
namespace Meibuyu\Micro;
interface SiteInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:38
* Description:
*/
namespace Meibuyu\Micro;
interface SizeInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:37
* Description:
*/
namespace Meibuyu\Micro;
interface SupplierInterface
{
}
<?php
/**
* Created by PhpStorm.
* User: 梁俊杰
* Date: 2019/11/19
* Time: 08:37
* Description:
*/
namespace Meibuyu\Micro;
interface TeamInterface
{
}
<?php
/**
* Created by PhpStorm.
* UserInterface: 梁俊杰
* Date: 2019/11/19
* Time: 08:36
* Description:
*/
namespace Meibuyu\Micro;
interface UserInterface
{
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment