mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
调整代码
This commit is contained in:
parent
f57bfb06e2
commit
9568df3f2a
@ -13,6 +13,17 @@ use think\admin\Service;
|
||||
class GoodsService extends Service
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取商品标签数据
|
||||
* @return array
|
||||
*/
|
||||
public function getMarkData(): array
|
||||
{
|
||||
$map = ['status' => 1];
|
||||
$query = $this->app->db->name('ShopGoodsMark');
|
||||
return $query->where($map)->order('sort desc,id desc')->column('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类数据
|
||||
* @param string $type 数据格式 arr2tree | arr2table
|
||||
@ -29,14 +40,39 @@ class GoodsService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品标签数据
|
||||
* 获取分类数据
|
||||
* @param boolean $simple 简化数据
|
||||
* @return array
|
||||
*/
|
||||
public function getMarkData(): array
|
||||
public function getCateData($simple = true): array
|
||||
{
|
||||
$map = ['status' => 1];
|
||||
$query = $this->app->db->name('ShopGoodsMark');
|
||||
return $query->where($map)->order('sort desc,id desc')->column('name');
|
||||
$map = ['status' => 1, 'deleted' => 0];
|
||||
$cates = $this->app->db->name('ShopGoodsCate')->where($map)->column('id,pid,name', 'id');
|
||||
foreach ($cates as $cate) if (isset($cates[$cate['pid']])) $cates[$cate['id']]['parent'] =& $cates[$cate['pid']];
|
||||
foreach ($cates as $key => $cate) {
|
||||
$id = $cate['id'];
|
||||
$cates[$id]['ids'][] = $cate['id'];
|
||||
$cates[$id]['names'][] = $cate['name'];
|
||||
while (isset($cate['parent']) && $cate = $cate['parent']) {
|
||||
$cates[$id]['ids'][] = $cate['id'];
|
||||
$cates[$id]['names'][] = $cate['name'];
|
||||
}
|
||||
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
|
||||
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
|
||||
if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) {
|
||||
unset($cates[$key]);
|
||||
}
|
||||
}
|
||||
return $cates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最大分类等级
|
||||
* @return integer
|
||||
*/
|
||||
public function getCateMax(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,40 +141,4 @@ class GoodsService extends Service
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类数据
|
||||
* @param boolean $simple 简化数据
|
||||
* @return array
|
||||
*/
|
||||
public function getCateData($simple = true): array
|
||||
{
|
||||
$map = ['status' => 1, 'deleted' => 0];
|
||||
$cates = $this->app->db->name('ShopGoodsCate')->where($map)->column('id,pid,name', 'id');
|
||||
foreach ($cates as $cate) if (isset($cates[$cate['pid']])) $cates[$cate['id']]['parent'] =& $cates[$cate['pid']];
|
||||
foreach ($cates as $key => $cate) {
|
||||
$id = $cate['id'];
|
||||
$cates[$id]['ids'][] = $cate['id'];
|
||||
$cates[$id]['names'][] = $cate['name'];
|
||||
while (isset($cate['parent']) && $cate = $cate['parent']) {
|
||||
$cates[$id]['ids'][] = $cate['id'];
|
||||
$cates[$id]['names'][] = $cate['name'];
|
||||
}
|
||||
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
|
||||
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
|
||||
if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) {
|
||||
unset($cates[$key]);
|
||||
}
|
||||
}
|
||||
return $cates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最大分类等级
|
||||
* @return integer
|
||||
*/
|
||||
public function getCateMax(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
}
|
@ -74,7 +74,7 @@ class OrderService extends Service
|
||||
|
||||
/**
|
||||
* 刷新用户入会礼包
|
||||
* @param integer $uid
|
||||
* @param integer $uid 用户UID
|
||||
* @return integer
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
@ -82,17 +82,16 @@ class OrderService extends Service
|
||||
{
|
||||
// 检查是否购买入会礼包
|
||||
$query = $this->app->db->table('shop_order a')->join('shop_order_item b', 'a.order_no=b.order_no');
|
||||
$count = $query->where("a.uid={$uid} and a.status>=4 and a.payment_status=1 and b.vip_entry>0")->count();
|
||||
$buyVipEntry = $count > 0 ? 1 : 0;
|
||||
$entry = $query->where("a.uid={$uid} and a.status>=4 and a.payment_status=1 and b.vip_entry>0")->count() ? 1 : 0;
|
||||
// 用户最后支付时间
|
||||
$query = $this->app->db->name('ShopOrder');
|
||||
$buyLastMap = [['uid', '=', $uid], ['status', '>=', 4], ['payment_status', '=', 1]];
|
||||
$buyLastDate = $query->where($buyLastMap)->order('payment_datetime desc')->value('payment_datetime');
|
||||
$lastMap = [['uid', '=', $uid], ['status', '>=', 4], ['payment_status', '=', 1]];
|
||||
$lastDate = $query->where($lastMap)->order('payment_datetime desc')->value('payment_datetime');
|
||||
// 更新用户支付信息
|
||||
$this->app->db->name('DataUser')->where(['id' => $uid])->update([
|
||||
'buy_vip_entry' => $buyVipEntry, 'buy_last_date' => $buyLastDate,
|
||||
'buy_vip_entry' => $entry, 'buy_last_date' => $lastDate,
|
||||
]);
|
||||
return $buyVipEntry;
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,6 +125,7 @@ class OrderService extends Service
|
||||
*/
|
||||
public function buildData(array &$data = [], $from = true): array
|
||||
{
|
||||
if (empty($data)) return $data;
|
||||
// 关联发货信息
|
||||
$nobs = array_unique(array_column($data, 'order_no'));
|
||||
$trucks = $this->app->db->name('ShopOrderSend')->whereIn('order_no', $nobs)->column('*', 'order_no');
|
||||
@ -135,7 +135,7 @@ class OrderService extends Service
|
||||
$items = $query->withoutField('id,uid,status,deleted,create_at')->whereIn('order_no', $nobs)->select()->toArray();
|
||||
// 关联用户数据
|
||||
$fields = 'phone,username,nickname,headimg,status,vip_code,vip_name';
|
||||
UserAdminService::instance()->buildByUid($data, 'uid', 'user', $fields);
|
||||
if ($data) UserAdminService::instance()->buildByUid($data, 'uid', 'user', $fields);
|
||||
if ($from) UserAdminService::instance()->buildByUid($data, 'puid1', 'from', $fields);
|
||||
foreach ($data as &$vo) {
|
||||
[$vo['sales'], $vo['truck'], $vo['items']] = [0, $trucks[$vo['order_no']] ?? [], []];
|
||||
|
Loading…
x
Reference in New Issue
Block a user