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); } }