Compare commits
2 Commits
d74728f179
...
23e783b6ab
Author | SHA1 | Date |
---|---|---|
zwesy | 23e783b6ab | |
zwesy | 77fc66fe0d |
|
@ -1,272 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\model\AccountRecord;
|
||||
use app\model\Disease;
|
||||
use app\repository\ArchivesRepository;
|
||||
use Exception;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\response\Json;
|
||||
use app\exception\RepositoryException;
|
||||
|
||||
class Archives extends Base
|
||||
{
|
||||
protected $noNeedLogin = ['course', 'detail'];
|
||||
|
||||
/**
|
||||
* 病种列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function disease(): Json
|
||||
{
|
||||
$data = Disease::getListByPid();
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 病种问题文章列表 分类问题
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function diseaseQuestion(): Json
|
||||
{
|
||||
$diseaseId = input('disease_id/d', 0);
|
||||
|
||||
try {
|
||||
$data = ArchivesRepository::getInstance()->diseaseQuestion($diseaseId);
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
ArchivesRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恒美小课堂
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function course(): Json
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$courseId = input('course_id/d', 0);
|
||||
$page = input('page/d', 1);
|
||||
$size = input('size/d', 20);
|
||||
|
||||
try {
|
||||
$data = ArchivesRepository::getInstance()->course($accountId, $courseId, $page, $size);
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
ArchivesRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 热门推荐
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function hot(): Json
|
||||
{
|
||||
$categoryId = input('category_id/d', 0);
|
||||
$page = input('page/d', 1);
|
||||
$size = input('size/d', 20);
|
||||
$keyword = input('keyword/s', '');
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$where[] = ['hot', '=', 1];
|
||||
if (!empty($keyword)) {
|
||||
|
||||
$keyword = trim($keyword);
|
||||
$where[] = ['title|subtitle|disease_name|doctor_name', 'like', '%'.$keyword.'%'];
|
||||
AccountRecord::saveSearch($accountId, $keyword);
|
||||
}
|
||||
$data = ArchivesRepository::getInstance()->category($accountId, $categoryId, $where, $page, $size);
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
ArchivesRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定栏目内容列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function category(): Json
|
||||
{
|
||||
$categoryId = input('category_id/d', 0);
|
||||
$page = input('page/d', 1);
|
||||
$size = input('size/d', 20);
|
||||
$keyword = input('keyword/s', '');
|
||||
$diseaseIds = input('disease_id/s', '');//病种 多个用逗号分隔
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$where = [];
|
||||
if (!empty($keyword)) {
|
||||
$keyword = trim($keyword);
|
||||
$where[] = ['title|subtitle|disease_name|doctor_name', 'like', '%'.$keyword.'%'];
|
||||
AccountRecord::saveSearch($accountId, $keyword);
|
||||
}
|
||||
|
||||
if (!empty($diseaseIds)) {
|
||||
$where[] = ['disease_id', 'in', explode(',', $diseaseIds)];
|
||||
}
|
||||
|
||||
$data = ArchivesRepository::getInstance()->category($accountId, $categoryId, $where, $page, $size);
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
ArchivesRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取关于我们栏目内容列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function about(): Json
|
||||
{
|
||||
$categoryId = input('category_id/d', 0);
|
||||
$page = input('page/d', 1);
|
||||
$size = input('size/d', 20);
|
||||
$exceptId = input('except_id/d', 0);
|
||||
$keyword = input('keyword/s', '');
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$where = [];
|
||||
if (!empty($keyword)) {
|
||||
$keyword = trim($keyword);
|
||||
$where[] = ['title|subtitle|disease_name|doctor_name', 'like', '%'.$keyword.'%'];
|
||||
AccountRecord::saveSearch($accountId, $keyword);
|
||||
}
|
||||
|
||||
if ($exceptId > 0) {
|
||||
$where[] = ['id', '<>', $exceptId];
|
||||
}
|
||||
|
||||
$order = ['published_at' => 'desc'];
|
||||
|
||||
$data = ArchivesRepository::getInstance()->about($accountId, $categoryId, $where, $page, $size, $order);
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
ArchivesRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容详情
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function detail(): Json
|
||||
{
|
||||
$id = input('id/d', 0);
|
||||
$shareId = input('share_id/d', 0);//分享人ID
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$data = ArchivesRepository::getInstance()->detail($id, $accountId, $shareId);
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
ArchivesRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '获取详情失败');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞、收藏
|
||||
*/
|
||||
public function record(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4000, '无效请求');
|
||||
}
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$archiveId = $this->request->param('archive_id/d', 0);
|
||||
$action = $this->request->param('action/s', '');
|
||||
|
||||
try {
|
||||
ArchivesRepository::getInstance()->record($accountId, $archiveId, $action);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消 点赞、收藏
|
||||
*/
|
||||
public function unRecord(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4000, '无效请求');
|
||||
}
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$archiveId = $this->request->param('archive_id/d', 0);
|
||||
$action = $this->request->param('action/s', '');
|
||||
|
||||
try {
|
||||
ArchivesRepository::getInstance()->unRecord($accountId, $archiveId, $action);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户内容收藏列表
|
||||
*/
|
||||
public function collects(): Json
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$categoryId = $this->request->param('category_id/d', 0);
|
||||
$page = $this->request->param('page/d', 1);
|
||||
$size = $this->request->param('size/d', 10);
|
||||
|
||||
$page = $page <= 0 ? 1 : $page;
|
||||
$size = $size <= 0 ? 10 : $size;
|
||||
$data = ArchivesRepository::getInstance()->accountCollects($accountId, $categoryId, $page, $size);
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\repository\AccountRepository;
|
||||
use app\repository\CommonRepository;
|
||||
use app\repository\OperationRepository;
|
||||
use app\repository\OrderRepository;
|
||||
use app\service\Sms;
|
||||
use app\validate\CommonValidate;
|
||||
use think\Collection;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\response\Json;
|
||||
|
||||
class Common extends Base
|
||||
{
|
||||
protected $noNeedLogin = [
|
||||
'slidePositions',
|
||||
'slides',
|
||||
];
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/common/send-code",
|
||||
* tags={"common"},
|
||||
* operationId="sendCode",
|
||||
* )
|
||||
*/
|
||||
public function sendCode(): Json
|
||||
{
|
||||
$input = input('post.');
|
||||
$validate = new CommonValidate();
|
||||
if (!$validate->scene('send_sms')->check($input)) {
|
||||
return $this->json(4001, '参数错误');
|
||||
}
|
||||
if (!in_array($input['type'], ['register', 'login', 'binding'])) {
|
||||
return $this->json(4002, '参数错误');
|
||||
}
|
||||
|
||||
CommonRepository::getInstance()->sendSms($input['phone'], $input['type']);
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看轮播图可视位置配置信息
|
||||
*/
|
||||
public function slidePositions(): Json
|
||||
{
|
||||
$repo = OperationRepository::getInstance();
|
||||
$list = $repo->slidePositions();
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 轮播图
|
||||
*/
|
||||
public function slides(): Json
|
||||
{
|
||||
$size = $this->request->param('size/d', 0);
|
||||
$position = trim($this->request->param('position/s', ''));
|
||||
if (empty($position)) {
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
try {
|
||||
$repo = OperationRepository::getInstance();
|
||||
$list = $repo->slideListByPosition($position, $size);
|
||||
} catch (\Exception $e) {
|
||||
$list = new Collection();
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快递公司列表
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
* @throws DbException
|
||||
* @throws DataNotFoundException
|
||||
*/
|
||||
public function expressList(): Json
|
||||
{
|
||||
$list = OrderRepository::getInstance()->allExpress();
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\repository\GoodsRepository;
|
||||
use app\validate\Goods as GoodsValidate;
|
||||
use Exception;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 测试用
|
||||
*
|
||||
* Class DepartmentGoodsListLog
|
||||
* @package app\controller\api
|
||||
*/
|
||||
class DepartmentGoodsListLog extends Base
|
||||
{
|
||||
/**
|
||||
* @return Json
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$validate = new GoodsValidate();
|
||||
if (!$validate->scene('base')->check($params)) {
|
||||
return $this->json(4001, $validate->getError());
|
||||
}
|
||||
|
||||
$data = GoodsRepository::getInstance()->list();
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$validate = new GoodsValidate();
|
||||
if (!$validate->scene('base')->check($params)) {
|
||||
return $this->json(4001, $validate->getError());
|
||||
}
|
||||
|
||||
$data = GoodsRepository::getInstance()->categoryList();
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
|
||||
public function testApiClassMethod()
|
||||
{
|
||||
$header = $this->request->header();
|
||||
$all = $this->request->param();
|
||||
$get = input('get.');
|
||||
$post = input('post.');
|
||||
return $this->json(0, 'success', ['cost'=>$cost ?? 0]);
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\job\NotifySms;
|
||||
use app\model\AccountFootmarks;
|
||||
use app\model\HotKeyword;
|
||||
use app\repository\AccountRepository;
|
||||
use app\service\ExtraConfig;
|
||||
use think\Collection;
|
||||
use think\facade\Queue;
|
||||
use think\response\Json;
|
||||
|
||||
class Index extends Base
|
||||
{
|
||||
protected $noNeedLogin = [
|
||||
'miniProgramSetting',
|
||||
'clearFootmarks',
|
||||
'hotKeywords'
|
||||
];
|
||||
|
||||
public function index(): Json
|
||||
{
|
||||
return json(['code' => 0, 'msg' => 'I am index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用
|
||||
*
|
||||
* @return Json
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public function test(): Json
|
||||
{
|
||||
$userId = $this->request->middleware('userInfo')['user_id'] ?? 0;
|
||||
$user = AccountRepository::getInstance()->info($userId, []);
|
||||
|
||||
return json(['code' => 0, 'msg' => 'I am test ', 'data' => $user]);
|
||||
}
|
||||
|
||||
public function login(): Json
|
||||
{
|
||||
$userId = $this->request->middleware('userInfo')['user_id'] ?? 0;
|
||||
return json(['code' => 0, 'msg' => 'I am login '.$userId]);
|
||||
}
|
||||
|
||||
public function notify()
|
||||
{
|
||||
$beginNotifyList = AccountRepository::getInstance()->getBeginNotifyList();
|
||||
// $res = Queue::later(3, NotifySms::class, $beginNotifyList);
|
||||
// $getSuccessList = AccountRepository::getInstance()->getSuccessList();
|
||||
return $this->json(0, 'success', $beginNotifyList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序个性装修配置
|
||||
*/
|
||||
public function miniProgramSetting(): Json
|
||||
{
|
||||
$conf = ExtraConfig::miniProgram();
|
||||
return $this->json(0, 'success', $conf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推荐显示的热搜词
|
||||
*/
|
||||
public function hotKeywords(): Json
|
||||
{
|
||||
try {
|
||||
$type = input('type/s',"");
|
||||
$list = HotKeyword::allRecommends($type);
|
||||
} catch (\Exception $e) {
|
||||
$list = new Collection();
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理过期足迹
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function clearFootmarks(): Json
|
||||
{
|
||||
try {
|
||||
//清理N天以前的数据
|
||||
$day = 30;
|
||||
$time = date('Y-m-d H:i:s', time() - $day * 86400);
|
||||
$count = AccountFootmarks::where('created_at', '<', $time)->count();
|
||||
AccountFootmarks::where('created_at', '<', $time)->delete();
|
||||
return $this->json(0, '成功清理足迹(条):'.$count);
|
||||
} catch (\Exception $e) {
|
||||
return $this->json(5000, '清理足迹失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
|
||||
use app\model\Account;
|
||||
use app\model\AccountLevel;
|
||||
use app\repository\AccountRepository;
|
||||
use think\response\Json;
|
||||
|
||||
class Level extends Base
|
||||
{
|
||||
protected $noNeedLogin = [
|
||||
|
||||
];
|
||||
|
||||
public function index(): Json
|
||||
{
|
||||
$userId = $this->request->user['user_id'] ?? 0;
|
||||
$user = Account::findById($userId);
|
||||
if (empty($user)) {
|
||||
return json(['code' => 6001, 'msg' => '未登录']);
|
||||
}
|
||||
$level = AccountRepository::getInstance()->getUserLevel($user["coin_total"]);
|
||||
$nextLevel = AccountRepository::getInstance()->getUserNextLevel($level["value"]);
|
||||
|
||||
if (!empty($nextLevel)) {
|
||||
$nextLevel["disparity"] = ( $nextLevel["value"] - $user['coin_total']);
|
||||
}
|
||||
return $this->json(0, "ok", [
|
||||
"level" => $level,
|
||||
"nextLevel" => $nextLevel,
|
||||
"nickname" => $user['nickname'],
|
||||
"headimgurl" => $user['headimgurl'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,406 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\repository\OrderRepository;
|
||||
use app\validate\OrderValidate;
|
||||
use app\model\Order as OrderModel;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*
|
||||
* Class Order
|
||||
* @package app\controller\api
|
||||
*/
|
||||
class Order extends Base
|
||||
{
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @return Json
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function create(): Json
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->param();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$data = OrderRepository::getInstance()->createOrder($accountId, $params);
|
||||
OrderRepository::getInstance()->updateSpuStock([]);
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('订单创建失败', $e, 'error', 'order');
|
||||
return $this->json(5000, '订单创建失败');
|
||||
}
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function shoppingCart(): Json
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$type = $params['type'] ?? '';
|
||||
$page = $params['page'] ?? 1;
|
||||
$size = $params['size'] ?? 20;
|
||||
|
||||
$data = OrderRepository::getInstance()->shoppingCart($accountId, $type, $page, $size);
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加购物车
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function shoppingCartAdd(): Json
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->param();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$rules = [
|
||||
'sku_id|商品' => 'require|number',
|
||||
'num|数量' => 'require|number',
|
||||
];
|
||||
|
||||
$validate = $this->validateByApi($params, $rules);
|
||||
if ($validate !== true) {
|
||||
return $validate;
|
||||
}
|
||||
|
||||
try {
|
||||
OrderRepository::getInstance()->shoppingCartAdd($accountId, $params['sku_id'], $params['num'] ?? 1);
|
||||
return $this->json();
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('购物车添加失败', $e);
|
||||
return $this->json(5000, '购物车添加失败');
|
||||
}
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车商品数量变更
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function shoppingCartChangeNum(): Json
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->param();
|
||||
$rules = [
|
||||
'id|ID' => 'require|number',
|
||||
'num|数量' => 'require|number',
|
||||
];
|
||||
|
||||
$validate = $this->validateByApi($params, $rules);
|
||||
if ($validate !== true) {
|
||||
return $validate;
|
||||
}
|
||||
try {
|
||||
OrderRepository::getInstance()->shoppingCartChangeNum($params['id'], $params['num']);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('购物车数量加减失败', $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车商品删除
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function shoppingCartDel(): Json
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$id = input('post.id/d', 0);
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
if (!$id) {
|
||||
return $this->json(4001, '参数错误');
|
||||
}
|
||||
|
||||
try {
|
||||
OrderRepository::getInstance()->shoppingCartDel($accountId, $id);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('购物车数量加减失败', $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单准备信息
|
||||
* 结算页面 获取商品数据及汇总金额
|
||||
* @return Json
|
||||
*/
|
||||
public function prepareInfo(): Json
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->param();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$data = OrderRepository::getInstance()->prepareInfo($accountId, $params);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('获取订单前置信息失败', $e, 'error', 'order');
|
||||
return $this->json(5000, '订单信息获取失败');
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功通知
|
||||
* 结算页面 获取商品数据及汇总金额
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function paid(): Json
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->param();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$rules = [
|
||||
'order_coding|订单编号' => 'require',
|
||||
];
|
||||
|
||||
$validate = $this->validateByApi($params, $rules);
|
||||
if ($validate !== true) {
|
||||
return $validate;
|
||||
}
|
||||
|
||||
try {
|
||||
if (OrderRepository::getInstance()->setPaid($params['order_coding'])) {
|
||||
return $this->json();
|
||||
}
|
||||
return $this->json(4003, '支付失败');
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('支付成功通知操作失败', $e);
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单验收 - 确认收货
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function accepted(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$orderId = $this->request->param('order_id', 0);
|
||||
|
||||
try {
|
||||
OrderRepository::getInstance()->orderAccepted($orderId, $accountId);
|
||||
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function ship(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
$orderId = $this->request->param('order_id', 0);
|
||||
$expressId = $this->request->param('express_id', 0);
|
||||
$expressNumber = $this->request->param('express_number', 0);
|
||||
|
||||
try {
|
||||
OrderRepository::getInstance()->orderShipping($orderId, $expressId, $expressNumber);
|
||||
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单物流
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function logistics(): Json
|
||||
{
|
||||
$orderCoding = input('order_coding');
|
||||
|
||||
try {
|
||||
$res = OrderRepository::getInstance()->logistics($orderCoding);
|
||||
return $this->json(0, 'success', $res);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('物流查询失败', $e);
|
||||
return $this->json(5000, '获取物流信息失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
*
|
||||
* @return Json
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function cancel(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
$orderCoding = $this->request->param('order_coding', 0);
|
||||
$reason = $this->request->param('remarks', '');
|
||||
|
||||
try {
|
||||
OrderRepository::getInstance()->setClosed($orderCoding, OrderModel::STATUS_CLOSED, $reason);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单付款
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function pay(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4002, '请求错误');
|
||||
}
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$orderCoding = $this->request->param('order_coding', 0);
|
||||
|
||||
try {
|
||||
$res = OrderRepository::getInstance()->pay($orderCoding, $accountId);
|
||||
return $this->json(0, 'success', $res);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车数量
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function shoppingCartCount(): Json
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$type = $this->request->param('type/s', 'spu');
|
||||
|
||||
try {
|
||||
$count = OrderRepository::getInstance()->shoppingCartCount($accountId, $type);
|
||||
return $this->json(0, 'success', ['count' => $count]);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品sku核验
|
||||
*
|
||||
*/
|
||||
public function check(): Json
|
||||
{
|
||||
$orderCoding = input('order_coding/s', '');
|
||||
$id = input('id/d', 0);
|
||||
$checkBy = input('check_user/d', 0);
|
||||
$num = input('num/d', 1);
|
||||
|
||||
try {
|
||||
OrderRepository::getInstance()->check($orderCoding, $id, $num, $checkBy);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('订单商品核验失败', $e);
|
||||
return $this->json(5000, '订单商品核验失败');
|
||||
}
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品sku核验结果
|
||||
*
|
||||
*/
|
||||
public function checkResult(): Json
|
||||
{
|
||||
$orderCoding = input('order_coding/s', '');
|
||||
$id = input('id/d', 0);
|
||||
$notCheckNum = input('not_check_num/d', 0);
|
||||
|
||||
try {
|
||||
$res = OrderRepository::getInstance()->checkResult($orderCoding, $id, $notCheckNum);
|
||||
return $this->json(0, 'success', ['result' => (int) $res]);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('订单商品核验结果获取失败', $e);
|
||||
return $this->json(5000, '订单商品核验结果获取失败');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\repository\BusinessRepository;
|
||||
use app\repository\RechargeRepository;
|
||||
use app\service\wx\WechatPay;
|
||||
use app\model\Recharge as RechargeModel;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 充值
|
||||
*
|
||||
* Class Recharge
|
||||
* @package app\controller\api
|
||||
*/
|
||||
class Recharge extends Base
|
||||
{
|
||||
protected $noNeedLogin = ['query'];
|
||||
|
||||
/**
|
||||
* 查询是否支付成功
|
||||
* */
|
||||
public function query()
|
||||
{
|
||||
$orderNum = input("order_num/s");
|
||||
if (empty($orderNum)) {
|
||||
return $this->json("4001", "参数错误");
|
||||
}
|
||||
$recharge = RechargeRepository::getInstance()->getModel()->where(["order_num" => $orderNum])->lock(true)->find();
|
||||
if (empty($recharge)) {
|
||||
return $this->json("4001", "订单不存在");
|
||||
}
|
||||
if ($recharge['state'] == RechargeModel::state_on) {
|
||||
return $this->json();
|
||||
}
|
||||
$business = BusinessRepository::getInstance()->getModel()->where(["code" => $recharge['business_code']])->lock(true)->find();
|
||||
if (empty($business)) {
|
||||
return $this->json("4001", "商家不存在");
|
||||
}
|
||||
//查询 交易成功判断条件: return_code、result_code和trade_state都为SUCCESS
|
||||
$res = WechatPay::getInstance()->order->queryByOutTradeNumber($orderNum);
|
||||
if ($res['return_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
|
||||
if (isset($res['result_code']) && $res['result_code'] == 'SUCCESS') {
|
||||
if (isset($res['trade_state']) && $res['trade_state'] == 'SUCCESS') {
|
||||
Db::startTrans();
|
||||
try {
|
||||
//这里确定支付成功
|
||||
$total_fee = $res['total_fee'] / 100;
|
||||
//加余额
|
||||
$business->save(["balance" => ($business["balance"] + $total_fee)]);
|
||||
//修改支付状态
|
||||
$recharge->save([
|
||||
"money" => $total_fee,
|
||||
"state" => RechargeModel::state_on,
|
||||
"update_time" => date("Y-m-d H:i:s"),
|
||||
"balance" => $business->balance
|
||||
]);
|
||||
Db::commit();
|
||||
return $this->json();
|
||||
} catch (RepositoryException $e) {
|
||||
Db::rollback();
|
||||
return $this->json("5001", $e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->json("5001", "充值失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->json("4001", "未支付成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信的回调
|
||||
*
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\Exception
|
||||
*/
|
||||
public function notify(){
|
||||
if ($this->request->isPost()) {
|
||||
$app = WechatPay::getInstance();
|
||||
$response = $app->handlePaidNotify(function ($message, $fail) {
|
||||
// $aa = '{"appid":"wxa02e44170bc722cd","bank_type":"OTHERS","cash_fee":"1","fee_type":"CNY","is_subscribe":"N","mch_id":"1605090111","nonce_str":"60f7d8a1e4ac8","openid":"oKrEm0ehgsy2ZTWzEva4tbLuUgFw","out_trade_no":"16268555858753004863","result_code":"SUCCESS","return_code":"SUCCESS","sign":"DB3F6CDCB7FBB3B9DDF7C0CC8BBD5AAD","time_end":"20210721162000","total_fee":"1","trade_type":"JSAPI","transaction_id":"4200001200202107217942681078"}';
|
||||
// $message = json_decode($aa, true);
|
||||
$m = json_encode($message, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$recharge = RechargeRepository::getInstance()->getModel()->where(["order_num" => $message['out_trade_no']])->lock(true)->find();
|
||||
if (empty($recharge)) {
|
||||
$this->log(sprintf("[微信支付回调][%s][%s]订单支付成功,但系统查无此订单 info:%s", date('Y-m-d H:i:s'), $message['out_trade_no'], $m), 'error');
|
||||
return true;//订单不存在
|
||||
}
|
||||
if ($recharge['state'] == RechargeModel::state_on) {
|
||||
return true;//订单已经支付
|
||||
}
|
||||
$business = BusinessRepository::getInstance()->getModel()->where(["code" => $recharge['business_code']])->lock(true)->find();
|
||||
if (empty($business)) {
|
||||
$this->log(sprintf("[微信支付回调][%s][%s]订单支付成功,但商家不存在 info:%s", date('Y-m-d H:i:s'), $message['out_trade_no'], $m), 'error');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if ($message['return_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
|
||||
if (isset($message['result_code']) && $message['result_code'] == 'SUCCESS') {
|
||||
if (isset($message['trade_state']) && $message['trade_state'] == 'SUCCESS') {
|
||||
Db::startTrans();
|
||||
try {
|
||||
//这里确定支付成功
|
||||
$total_fee = $message['total_fee'] / 100;
|
||||
//加余额
|
||||
$business->save(["balance" => ($business["balance"] + $total_fee)]);
|
||||
//修改支付状态
|
||||
$recharge->save([
|
||||
"money" => $total_fee,
|
||||
"state" => RechargeModel::state_on,
|
||||
"update_time" => date("Y-m-d H:i:s"),
|
||||
"balance" => $business->balance
|
||||
]);
|
||||
Db::commit();
|
||||
//记录日志
|
||||
$this->log(sprintf("[微信支付回调][%s][%s]订单支付成功 info:%s", date('Y-m-d H:i:s'), $message['out_trade_no'], $m), 'info');
|
||||
return true;
|
||||
} catch (RepositoryException $e) {
|
||||
Db::rollback();
|
||||
$this->log(sprintf("[微信支付回调][%s][%s]订单支付成功-修改订单状态失败-RepositoryException info:%s", date('Y-m-d H:i:s'), $message['out_trade_no'], $m), 'info');
|
||||
return $fail('Order status edit failed.');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->log(sprintf("[微信支付回调][%s][%s]订单支付成功-修改订单状态失败-Exception info:%s", date('Y-m-d H:i:s'), $message['out_trade_no'], $m), 'info');
|
||||
return $fail('Order status edit failed.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fail('通信失败,请稍后再通知我');
|
||||
});
|
||||
|
||||
$response->send();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 记录订单日志
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $type
|
||||
*/
|
||||
private function log(string $message, string $type = 'info'): void
|
||||
{
|
||||
Log::channel('order')->write($message, $type);
|
||||
}
|
||||
}
|
|
@ -1,181 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\model\Account;
|
||||
use app\model\AccountSignOnline;
|
||||
use app\repository\AccountRepository;
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
|
||||
class Sign extends Base
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
|
||||
|
||||
/**
|
||||
* 签到页面加载
|
||||
* */
|
||||
public function miniLoad()
|
||||
{
|
||||
Config::load('extra/base', 'base');
|
||||
$baseConfig = config('base');
|
||||
$score = isset($baseConfig['sign_score']) ? abs($baseConfig['sign_score']) : 1;
|
||||
|
||||
$userId = $this->request->user['user_id'] ?? 0;
|
||||
if ($userId == 0) {
|
||||
return $this->json(6001, "请先登录");
|
||||
}
|
||||
|
||||
$account = Account::findOne(["id" => $userId], []);
|
||||
if (empty($account)) {
|
||||
return $this->json(6001, "请先登录");
|
||||
}
|
||||
|
||||
//更新连续签到次数
|
||||
AccountRepository::getInstance()->checkContinuitySign($account);
|
||||
|
||||
$weekDate = getLatelyWeekDate();
|
||||
|
||||
$weedSignInOnlineRecord = AccountRepository::getInstance()->weedSignInOnlineRecord($userId, $weekDate["1"]["date"], strtotime($weekDate["7"]["date"]) + 86399);
|
||||
|
||||
foreach ($weedSignInOnlineRecord as $item) {
|
||||
$w = date("w", strtotime($item['created_at']));
|
||||
if ($w == 0) {
|
||||
$weekDate["1"]["record"] = $item["score"];
|
||||
} else {
|
||||
$weekDate[$w]["record"] = $item["score"];
|
||||
}
|
||||
$weekDate[$w]['is_sign'] = AccountSignOnline::COMMON_ON;//当天是否签到
|
||||
}
|
||||
$todaySignIn = AccountSignOnline::COMMON_OFF;
|
||||
foreach ($weekDate as &$item) {
|
||||
|
||||
$key = date("m.d", strtotime($item['date']));
|
||||
if (!isset($item['record'])) {
|
||||
$item['record'] = $score;
|
||||
$item['is_sign'] = AccountSignOnline::COMMON_OFF;//当天是否签到
|
||||
}
|
||||
|
||||
if ($key == date("m.d")) {
|
||||
$key = "今天";
|
||||
|
||||
if ($item['is_sign'] == AccountSignOnline::COMMON_ON) {
|
||||
$todaySignIn = AccountSignOnline::COMMON_ON;
|
||||
}
|
||||
} elseif ($key == (date("m.d", strtotime("+1 day")))) {
|
||||
$key = "明天";
|
||||
}
|
||||
$item["key"] = $key;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $this->json(0, "操作成功", [
|
||||
"sign_record" => $weekDate,
|
||||
"reward_score" => $score,
|
||||
"user_score" => $account['score'],
|
||||
"today_sign_in" => $todaySignIn,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到记录
|
||||
* */
|
||||
|
||||
public function onlineSignRecord()
|
||||
{
|
||||
$userId = $this->request->user['user_id'] ?? 0;
|
||||
if ($userId == 0) {
|
||||
return $this->json(6001, "请先登录");
|
||||
}
|
||||
|
||||
$page = input("page/d", 1);
|
||||
$size = input("size/d", 10);
|
||||
|
||||
$record = AccountRepository::getInstance()->onlineSignRecordList($userId, $page, $size);
|
||||
if ($record->isEmpty()) {
|
||||
return $this->json(4001, "没有更多");
|
||||
}
|
||||
return $this->json(0, "ok", $record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 线上签到
|
||||
* */
|
||||
public function onlineSingIn(): Json
|
||||
{
|
||||
//检查是否已经签到
|
||||
$userId = $this->request->user['user_id'] ?? 0;
|
||||
if ($userId == 0) {
|
||||
return $this->json(6001, "请先登录");
|
||||
}
|
||||
|
||||
$check = AccountRepository::getInstance()->checkSignInOnline($userId);
|
||||
if ($check) {
|
||||
return $this->json(4003, "今天已经签到了,请明天再来");
|
||||
}
|
||||
$account = Account::findOne(["id" => $userId], [], function ($q) {
|
||||
return $q->lock(true);
|
||||
});
|
||||
if (empty($account)) {
|
||||
return $this->json(6001, "请先登录");
|
||||
}
|
||||
|
||||
//更新连续签到次数
|
||||
AccountRepository::getInstance()->checkContinuitySign($account);
|
||||
|
||||
Config::load('extra/base', 'base');
|
||||
$baseConfig = config('base');
|
||||
$score = isset($baseConfig['sign_score']) ? abs($baseConfig['sign_score']) : 1;
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
AccountRepository::getInstance()->SignInOnline($account, $score);
|
||||
Db::commit();
|
||||
return $this->json();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->json(4003, "签到失败");
|
||||
} catch (RepositoryException $e) {
|
||||
Db::rollback();
|
||||
$this->json(4003, "签到失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 线下签到
|
||||
* */
|
||||
public function SingIn(): Json
|
||||
{
|
||||
//检查是否已经签到
|
||||
$userId = $this->request->user['user_id'] ?? 0;
|
||||
if ($userId == 0) {
|
||||
return $this->json(6001, "请先登录");
|
||||
}
|
||||
|
||||
$check = AccountRepository::getInstance()->checkSignIn($userId);
|
||||
if ($check) {
|
||||
return $this->json(4003, "今天已经签到了,请明天再来");
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
AccountRepository::getInstance()->SignIn($userId);
|
||||
Db::commit();
|
||||
return $this->json();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->json(4003, "签到失败");
|
||||
} catch (RepositoryException $e) {
|
||||
Db::rollback();
|
||||
$this->json(4003, "签到失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,335 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\controller\api\Base;
|
||||
use app\exception\RepositoryException;
|
||||
use app\model\AccountLevel;
|
||||
use app\model\AccountRecord;
|
||||
use app\model\AccountRole;
|
||||
use app\model\Spu as SpuModel;
|
||||
use app\model\Disease;
|
||||
use app\model\SpuActivity;
|
||||
use app\model\Staff;
|
||||
use app\repository\OrderRepository;
|
||||
use app\repository\SpuRepository;
|
||||
use Exception;
|
||||
use think\Collection;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Log;
|
||||
use think\response\Json;
|
||||
|
||||
class Spu extends Base
|
||||
{
|
||||
protected $exceptExtra = ['list', 'category', 'detail'];
|
||||
|
||||
/**
|
||||
* 商品列表筛选条件
|
||||
*
|
||||
* @throws ModelNotFoundException
|
||||
* @throws DbException
|
||||
* @throws DataNotFoundException
|
||||
*/
|
||||
public function condition(): Json
|
||||
{
|
||||
$list = [
|
||||
'disease' => Disease::getListByPid(0, ['pid', 'name', 'id', 'sort']),
|
||||
'doctor_roles' => AccountRole::findAccountRolesByGroupName(AccountRole::ROLE_GROUP_DOCTOR),
|
||||
'activity' => SpuModel::activity(),
|
||||
];
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已发布的商品列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws RepositoryException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$repo = SpuRepository::getInstance();
|
||||
|
||||
$fields = SpuModel::spuListFields();
|
||||
|
||||
$params = input();
|
||||
$params['fields'] = $fields;
|
||||
$params['is_score'] = SpuModel::COMMON_OFF;//排除积分商品
|
||||
|
||||
$list = $repo->listForFront($params, function ($q) {
|
||||
return $q->with([
|
||||
'activity_info' => function ($query) {
|
||||
$query->withoutField('content');
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已发布的积分商品列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws RepositoryException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function score(): Json
|
||||
{
|
||||
$repo = SpuRepository::getInstance();
|
||||
|
||||
$type = input('type/s', SpuModel::TYPE_NORMAL);//normal=综合 newest=最新
|
||||
$sortField = input('sort_field/s', '');// score=积分 num=兑换量
|
||||
$sortValue = input('sort_value/s', '');//desc=降序 asc=升序
|
||||
|
||||
$rules = [
|
||||
'page|页数' => 'integer|gt:0',
|
||||
'size|每页数量' => 'integer|gt:0',
|
||||
'type|类型' => 'in:newest,'.SpuModel::TYPE_NORMAL,
|
||||
'sort_field|排序字段' => 'in:score,amount',
|
||||
'sort_value|排序值' => 'in:asc,desc',
|
||||
];
|
||||
|
||||
$message = [
|
||||
'type.in' => '类型错误',
|
||||
'$sortField.in' => '排序字段错误',
|
||||
'sort_value.in' => '排序值错误',
|
||||
];
|
||||
|
||||
$params = input();
|
||||
|
||||
$validate = $this->validateByApi($params, $rules, $message);
|
||||
if ($validate !== true) {
|
||||
return $validate;
|
||||
}
|
||||
|
||||
$order = [];//排序
|
||||
|
||||
// 综合排序
|
||||
if ($type === SpuModel::TYPE_NORMAL) {
|
||||
$order = [
|
||||
'sort' => 'desc',
|
||||
'id' => 'desc',
|
||||
];
|
||||
}
|
||||
|
||||
// 最新排序
|
||||
if ($type === 'newest') {
|
||||
$order = ['published_at' => 'desc'];
|
||||
}
|
||||
|
||||
// 兑换量排序
|
||||
if (!empty($sortField)) {
|
||||
if (empty($sortValue)) {
|
||||
return $this->json(4003, '排序参数错误');
|
||||
}
|
||||
$order = [
|
||||
$sortField => $sortValue
|
||||
];
|
||||
}
|
||||
|
||||
$params['is_score'] = SpuModel::COMMON_ON;
|
||||
$params['fields'] = SpuModel::scoreListFields();
|
||||
|
||||
$list = $repo->listForFront($params, function ($q) {
|
||||
return $q->with([
|
||||
'activity_info' => function ($query) {
|
||||
$query->withoutField('content');
|
||||
}
|
||||
]);
|
||||
}, $order);
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function collection(): Json
|
||||
{
|
||||
$rules = [
|
||||
'page|页数' => 'integer',
|
||||
'size|每页数量' => 'integer',
|
||||
];
|
||||
|
||||
$params = input();
|
||||
$page = $params['page'] ?? 1;
|
||||
$size = $params['size'] ?? 10;
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
|
||||
$params['page'] = 1;
|
||||
$params['size'] = 0;
|
||||
|
||||
$validate = $this->validateByApi($params, $rules);
|
||||
if ($validate !== true) {
|
||||
return $validate;
|
||||
}
|
||||
|
||||
//获取收藏相关
|
||||
$collection = AccountRecord::where('type', AccountRecord::TYPE_SPU)
|
||||
->where('action', AccountRecord::ACTION_COLLECT)
|
||||
->where('account_id', $accountId)
|
||||
->where('is_record', AccountRecord::COMMON_ON)
|
||||
->order('recorded_at', 'desc');
|
||||
|
||||
$total = $collection->count();
|
||||
if ($total <= 0) {
|
||||
return $this->json(0, 'success', [
|
||||
'total' => 0,
|
||||
'current' => $page,
|
||||
'size' => $size,
|
||||
'list' => new Collection(),
|
||||
]);
|
||||
}
|
||||
|
||||
$recordList = $collection->page($page)->limit($size)->field('relation_id,recorded_at')->select();
|
||||
|
||||
$where = [];
|
||||
$where[] = ['id', 'in', $recordList->column('relation_id')];
|
||||
|
||||
$list = SpuRepository::getInstance()->listForFront($params, function ($q) {
|
||||
return $q->with([
|
||||
'activity_info' => function ($query) {
|
||||
$query->withoutField('content');
|
||||
}
|
||||
]);
|
||||
}, [], $where);
|
||||
|
||||
$data = [];
|
||||
$spuList = $list['list']->toArray();
|
||||
foreach ($recordList as $record) {
|
||||
foreach ($spuList as $key => $spu) {
|
||||
if ($record['relation_id'] == $spu['id']) {
|
||||
$data[] = $spu;
|
||||
unset($spuList[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$list['total'] = $total;
|
||||
$list['current'] = $page;
|
||||
$list['size'] = $size;
|
||||
$list['list'] = $data;
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SPU 详情
|
||||
*/
|
||||
public function detail(): Json
|
||||
{
|
||||
$repo = SpuRepository::getInstance();
|
||||
$id = input('id/d', 0);
|
||||
$shareId = input('share_id/d', 0);//分享人ID
|
||||
$isActivity = input('is_activity/d', 0);//分享人ID
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$data = $repo->detail($id, $accountId, $shareId, (bool) $isActivity);
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$repo->log($e->getMessage(), $e);
|
||||
return $this->json(5000, '获取详情失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定活动商品的拼团列表 仅限拼团活动商品
|
||||
*/
|
||||
public function groupList(): Json
|
||||
{
|
||||
$id = input('id/d', 0);
|
||||
|
||||
try {
|
||||
$data = OrderRepository::getInstance()->getGroupList($id);
|
||||
return $this->json(0, 'success', $data);
|
||||
} catch (RepositoryException $e) {
|
||||
return $this->json(4001, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
SpuRepository::log($e->getMessage(), $e);
|
||||
return $this->json(5000, '获取拼团列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏
|
||||
*/
|
||||
public function record(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4000, '无效请求');
|
||||
}
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$id = $this->request->param('id/d', 0);
|
||||
$action = $this->request->param('action/s', '');
|
||||
|
||||
try {
|
||||
if ($accountId <= 0 || $id <= 0) {
|
||||
return $this->json(4001, '无效请求');
|
||||
}
|
||||
|
||||
if (!in_array($action, AccountRecord::allowActions())) {
|
||||
return $this->json(4001, '操作类型参数错误');
|
||||
}
|
||||
|
||||
if (!SpuModel::findById($id)) {
|
||||
return $this->json(4001, '商品不存在');
|
||||
}
|
||||
|
||||
AccountRecord::record($accountId, AccountRecord::TYPE_SPU, $action, $id);
|
||||
} catch (Exception $e) {
|
||||
Log::error('[商品记录失败]'.$e->getMessage());
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消 收藏
|
||||
*/
|
||||
public function unRecord(): Json
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->json(4000, '无效请求');
|
||||
}
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$id = $this->request->param('id/d', 0);
|
||||
$action = $this->request->param('action/s', '');
|
||||
|
||||
try {
|
||||
if ($accountId <= 0 || $id <= 0) {
|
||||
return $this->json(4001, '无效请求');
|
||||
}
|
||||
|
||||
if (!in_array($action, AccountRecord::allowActions())) {
|
||||
return $this->json(4001, '操作类型参数错误');
|
||||
}
|
||||
|
||||
if (!SpuModel::findById($id)) {
|
||||
return $this->json(4001, '商品不存在');
|
||||
}
|
||||
|
||||
AccountRecord::unRecord($accountId, $id, AccountRecord::TYPE_SPU, $action);
|
||||
} catch (Exception $e) {
|
||||
Log::error('[取消商品记录失败]'.$e->getMessage());
|
||||
return $this->json(5000, '操作失败');
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\model\AccountFootmarks;
|
||||
use app\model\Event;
|
||||
use Exception;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\response\Json;
|
||||
|
||||
class Statistics extends Base
|
||||
{
|
||||
protected $noNeedLogin = ['event'];
|
||||
/**
|
||||
* 事件列表
|
||||
*
|
||||
* @return Json
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function event(): Json
|
||||
{
|
||||
$data = Event::field('id, name')->select()->toArray();
|
||||
|
||||
return $this->json(0, 'success', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报
|
||||
*
|
||||
* @return Json
|
||||
* @throws Exception
|
||||
*/
|
||||
public function report(): Json
|
||||
{
|
||||
$data = input();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
if (count($data) > 1000) {
|
||||
//TODO 太大就分片处理
|
||||
|
||||
} else {
|
||||
foreach ($data as $d) {
|
||||
if (!isset($d['e']) || !isset($d['t'])) {
|
||||
return $this->json(4001, '参数错误');
|
||||
}
|
||||
$arr = [];
|
||||
$arr['event_id'] = (int) ($d['e'] ?? 0);
|
||||
$arr['account_id'] = $accountId;
|
||||
$arr['content_id'] = (int) ($d['c'] ?? 0);
|
||||
$t = (strlen($d['t']) == 13) ? $d['t'] / 1000 : $d['t'];
|
||||
$arr['created_at'] = date('Y-m-d H:i:s', $t);
|
||||
|
||||
$insert[] = $arr;
|
||||
}
|
||||
}
|
||||
|
||||
// 若量大 时间长 可丢入队列操作
|
||||
if (count($insert) > 0) {
|
||||
(new AccountFootmarks())->saveAll($insert);
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>恭喜,站点创建成功!</title>
|
||||
<style>
|
||||
|
||||
.container {
|
||||
width: 60%;
|
||||
margin: 10% auto 0;
|
||||
background-color: #f0f0f0;
|
||||
padding: 2% 5%;
|
||||
border-radius: 10px
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
ul li {
|
||||
line-height: 2.3
|
||||
}
|
||||
|
||||
a {
|
||||
color: #20a53a
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>恭喜, 站点创建成功!</h1>
|
||||
<h3>这是默认index.html,本页面由系统自动生成</h3>
|
||||
<ul>
|
||||
<li>本页面在FTP根目录下的index.html</li>
|
||||
<li>您可以修改、删除或覆盖本页面</li>
|
||||
<li>FTP相关信息,请到“面板系统后台 > FTP” 查看</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,9 +1 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
Options +FollowSymlinks -Multiviews
|
||||
RewriteEngine On
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_URI} !^(.*)\.(gif|jpg|jpeg|png|swf|mp4)$ [NC]
|
||||
RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
|
||||
</IfModule>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<title>404</title>
|
||||
<style>
|
||||
body{
|
||||
background-color:#444;
|
||||
font-size:14px;
|
||||
}
|
||||
h3{
|
||||
font-size:60px;
|
||||
color:#eee;
|
||||
text-align:center;
|
||||
padding-top:30px;
|
||||
font-weight:normal;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>404锛屾偍璇锋眰鐨勬枃浠朵笉瀛樺湪!</h3>
|
||||
</body>
|
||||
</html>
|
|
@ -120,7 +120,7 @@
|
|||
<div class="layui-form-item layui-form-item-lg">
|
||||
<label class="layui-form-label">商家发布优惠券</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" {if $item.directory == 1} checked="" {/if} lay-skin="switch" lay-filter="switchDirectory" lay-text="开启|关闭">
|
||||
<input type="checkbox" {if isset($item.directory) && $item.directory == 1} checked="" {/if} lay-skin="switch" lay-filter="switchDirectory" lay-text="开启|关闭">
|
||||
<input type="hidden" id="directory" name="directory" value="{$item.directory ?? 0}">
|
||||
</div>
|
||||
</div>
|
||||
|
@ -142,7 +142,7 @@
|
|||
<div class="layui-form-item layui-form-item-lg">
|
||||
<label class="layui-form-label">评论人工审核可见</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" {if $item.commentState == 1} checked="" {/if} lay-skin="switch" lay-filter="switchCommentState" lay-text="开启|关闭">
|
||||
<input type="checkbox" {if isset($item.commentState) && $item.commentState == 1} checked="" {/if} lay-skin="switch" lay-filter="switchCommentState" lay-text="开启|关闭">
|
||||
<input type="hidden" id="commentState" name="commentState" value="{$item.commentState ?? 0}">
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue