pull/1/head
parent
f26a27fec5
commit
6856f5c2cc
@ -0,0 +1,143 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* 服务控制器 |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace app\api\controller; |
||||||
|
|
||||||
|
use app\api\model\Server\ServerCategory; |
||||||
|
use app\api\model\Server\ServerOrder; |
||||||
|
use app\common\enum\ServerEnum; |
||||||
|
use cores\exception\BaseException; |
||||||
|
use think\db\exception\DataNotFoundException; |
||||||
|
use think\db\exception\DbException; |
||||||
|
use think\db\exception\ModelNotFoundException; |
||||||
|
use think\response\Json; |
||||||
|
|
||||||
|
class Server extends Controller |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @notes:分类列表 |
||||||
|
* @return Json |
||||||
|
* @throws DataNotFoundException |
||||||
|
* @throws DbException |
||||||
|
* @throws ModelNotFoundException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function categoryList(): Json |
||||||
|
{ |
||||||
|
$model = new ServerCategory(); |
||||||
|
$list = $model->list(); |
||||||
|
if (!empty($list)) { |
||||||
|
foreach ($list as $key => $value) { |
||||||
|
unset($list[$key]['image']); |
||||||
|
} |
||||||
|
} |
||||||
|
return $this->renderSuccess(compact('list')); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes:服务列表页 |
||||||
|
* @throws DbException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function list(): Json |
||||||
|
{ |
||||||
|
$server_name = $this->request->post('server_name'); |
||||||
|
$category_id = intval($this->request->post('category_id')); |
||||||
|
$where = []; |
||||||
|
if ($server_name) { |
||||||
|
$where[] = ['server.server_name', 'like', "%$server_name%"]; |
||||||
|
} |
||||||
|
if ($category_id) { |
||||||
|
$where[] = ['server.category_id', '=', $category_id]; |
||||||
|
} |
||||||
|
$model = new \app\api\model\Server($where); |
||||||
|
$list = $model->getList(); |
||||||
|
$data['list'] = $list->items(); |
||||||
|
$data['total'] = $list->total(); |
||||||
|
if (!$list->isEmpty()) { |
||||||
|
foreach ($data['list'] as $key => $value) { |
||||||
|
unset($data['list'][$key]['image']); |
||||||
|
unset($data['list'][$key]['category']); |
||||||
|
} |
||||||
|
} |
||||||
|
return $this->renderSuccess($data); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes:订单状态 |
||||||
|
* @return Json |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function orderStatus(): Json |
||||||
|
{ |
||||||
|
$list = array_values(ServerEnum::data()); |
||||||
|
return $this->renderSuccess(compact('list')); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes:用户订单列表 |
||||||
|
* @throws DbException |
||||||
|
* @throws BaseException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function userOrderList(): Json |
||||||
|
{ |
||||||
|
$order_no = $this->request->post('order_no'); |
||||||
|
$order_status = intval($this->request->post('order_status')); |
||||||
|
$where = []; |
||||||
|
if (!empty($order_no)) { |
||||||
|
$where['order_no'] = $order_no; |
||||||
|
} |
||||||
|
if ($order_status) { |
||||||
|
$where['order_status'] = $order_status; |
||||||
|
} |
||||||
|
$model = new ServerOrder($where); |
||||||
|
$list = $model->userOrders($where); |
||||||
|
$data['list'] = $list->items(); |
||||||
|
$data['total'] = $list->total(); |
||||||
|
if (!$list->isEmpty()) { |
||||||
|
if (!$list->isEmpty()) { |
||||||
|
foreach ($data['list'] as $key => $value) { |
||||||
|
unset($data['list'][$key]['image']); |
||||||
|
unset($data['list'][$key]['dealer']); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return $this->renderSuccess($data); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes: |
||||||
|
* @return Json |
||||||
|
* @throws BaseException |
||||||
|
* @throws DbException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function dealerOrderList(): Json |
||||||
|
{ |
||||||
|
$order_no = $this->request->post('order_no'); |
||||||
|
$order_status = intval($this->request->post('order_status')); |
||||||
|
$where = []; |
||||||
|
if (!empty($order_no)) { |
||||||
|
$where['order_no'] = $order_no; |
||||||
|
} |
||||||
|
if ($order_status) { |
||||||
|
$where['order_status'] = $order_status; |
||||||
|
} |
||||||
|
$model = new ServerOrder($where); |
||||||
|
$list = $model->dealerOrders($where); |
||||||
|
$data['list'] = $list->items(); |
||||||
|
$data['total'] = $list->total(); |
||||||
|
if (!$list->isEmpty()) { |
||||||
|
if (!$list->isEmpty()) { |
||||||
|
foreach ($data['list'] as $key => $value) { |
||||||
|
unset($data['list'][$key]['image']); |
||||||
|
unset($data['list'][$key]['dealer']); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return $this->renderSuccess($data); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\api\model; |
||||||
|
|
||||||
|
use app\common\model\server\Server as BaseServer; |
||||||
|
|
||||||
|
class Server extends BaseServer |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 隐藏字段 |
||||||
|
* @var array |
||||||
|
*/ |
||||||
|
protected $hidden = [ |
||||||
|
'store_id', |
||||||
|
'create_time', |
||||||
|
'update_time', |
||||||
|
'status', |
||||||
|
'image_id', |
||||||
|
'delete_time', |
||||||
|
]; |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\api\model\Server; |
||||||
|
|
||||||
|
use app\api\model\UploadFile; |
||||||
|
use app\common\model\ServerCategory as BaseServerCategory; |
||||||
|
use think\db\exception\DataNotFoundException; |
||||||
|
use think\db\exception\DbException; |
||||||
|
use think\db\exception\ModelNotFoundException; |
||||||
|
use think\model\relation\HasOne; |
||||||
|
|
||||||
|
class ServerCategory extends BaseServerCategory |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 隐藏字段 |
||||||
|
* @var array |
||||||
|
*/ |
||||||
|
protected $hidden = [ |
||||||
|
'store_id', |
||||||
|
'create_time', |
||||||
|
'update_time', |
||||||
|
'status', |
||||||
|
'image_id', |
||||||
|
]; |
||||||
|
|
||||||
|
/** |
||||||
|
* 分类图片 |
||||||
|
* @return HasOne |
||||||
|
*/ |
||||||
|
public function image(): HasOne |
||||||
|
{ |
||||||
|
return $this->hasOne(UploadFile::class, 'file_id', 'image_id') |
||||||
|
->bind(['image_url' => 'preview_url']); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes:获取全部记录 |
||||||
|
* @return array |
||||||
|
* @throws DataNotFoundException |
||||||
|
* @throws DbException |
||||||
|
* @throws ModelNotFoundException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function list(): array |
||||||
|
{ |
||||||
|
return $this->with(['image']) |
||||||
|
->order(['sort', 'create_time']) |
||||||
|
->select() |
||||||
|
->toArray(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\api\model\Server; |
||||||
|
|
||||||
|
|
||||||
|
use app\api\service\User as UserService; |
||||||
|
use app\common\model\server\Order; |
||||||
|
use cores\exception\BaseException; |
||||||
|
use think\db\exception\DbException; |
||||||
|
use think\Paginator; |
||||||
|
|
||||||
|
class ServerOrder extends Order |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 隐藏字段 |
||||||
|
* @var array |
||||||
|
*/ |
||||||
|
protected $hidden = [ |
||||||
|
'store_id', |
||||||
|
'create_time', |
||||||
|
'update_time', |
||||||
|
'trade_id', |
||||||
|
'server_image_id', |
||||||
|
'is_delete', |
||||||
|
]; |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes:用户服务订单列表 |
||||||
|
* @param $where |
||||||
|
* @param int $listRows |
||||||
|
* @return Paginator |
||||||
|
* @throws BaseException |
||||||
|
* @throws DbException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function userOrders($where, int $listRows = 15): Paginator |
||||||
|
{ |
||||||
|
// 当前用户ID |
||||||
|
$userId = UserService::getCurrentLoginUserId(); |
||||||
|
// 查询列表数据 |
||||||
|
return $this->with(['image', 'dealer']) |
||||||
|
->where($where) |
||||||
|
->where('user_id', '=', $userId) |
||||||
|
->where('is_delete', '=', 0) |
||||||
|
->order(['create_time' => 'desc']) |
||||||
|
->paginate($listRows); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @notes:分销员订单列表 |
||||||
|
* @param $where |
||||||
|
* @param int $listRows |
||||||
|
* @return Paginator |
||||||
|
* @throws BaseException |
||||||
|
* @throws DbException |
||||||
|
* @author: wanghousheng |
||||||
|
*/ |
||||||
|
public function dealerOrders($where, int $listRows = 15): Paginator |
||||||
|
{ |
||||||
|
// 当前用户ID |
||||||
|
$userId = UserService::getCurrentLoginUserId(); |
||||||
|
// 查询列表数据 |
||||||
|
return $this->with(['image', 'user']) |
||||||
|
->where($where) |
||||||
|
->where('dealer_id', '=', $userId) |
||||||
|
->where('is_delete', '=', 0) |
||||||
|
->order(['create_time' => 'desc']) |
||||||
|
->paginate($listRows); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace app\common\enum\user; |
||||||
|
|
||||||
|
use app\common\enum\EnumBasics; |
||||||
|
|
||||||
|
class UserTypeEnum extends EnumBasics |
||||||
|
{ |
||||||
|
// 普通用户 |
||||||
|
const NORMAL = 10; |
||||||
|
|
||||||
|
// 会员用户 |
||||||
|
const MEMBER = 20; |
||||||
|
|
||||||
|
// 分销商用户 |
||||||
|
const DEALER = 30; |
||||||
|
|
||||||
|
// 店长用户 |
||||||
|
const STORE = 40; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取用户类型值 |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public static function data(): array |
||||||
|
{ |
||||||
|
return [ |
||||||
|
self::NORMAL => [ |
||||||
|
'name' => '普通会员', |
||||||
|
'value' => self::NORMAL, |
||||||
|
], |
||||||
|
self::MEMBER => [ |
||||||
|
'name' => 'PLUS会员', |
||||||
|
'value' => self::MEMBER, |
||||||
|
], |
||||||
|
self::DEALER => [ |
||||||
|
'name' => '分销商', |
||||||
|
'value' => self::DEALER, |
||||||
|
], |
||||||
|
self::STORE => [ |
||||||
|
'name' => '店长', |
||||||
|
'value' => self::STORE, |
||||||
|
] |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据值获取名称 |
||||||
|
* @param string $value |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public static function getName(string $value): string |
||||||
|
{ |
||||||
|
return self::data()[$value]['name']; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue