| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\logic;
- use app\common\enum\PresellEnum;
- use app\common\enum\SeckillEnum;
- use app\common\enum\TeamEnum;
- use app\common\logic\BaseLogic;
- use app\common\model\BargainActivity;
- use app\common\model\BargainGoods;
- use app\common\model\Presell;
- use app\common\model\PresellGoods;
- use app\common\model\SeckillActivity;
- use app\common\model\SeckillGoods;
- use app\common\model\TeamActivity;
- use app\common\model\TeamGoods;
- use app\common\service\FileService;
- class CommonLogic extends BaseLogic
- {
- public static function getActivity($get, $type)
- {
- $where = [];
- if (!empty($get['keyword']) and $get['keyword']) {
- $where[] = ['name', 'like', '%'.$get['keyword'].'%'];
- }
- switch ($type) {
- case 'team':
- $count = (new TeamActivity())->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])->count();
- $lists = (new TeamActivity())
- ->field('id,name,start_time,end_time,status')
- ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])
- ->where($where)
- ->page($get['page_no'] ?? 1, $get['page_size'] ?? 25)
- ->select()
- ->toArray();
- foreach ($lists as &$item) {
- $item['status_text'] = TeamEnum::getActivityStatusDesc($item['status']);
- $item['start_time'] = date('Y-m-d H:i:s', $item['start_time']);
- $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
- $item['goods_num'] = (new TeamGoods())->where(['team_id'=>$item['id']])->count();
- }
- return [
- 'count' => $count,
- 'lists' => $lists,
- 'page_no' => $get['page_no'] ?? 1,
- 'page_size' => $get['page_no'] ?? 25
- ];
- break;
- case 'seckill':
- $count = (new SeckillActivity()) ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])->count();
- $lists = (new SeckillActivity())
- ->field('id,name,start_time,end_time,status')
- ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])
- ->where($where)
- ->select()
- ->toArray();
- foreach ($lists as &$item) {
- $item['status_text'] = SeckillEnum::getSeckillStatusDesc($item['status']);
- $item['start_time'] = date('Y-m-d H:i:s', $item['start_time']);
- $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
- $item['goods_num'] = (new SeckillGoods())->where(['seckill_id'=>$item['id']])->count();
- }
- return [
- 'count' => $count,
- 'lists' => $lists,
- 'page_no' => $get['page_no'] ?? 1,
- 'page_size' => $get['page_no'] ?? 25
- ];
- break;
- case 'bargain':
- $count = (new BargainActivity())->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])->count();
- $lists = (new BargainActivity())
- ->field('id,name,start_time,end_time,status')
- ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])
- ->where($where)
- ->select()
- ->toArray();
- foreach ($lists as &$item) {
- $item['status_text'] = SeckillEnum::getSeckillStatusDesc($item['status']);
- $item['goods_num'] = (new BargainGoods())->where(['activity_id'=>$item['id']])->count();
- }
- return [
- 'count' => $count,
- 'lists' => $lists,
- 'page_no' => $get['page_no'] ?? 1,
- 'page_size' => $get['page_no'] ?? 25
- ];
- break;
- case "presell":
- $count = Presell::where('status', PresellEnum::STATUS_START)->count();
- $lists = Presell::where('status', PresellEnum::STATUS_START)
- ->where($where)
- ->append([ 'type_text', 'status_text', 'send_type_text', 'goods_num' ])
- ->select()
- ->toArray();
-
- return [
- 'count' => $count,
- 'lists' => $lists,
- 'page_no' => $get['page_no'] ?? 1,
- 'page_size' => $get['page_no'] ?? 25
- ];
- break;
- }
- return [];
- }
- /**
- * @notes 获取活动商品列表数据
- * @param $type
- * @param $activity_id
- * @param $keyword
- * @return array
- * @author 张无忌
- * @date 2021/10/9 18:41
- */
- public static function getActivityGoods($type, $activity_id, $keyword='')
- {
- switch ($type) {
- case 'team':
- $where = [];
- if ($keyword) {
- $where[] = ['G.name', 'like', '%'.$keyword.'%'];
- }
- $lists = (new TeamGoods())->alias('TG')
- ->field('TG.*,G.total_stock,G.name,G.image,G.min_price,G.max_price')
- ->join('goods G', 'G.id = TG.goods_id')
- ->where('TG.team_id', '=', intval($activity_id))
- ->where($where)
- ->select()->toArray();
- $data = [];
- foreach ($lists as $item) {
- $data[] = [
- 'id' => $item['id'],
- 'goods_id' => $item['goods_id'],
- 'name' => $item['name'],
- 'image' => FileService::getFileUrl($item['image']),
- 'total_stock' => $item['total_stock'],
- 'min_price' => $item['min_price'],
- 'max_price' => $item['max_price'],
- 'min_activity_price' => $item['min_team_price'],
- 'max_activity_price' => $item['max_team_price']
- ];
- }
- return $data;
- break;
- case 'seckill':
- $where = [];
- if ($keyword) {
- $where[] = ['G.name', 'like', '%'.$keyword.'%'];
- }
- $lists = (new SeckillGoods())->alias('SG')
- ->field('SG.*,G.total_stock,G.name,G.image,G.min_price,G.max_price')
- ->join('goods G', 'G.id = SG.goods_id')
- ->where('SG.seckill_id', '=', intval($activity_id))
- ->where($where)
- ->select()->toArray();
- $data = [];
- foreach ($lists as $item) {
- $data[] = [
- 'id' => $item['id'],
- 'goods_id' => $item['goods_id'],
- 'name' => $item['name'],
- 'image' => FileService::getFileUrl($item['image']),
- 'total_stock' => $item['total_stock'],
- 'min_price' => $item['min_price'],
- 'max_price' => $item['max_price'],
- 'min_activity_price' => $item['min_seckill_price'],
- 'max_activity_price' => $item['max_seckill_price'],
- ];
- }
- return $data;
- break;
- case 'bargain':
- $where = [];
- if ($keyword) {
- $where[] = ['G.name', 'like', '%'.$keyword.'%'];
- }
- $lists = (new BargainGoods())->alias('BG')
- ->field('BG.*,G.total_stock,G.name,G.image,G.min_price,G.max_price')
- ->join('goods G', 'G.id = BG.goods_id')
- ->where('BG.activity_id', '=', intval($activity_id))
- ->where($where)
- ->select()->toArray();
- $data = [];
- foreach ($lists as $item) {
- $data[] = [
- 'id' => $item['id'],
- 'goods_id' => $item['goods_id'],
- 'name' => $item['name'],
- 'image' => FileService::getFileUrl($item['image']),
- 'total_stock' => $item['total_stock'],
- 'min_price' => $item['min_price'],
- 'max_price' => $item['max_price'],
- 'min_activity_price' => $item['min_price'],
- 'max_activity_price' => $item['max_price']
- ];
- }
- return $data;
- break;
- case 'presell':
- $where = [];
- if ($keyword) {
- $where[] = ['G.name', 'like', '%'.$keyword.'%'];
- }
-
- $lists = (new PresellGoods())->alias('PG')
- ->field([ 'PG.*' ])
- ->with([ 'detail' ])
- ->join('goods G', 'G.id = PG.goods_id')
- ->where('PG.presell_id', '=', intval($activity_id))
- ->where($where)
- ->select()->toArray();
-
- $data = [];
- foreach ($lists as $item) {
- $data[] = [
- 'id' => $item['id'],
- 'goods_id' => $item['goods_id'],
- 'name' => $item['detail']['name'],
- 'image' => FileService::getFileUrl($item['detail']['image']),
- 'total_stock' => $item['detail']['total_stock'],
- 'min_price' => $item['detail']['min_price'],
- 'max_price' => $item['detail']['max_price'],
- 'min_activity_price' => $item['min_price'],
- 'max_activity_price' => $item['max_price'],
- ];
- }
- return $data;
- break;
- }
- return [];
- }
- }
|