123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\api\logic;
-
- use app\common\basics\Logic;
- use app\common\enum\GoodsEnum;
- use app\common\enum\ShopEnum;
- use app\common\model\content\Article;
- use app\common\model\goods\Goods;
- use app\common\server\ConfigServer;
- use app\common\model\shop\ShopFollow;
- use app\common\model\shop\ShopCategory;
- use app\common\server\UrlServer;
- use think\facade\Db;
-
- class PcLogic extends Logic
- {
-
-
-
- public static function commonData($user_id)
- {
-
- $article = Db::name('article')
- ->where(['del' => 0, 'is_notice' => 1, 'is_show' => 1])
- ->order('create_time desc')
- ->field('id,title')
- ->limit(3)
- ->select();
- $cart_num = 0;
- $coupon_num = 0;
- $nickname = '';
-
- if ($user_id) {
- $cart_num = Db::name('cart')->where(['user_id' => $user_id])->sum('goods_num');
- $coupon_num = Db::name('coupon_list')->where(['user_id' => $user_id, 'del' => 0, 'status' => 0])->count();
- $nickname = Db::name('user')->where(['id' => $user_id])->value('nickname');
- }
-
- return [
- 'article' => $article,
- 'logo' => UrlServer::getFileUrl(ConfigServer::get('website', 'pc_logo')),
- 'name' => ConfigServer::get('website', 'name', ''),
- 'cart_num' => $cart_num,
- 'coupon_num' => $coupon_num,
- 'nickname' => $nickname,
- 'oa_qr_code' => UrlServer::getFileUrl(ConfigServer::get('oa', 'qr_code', '')),
- 'mnp_qr_code' => UrlServer::getFileUrl(ConfigServer::get('mnp', 'qr_code', '')),
- ];
- }
-
-
-
- public static function goodsList($page, $size, $name, $category_id,$shop_id, $type, $sort_type, $sort)
- {
- $where[] = ['del', '=', GoodsEnum::DEL_NORMAL];
- $where[] = ['status', '=', GoodsEnum::STATUS_SHELVES];
- $where[] = ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];
-
-
- $banShopIds = GoodsLogic::filterShopsIds();
- if (!empty($banShopIds)) {
- $where[] = ['shop_id', 'not in', $banShopIds];
- }
-
-
- if ($name) {
- $where[] = ['name', 'like', '%' . $name . '%'];
- }
-
- if ($category_id) {
- $where[] = ['shop_cate_id', '=', $category_id];
- }
-
- if ($shop_id) {
- $where[] = ['shop_id','=',$shop_id];
- }
-
- if (1 != $type) {
- switch ($type) {
- case 2:
- $where[] = ['is_new', '=', 1];
- break;
- case 3:
- $where[] = ['is_best', '=', 1];
- break;
- }
- }
-
- $order = [];
- if ($sort_type && $sort) {
- $order = [$sort_type => $sort];
- }
-
- $goods = new Goods();
-
- $count = $goods
- ->where($where)
- ->count();
-
- $list = $goods
- ->where($where)
- ->field('id,name,image,min_price as price,market_price,sales_actual + sales_virtual as sales_sum')
- ->order($order)
- ->page($page, $size)
- ->select();
-
- $more = is_more($count, $page, $size);
-
- return [
- 'list' => $list,
- 'page' => $page,
- 'size' => $size,
- 'count' => $count,
- 'more' => $more
- ];
- }
-
-
-
- public static function changeUserInfo($post)
- {
-
- $data = [
- 'nickname' => $post['nickname'],
- 'sex' => $post['sex'],
- 'update_time' => time(),
- ];
- Db::name('user')->where(['id' => $post['user_id']])->update($data);
- return true;
- }
-
-
- public static function categoryThirdTree()
- {
-
-
-
-
-
- $lists = Db::name('goods_category')->where(['is_show' => 1, 'del' => 0, 'level' => 1])->order('sort asc')->column('id,name,pid,image,level', 'id');
- $level2 = Db::name('goods_category')->where(['is_show' => 1, 'del' => 0, 'level' => 2])->order('sort asc')->column('id,name,pid,image,level', 'id');
- $level3 = Db::name('goods_category')->where(['is_show' => 1, 'del' => 0, 'level' => 3])->order('sort asc')->field('id,name,pid,image,level')->select();
-
-
- foreach ($level3 as $list3) {
- if (isset($level2[$list3['pid']])) {
- $list3['image'] = UrlServer::getFileUrl($list3['image']);
- $list3['type'] = 1;
- $level2[$list3['pid']]['sons'][] = $list3;
- }
- }
-
- foreach ($level2 as $key2 => $list2) {
- if (isset($lists[$list2['pid']])) {
- $list2['type'] = 1;
- $list2['image'] = UrlServer::getFileUrl($list2['image']);
- $lists[$list2['pid']]['sons'][] = $list2;
- }
- }
-
-
-
- foreach ($lists as $key1 => $list1) {
- if (!isset($list1['sons'])) {
- $lists[$key1]['sons'] = [];
- }
- $lists[$key1]['image'] = UrlServer::getFileUrl($list1['image']);
- $lists[$key1]['type'] = 1;
- }
-
-
-
- return array_values($lists);
- }
-
- public static function articleDetail($id)
- {
- $article = Article::field('id,title,create_time,visit,content')
- ->where(['id' => $id])
- ->findOrEmpty();
-
- if($article->isEmpty()) {
- $article = [];
- } else {
- $article->visit = $article->visit + 1;
- $article->save();
- $article = $article->toArray();
- }
-
- $recommend_list = Db::name('article')
- ->where([['del','=','0'], ['id','<>',$id]])
- ->field('id,title,image,visit')
- ->order('visit desc')
- ->limit(5)
- ->select()
- ->toArray();
- foreach ($recommend_list as &$recommend){
- $recommend['image'] = UrlServer::getFileUrl($recommend['image']);
- }
- $article['recommend_list'] = $recommend_list;
- return $article;
- }
-
-
-
- public static function shopFollowList($get)
- {
- $where = [
- 'sf.user_id' => $get['user_id'],
- 'sf.status' => 1
- ];
-
- $lists = ShopFollow::alias('sf')
- ->field('s.id,s.name,s.cid,s.type,s.logo,s.score,s.cover,sf.shop_id')
- ->leftJoin('shop s', 's.id=sf.shop_id')
- ->where($where)
- ->order('sf.update_time', 'desc')
- ->page($get['page_no'], $get['page_size'])
- ->select()
- ->toArray();
-
- $count = ShopFollow::alias('sf')->where($where)->count();
-
- $typeDesc = [1=>'官方自营', 2=>'入驻商家'];
- foreach($lists as &$item) {
-
- $goodsWhere = [
- ['del', '=', GoodsEnum::DEL_NORMAL],
- ['status', '=', GoodsEnum::STATUS_SHELVES],
- ['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK],
- ['is_recommend', '=', 1],
- ['shop_id', '=', $item['id']]
- ];
- $item['goods_list'] = Goods::field('id,image,name,min_price,market_price')
- ->where($goodsWhere)
- ->order([
- 'sort_weight' => 'asc',
- 'id' => 'desc'
- ])
- ->limit(5)
- ->select()
- ->toArray();
-
- $item['type_desc'] = $typeDesc[$item['type']];
-
- $item['cid_desc'] = ShopCategory::where('id', $item['cid'])->value('name');
-
- $item['logo'] = UrlServer::getFileUrl($item['logo']);
- $item['cover'] = $item['cover'] ? UrlServer::getFileUrl($item['cover']) : UrlServer::getFileUrl(ShopEnum::DEFAULT_COVER);
- }
-
- $data = [
- 'lists' => $lists,
- 'count' => $count,
- 'more' => is_more($count, $get['page_no'], $get['page_size']),
- 'page_no' => $get['page_no'],
- 'page_size' => $get['page_size'],
- ];
- return $data;
- }
- }
|