| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
- * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
- * =========================================================
- */
- namespace addon\store\shopapi\controller;
- use app\model\member\Hongbao as MemberHongbao;
- use app\model\system\Promotion as PromotionModel;
- /**
- * 红包控制器
- * Class Hongbao
- * @package addon\shop\siteapi\controller
- */
- class Hongbao extends BaseStoreApi
- {
- /**
- * 红包
- */
- public function lists()
- {
- $hongbao_model = new MemberHongbao();
- $site_id = $this->site_id;
- $from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : '';
- $from_type_id = isset($this->params[ 'from_type_id' ]) ? $this->params[ 'from_type_id' ] : 0;
- $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
- $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
- $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
- $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
- $from_type_name = isset($this->params[ 'from_type_name' ]) ? $this->params[ 'from_type_name' ] : '';
- $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
- $hongbao_type = isset($this->params[ 'hongbao_type' ]) ? $this->params[ 'hongbao_type' ] : '';
- $condition = [
- [ 'a.site_id', "=", $site_id ],
- ];
- if (!empty($from_type)) {
- $condition[] = [ "a.from_type", "=", $from_type ];
- }
- if (!empty($from_type_id)) {
- $condition[] = [ "a.from_type_id", "=", $from_type_id ];
- }
- if (!empty($from_type_name)) {
- $condition[] = [ "a.from_type_name", 'like', '%' . $from_type_name . '%' ];
- }
- if (!empty($hongbao_type)) {
- $condition[] = [ "a.hongbao_type", '=', $hongbao_type ];
- }
- if ($name !== '') {
- $condition[] = [ "a.name", 'like', '%' . $name . '%' ];
- }
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ 'a.create_time', '>=', date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ "a.create_time", "<=", date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'a.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- $join = [
- [ 'goods g', "g.goods_id = a.from_type_id and a.from_type = 'goods' ", 'left' ],
- [ 'promotion p', "p.promotion_id = a.from_type_id and a.from_type = 'promotion' ", 'left' ],
- ];
- $order = 'a.hongbao_id desc';
- $field = "a.*,IF(a.from_type = 'goods',(g.goods_image),(p.image)) as images,IF(a.from_type = 'goods',(g.start_time),(p.start_time)) as start_time,IF(a.from_type = 'goods',(g.end_time),(p.end_time)) as end_time,IF(a.from_type = 'goods',(g.promotion_type),(p.promotion_type)) as promotion_type";
- $list = $hongbao_model->getHongbaoPageList($condition, $page, $page_size, $order, $field, $alias = 'a', $join);
- $promotion_model = new PromotionModel();
- $promotion_type_list = $promotion_model->getPromotionType('all');
- if (!empty($list[ 'data' ][ 'list' ])) {
- foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
- $list[ 'data' ][ 'list' ][ $k ][ 'promotion_type_name' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'title' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'promotion_type_icon' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'icon' ];
- }
- }
- return $this->response($list);
- }
- /**
- * 账户红包数据
- */
- public function hongbaoAccount()
- {
- $hongbao_model = new MemberHongbao();
- $site_id = $this->site_id;
- //累计发放红包数,累计发放金额
- $total_info = $hongbao_model->getMemberHongbaoInfo([ [ 'hongbao_type', '=', 'site' ], [ 'site_id', '=', $site_id ] ], 'sum(money) as total_money, count(member_hongbao_id) as total_count')[ 'data' ];
- //累计使用
- $use_info = $hongbao_model->getMemberHongbaoInfo([ [ 'hongbao_type', '=', 'site' ], [ 'site_id', '=', $site_id ], [ 'state', '=', 2 ] ], 'sum(money) as use_money')[ 'data' ];
- //剩余
- $surplus_info = $hongbao_model->getMemberHongbaoInfo([ [ 'hongbao_type', '=', 'site' ], [ 'site_id', '=', $site_id ], [ 'state', '=', 1 ] ], 'sum(money) as surplus_money')[ 'data' ];
- $data = [];
- $data[ 'total_money' ] = $total_info[ 'total_money' ] ?? 0;
- $data[ 'total_count' ] = $total_info[ 'total_count' ] ?? 0;
- $data[ 'use_money' ] = $use_info[ 'use_money' ] ?? 0;
- $data[ 'surplus_money' ] = $surplus_info[ 'surplus_money' ] ?? 0;
- return $this->response($this->success($data));
- }
- /**
- * 红包领取记录
- */
- public function receivelists()
- {
- $hongbao_model = new MemberHongbao();
- $site_id = $this->site_id;
- $from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : '';
- $from_type_id = isset($this->params[ 'from_type_id' ]) ? $this->params[ 'from_type_id' ] : 0;
- $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
- $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
- $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
- $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
- $from_type_name = isset($this->params[ 'from_type_name' ]) ? $this->params[ 'from_type_name' ] : '';
- $parent_id = isset($this->params[ 'parent_id' ]) ? $this->params[ 'parent_id' ] : '';
- $nick_name = isset($this->params[ 'nickname' ]) ? $this->params[ 'nickname' ] : '';
- $hongbao_type = isset($this->params[ 'hongbao_type' ]) ? $this->params[ 'hongbao_type' ] : '';
- $state = isset($this->params[ 'state' ]) ? $this->params[ 'state' ] : '';
- $condition = [
- [ 'site_id', "=", $site_id ],
- ];
- if (!empty($from_type)) {
- $condition[] = [ "from_type", "=", $from_type ];
- if (!empty($from_type_id)) {
- $condition[] = [ "from_type_id", "=", $from_type_id ];
- }
- }
- if (!empty($from_type_name)) {
- $condition[] = [ "from_type_name", 'like', '%' . $from_type_name . '%' ];
- }
- if (!empty($parent_id)) {
- $condition[] = [ "hongbao_id", "=", $parent_id ];
- }
- if (!empty($nick_name)) {
- $condition[] = [ "member_name", 'like', '%' . $nick_name . '%' ];
- }
- if (!empty($hongbao_type)) {
- $condition[] = [ "hongbao_type", '=', $hongbao_type ];
- }
- if ($state !== '') {
- $condition[] = [ "state", '=', $state ];
- }
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ 'fetch_time', '>=', date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ "fetch_time", "<=", date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'fetch_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- $list = $hongbao_model->getMemberHongbaoPageList($condition, $page, $page_size);
- return $this->response($list);
- }
- /**
- * 红包详情
- */
- public function detail()
- {
- $id = isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : 0;
- $site_id = $this->site_id;
- $hongbao_model = new MemberHongbao();
- $info = $hongbao_model->getHongbaoDetail($id, $site_id);
- if (empty($info)) return $this->response($this->error([], "未获取到红包详情!"));
- return $this->response($info);
- }
- }
|