mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
代码调整优化
This commit is contained in:
parent
e90ceaac25
commit
4d73c3580f
@ -61,7 +61,7 @@ class News extends Controller
|
|||||||
$map = $this->_vali(['code.require' => '文章不能为空!']);
|
$map = $this->_vali(['code.require' => '文章不能为空!']);
|
||||||
$query = $this->_query('DataNewsXComment')->where($map);
|
$query = $this->_query('DataNewsXComment')->where($map);
|
||||||
$result = $query->order('id desc')->page(false, false, false, 5);
|
$result = $query->order('id desc')->page(false, false, false, 5);
|
||||||
NewsService::instance()->buildListByMinAndCode($result['list']);
|
NewsService::instance()->buildListByUidAndCode($result['list']);
|
||||||
$this->success('获取文章评论成功!', $result);
|
$this->success('获取文章评论成功!', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,10 @@ class Notify extends Controller
|
|||||||
* @param string $scene 支付场景
|
* @param string $scene 支付场景
|
||||||
* @param string $param 支付通道
|
* @param string $param 支付通道
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function alipay(string $scene = 'order', string $param = ''): string
|
public function alipay(string $scene = 'order', string $param = ''): string
|
||||||
{
|
{
|
||||||
|
@ -41,9 +41,7 @@ class News extends Auth
|
|||||||
{
|
{
|
||||||
$map = $this->_vali(['uid.value' => $this->uuid, 'code.require' => '文章不能为空!']);
|
$map = $this->_vali(['uid.value' => $this->uuid, 'code.require' => '文章不能为空!']);
|
||||||
$result = $this->_query('DataNewsXComment')->where($map)->order('id desc')->page(true, false);
|
$result = $this->_query('DataNewsXComment')->where($map)->order('id desc')->page(true, false);
|
||||||
if (count($result['list']) > 0) {
|
NewsService::instance()->buildListByUidAndCode($result);
|
||||||
NewsService::instance()->buildListByMinAndCode($result);
|
|
||||||
}
|
|
||||||
$this->success('获取评论列表成功', $result);
|
$this->success('获取评论列表成功', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,9 +105,7 @@ class News extends Auth
|
|||||||
$map = ['uid' => $this->uuid, 'type' => 1];
|
$map = ['uid' => $this->uuid, 'type' => 1];
|
||||||
$query = $this->_query('DataNewsXCollect')->where($map);
|
$query = $this->_query('DataNewsXCollect')->where($map);
|
||||||
$result = $query->order('id desc')->page(true, false, false, 15);
|
$result = $query->order('id desc')->page(true, false, false, 15);
|
||||||
if (count($result['list']) > 0) {
|
NewsService::instance()->buildListByUidAndCode($result['list']);
|
||||||
NewsService::instance()->buildListByMinAndCode($result['list']);
|
|
||||||
}
|
|
||||||
$this->success('获取收藏记录成功!', $result);
|
$this->success('获取收藏记录成功!', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +150,7 @@ class News extends Auth
|
|||||||
{
|
{
|
||||||
$query = $this->_query('DataNewsXCollect')->order('id desc');
|
$query = $this->_query('DataNewsXCollect')->order('id desc');
|
||||||
$result = $query->where(['uid' => $this->uuid, 'type' => 2])->page(true, false, false, 15);
|
$result = $query->where(['uid' => $this->uuid, 'type' => 2])->page(true, false, false, 15);
|
||||||
NewsService::instance()->buildListByMinAndCode($result['list']);
|
NewsService::instance()->buildListByUidAndCode($result['list']);
|
||||||
$this->success('获取点赞记录成功!', $result);
|
$this->success('获取点赞记录成功!', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +164,7 @@ class News extends Auth
|
|||||||
{
|
{
|
||||||
$query = $this->_query('DataNewsXCollect')->order('id desc');
|
$query = $this->_query('DataNewsXCollect')->order('id desc');
|
||||||
$result = $query->where(['uid' => $this->uuid, 'type' => 3])->page(true, false, false, 15);
|
$result = $query->where(['uid' => $this->uuid, 'type' => 3])->page(true, false, false, 15);
|
||||||
NewsService::instance()->buildListByMinAndCode($result['list']);
|
NewsService::instance()->buildListByUidAndCode($result['list']);
|
||||||
$this->success('获取浏览历史成功!', $result);
|
$this->success('获取浏览历史成功!', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,23 +34,19 @@ class NewsService extends Service
|
|||||||
* @param array $list 数据列表
|
* @param array $list 数据列表
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function buildListByMinAndCode(array &$list = []): array
|
public function buildListByUidAndCode(array &$list = []): array
|
||||||
{
|
{
|
||||||
if (count($list) > 0) {
|
if (count($list) > 0) {
|
||||||
/*! 读取文章内容 */
|
/*! 绑定文章内容 */
|
||||||
$codes = array_unique(array_column($list, 'code'));
|
$codes = array_unique(array_column($list, 'code'));
|
||||||
$colls = 'id,code,name,cover,mark,status,deleted,create_at,num_like,num_read,num_comment,num_collect';
|
$colls = 'id,code,name,cover,mark,status,deleted,create_at,num_like,num_read,num_comment,num_collect';
|
||||||
$items = $this->app->db->name('DataNewsItem')->whereIn('code', $codes)->column($colls, 'code');
|
$items = $this->app->db->name('DataNewsItem')->whereIn('code', $codes)->column($colls, 'code');
|
||||||
$marks = $this->app->db->name('DataNewsMark')->where(['status' => 1])->column('name');
|
$marks = $this->app->db->name('DataNewsMark')->where(['status' => 1])->column('name');
|
||||||
foreach ($items as &$vo) $vo['mark'] = str2arr($vo['mark'] ?: '', ',', $marks);
|
foreach ($items as &$vo) $vo['mark'] = str2arr($vo['mark'] ?: '', ',', $marks);
|
||||||
|
foreach ($list as &$vo) $vo['record'] = $items[$vo['code']] ?? [];
|
||||||
/*! 绑定用户数据 */
|
/*! 绑定用户数据 */
|
||||||
$mids = array_unique(array_column($list, 'uid'));
|
|
||||||
$colls = 'id,phone,nickname,username,headimg,status';
|
$colls = 'id,phone,nickname,username,headimg,status';
|
||||||
$users = $this->app->db->name('DataUser')->whereIn('id', $mids)->column($colls, 'id');
|
UserService::instance()->buildByUid($list, 'uid', 'member', $colls);
|
||||||
foreach ($list as &$vo) {
|
|
||||||
$vo['member'] = $users[$vo['uid']] ?? [];
|
|
||||||
$vo['record'] = $items[$vo['code']] ?? [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
@ -57,13 +57,6 @@ class OrderService extends Service
|
|||||||
*/
|
*/
|
||||||
public function buildItemData(array &$data = []): array
|
public function buildItemData(array &$data = []): array
|
||||||
{
|
{
|
||||||
// 关联用户数据
|
|
||||||
$mids = array_unique(array_merge(array_column($data, 'uid'), array_column($data, 'from')));
|
|
||||||
$members = $this->app->db->name('DataUser')->whereIn('id', $mids)->column('*', 'id');
|
|
||||||
foreach ($members as &$user) {
|
|
||||||
unset($user['token'], $user['tokenv'], $user['openid1'], $user['openid2']);
|
|
||||||
unset($user['unionid'], $user['password'], $user['status'], $user['deleted']);
|
|
||||||
}
|
|
||||||
// 关联发货信息
|
// 关联发货信息
|
||||||
$nobs = array_unique(array_column($data, 'order_no'));
|
$nobs = array_unique(array_column($data, 'order_no'));
|
||||||
$trucks = $this->app->db->name('ShopOrderSend')->whereIn('order_no', $nobs)->column('*', 'order_no');
|
$trucks = $this->app->db->name('ShopOrderSend')->whereIn('order_no', $nobs)->column('*', 'order_no');
|
||||||
@ -71,17 +64,17 @@ class OrderService extends Service
|
|||||||
// 关联订单商品
|
// 关联订单商品
|
||||||
$query = $this->app->db->name('ShopOrderItem')->where(['status' => 1, 'deleted' => 0]);
|
$query = $this->app->db->name('ShopOrderItem')->where(['status' => 1, 'deleted' => 0]);
|
||||||
$items = $query->withoutField('id,uid,status,deleted,create_at')->whereIn('order_no', $nobs)->select()->toArray();
|
$items = $query->withoutField('id,uid,status,deleted,create_at')->whereIn('order_no', $nobs)->select()->toArray();
|
||||||
|
// 关联用户数据
|
||||||
|
$fields = 'username,phone,nickname,headimg,status';
|
||||||
|
UserService::instance()->buildByUid($data, 'uid', 'member', $fields);
|
||||||
|
UserService::instance()->buildByUid($data, 'from', 'fromer', $fields);
|
||||||
foreach ($data as &$vo) {
|
foreach ($data as &$vo) {
|
||||||
$vo['sales'] = 0;
|
$vo['sales'] = 0;
|
||||||
$vo['member'] = $members[$vo['uid']] ?? [];
|
|
||||||
$vo['fromer'] = $members[$vo['from']] ?? [];
|
|
||||||
$vo['truck'] = $trucks[$vo['order_no']] ?? [];
|
$vo['truck'] = $trucks[$vo['order_no']] ?? [];
|
||||||
$vo['items'] = [];
|
$vo['items'] = [];
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) if ($vo['order_no'] === $item['order_no']) {
|
||||||
if ($vo['order_no'] === $item['order_no']) {
|
$vo['sales'] += $item['stock_sales'];
|
||||||
$vo['items'][] = $item;
|
$vo['items'][] = $item;
|
||||||
$vo['sales'] += $item['stock_sales'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\data\service;
|
namespace app\data\service;
|
||||||
|
|
||||||
|
use app\data\service\payment\AliPaymentService;
|
||||||
use app\data\service\payment\JoinPaymentService;
|
use app\data\service\payment\JoinPaymentService;
|
||||||
use app\data\service\payment\WechatPaymentService;
|
use app\data\service\payment\WechatPaymentService;
|
||||||
use think\admin\Service;
|
use think\admin\Service;
|
||||||
@ -98,15 +99,14 @@ abstract class PaymentService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付服务对象
|
* 支付服务对象
|
||||||
* @var JoinPaymentService|WechatPaymentService
|
* @var JoinPaymentService|WechatPaymentService|AliPaymentService
|
||||||
*/
|
*/
|
||||||
protected static $driver = [];
|
protected static $driver = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据配置实例支付服务
|
* 根据配置实例支付服务
|
||||||
* @param string $payid 支付通道编号
|
* @param string $payid 支付通道编号
|
||||||
* @return JoinPaymentService|WechatPaymentService
|
* @return JoinPaymentService|WechatPaymentService|AliPaymentService
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
*/
|
*/
|
||||||
public static function build(string $payid): PaymentService
|
public static function build(string $payid): PaymentService
|
||||||
|
@ -177,6 +177,23 @@ class UserService extends Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表绑定用户数据
|
||||||
|
* @param array $list 原数据列表
|
||||||
|
* @param string $keys 用户UID字段
|
||||||
|
* @param string $bind 绑定字段名称
|
||||||
|
* @param string $column 返回用户字段
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function buildByUid(array &$list, string $keys = 'uid', string $bind = 'user', string $column = '*'): array
|
||||||
|
{
|
||||||
|
if (count($list) < 1) return $list;
|
||||||
|
$uids = array_unique(array_column($list, $keys));
|
||||||
|
$users = $this->app->db->name('DataUser')->whereIn('id', $uids)->column($column, 'id');
|
||||||
|
foreach ($list as &$vo) $vo[$bind] = $users[$keys] ?? [];
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取令牌的认证值
|
* 获取令牌的认证值
|
||||||
* @return string
|
* @return string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user