params[ 'from_type' ]) ? $this->params[ 'from_type' ] : ''; $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1; $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS; $start_date = isset($this->params[ 'start_date' ]) ? $this->params[ 'start_date' ] : ''; $end_date = isset($this->params[ 'end_date' ]) ? $this->params[ 'end_date' ] : ''; $search_text_type = isset($this->params[ 'search_text_type' ]) ? $this->params[ 'search_text_type' ] : ''; $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : ''; $type = isset($this->params[ 'type' ]) ? $this->params[ 'type' ] : ''; $condition = [ [ 'ma.site_id', '=', $this->site_id ], [ 'ma.account_type', '=', 'point' ] ]; //来源类型 if ($from_type != '') { $condition[] = [ 'ma.from_type', '=', $from_type ]; } //发生时间 if ($start_date != '' && $end_date != '') { $condition[] = [ 'ma.create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ]; } else if ($start_date != '' && $end_date == '') { $condition[] = [ 'ma.create_time', '>=', strtotime($start_date) ]; } else if ($start_date == '' && $end_date != '') { $condition[] = [ 'ma.create_time', '<=', strtotime($end_date) ]; } if (!empty($search_text)) { if ($search_text_type == 'nickname') { $condition[] = [ 'm.nickname', 'like', "%" . $search_text . "%" ]; } else { $condition[] = [ 'm.mobile', 'like', "%" . $search_text . "%" ]; } } if ($type !== '') { if ($type == 2) {//获取 $condition[] = [ 'ma.account_data', '>', 0 ]; } if ($type == 3) {//消费 $condition[] = [ 'ma.account_data', '<', 0 ]; } } $join = [ [ 'member m', 'm.member_id = ma.member_id', 'left' ], ]; $field = 'ma.member_id,ma.fans_id,ma.account_type,ma.account_data,ma.from_type,ma.type_name,ma.remark,ma.create_time,m.nickname as m_nickname,m.headimg as m_headimg, m.mobile as m_mobile'; $member_account_model = new MemberAccount(); $res = $member_account_model->getMemberAccountPageList($condition, $page, $page_size, 'ma.create_time desc', $field, 'ma', $join); return $this->response($res); } /** * 积分 */ public function point() { $from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : ''; $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1; $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS; $start_date = isset($this->params[ 'start_date' ]) ? $this->params[ 'start_date' ] : ''; $end_date = isset($this->params[ 'end_date' ]) ? $this->params[ 'end_date' ] : ''; $from_type_id = isset($this->params[ 'from_type_id' ]) ? $this->params[ 'from_type_id' ] : ''; $condition = [ [ 'a.site_id', '=', $this->site_id ], ]; //来源类型 if ($from_type != '') { $condition[] = [ 'a.from_type', '=', $from_type ]; } if ($from_type_id != '') { $condition[] = [ 'a.from_type_id', '=', $from_type_id ]; } //发生时间 if ($start_date != '' && $end_date != '') { $condition[] = [ 'a.create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ]; } else if ($start_date != '' && $end_date == '') { $condition[] = [ 'a.create_time', '>=', strtotime($start_date) ]; } else if ($start_date == '' && $end_date != '') { $condition[] = [ 'a.create_time', '<=', strtotime($end_date) ]; } $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.state WHEN 1 WHEN 0 WHEN 2 END'; $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"; $point = new MemberPoint(); $res = $point->getPointPageList($condition, $page, $page_size, $order, $field, $alias = 'a', $join); $promotion_model = new PromotionModel(); $promotion_type_list = $promotion_model->getPromotionType('all'); if (!empty($res[ 'data' ][ 'list' ])) { foreach ($res[ 'data' ][ 'list' ] as $k => $v) { $res[ 'data' ][ 'list' ][ $k ][ 'promotion_type_name' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'title' ]; $res[ 'data' ][ 'list' ][ $k ][ 'promotion_type_icon' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'icon' ]; } } return $this->response($res); } /** * 积分配置项 */ public function pointConfig() { $point = new MemberPoint(); $config = new Config(); $config_type = $point->getConfigType(); foreach ($config_type as $k => $v) { $config_info = $config->getConfig([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', $this->app_module ], [ 'config_key', '=', $v[ 'key' ] ] ]); $config_type[ $k ][ 'config' ] = $config_info[ 'data' ]; } return $this->response($this->success($config_type)); } /** * 设置积分配置 */ public function setPointConfig() { $key = isset($this->params[ 'key' ]) ? $this->params[ 'key' ] : ''; $value = isset($this->params[ 'value' ]) ? $this->params[ 'value' ] : ''; $desc = isset($this->params[ 'desc' ]) ? $this->params[ 'desc' ] : ''; $config = new Config(); $res = $config->setConfig(json_decode($value), $desc, '1', [ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', $this->app_module ], [ 'config_key', '=', $key ] ]); return $this->response($this->success($res)); } /** * 账户积分数据 */ public function pointAccount() { $account = new MemberAccount(); //可用积分 $surplus_point = $account->getAccountSum([ [ 'site_id', '=', $this->site_id ] ], 'point')[ 'data' ]; //累计发放 $total_point = $account->getMemberAccountSum([ [ 'site_id', '=', $this->site_id ], [ 'account_type', '=', 'point' ], [ 'account_data', '>', '0' ] ], 'account_data')[ 'data' ]; //累计消耗 $use_total_point = $account->getMemberAccountSum([ [ 'site_id', '=', $this->site_id ], [ 'account_type', '=', 'point' ], [ 'account_data', '<', '0' ] ], 'account_data')[ 'data' ]; $data = []; $data[ 'surplus_point' ] = $surplus_point; $data[ 'total_point' ] = $total_point; $data[ 'use_total_point' ] = $use_total_point; return $this->response($this->success($data)); } /** * 积分来源类型类型 */ public function pointType() { $point_type = ( new MemberAccount() )->getFromType(); $point_type = $point_type[ 'point' ] ?? []; return $this->response($this->success($point_type)); } /** * 余额类型 */ public function balanceType() { $balance_type = ( new MemberAccount() )->getFromType(); $balance_type = $balance_type[ 'balance' ] ?? []; return $this->response($this->success($balance_type)); } /** * 余额流水 */ public function balance() { $from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : ''; $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1; $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS; $start_date = isset($this->params[ 'start_date' ]) ? $this->params[ 'start_date' ] : ''; $end_date = isset($this->params[ 'end_date' ]) ? $this->params[ 'end_date' ] : ''; $from_type_id = isset($this->params[ 'from_type_id' ]) ? $this->params[ 'from_type_id' ] : ''; $condition = [ [ 'a.site_id', '=', $this->site_id ], ]; //来源类型 if ($from_type != '') { $condition[] = [ 'a.from_type', '=', $from_type ]; } if ($from_type_id != '') { $condition[] = [ 'a.from_type_id', '=', $from_type_id ]; } //发生时间 if ($start_date != '' && $end_date != '') { $condition[] = [ 'a.create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ]; } else if ($start_date != '' && $end_date == '') { $condition[] = [ 'a.create_time', '>=', strtotime($start_date) ]; } else if ($start_date == '' && $end_date != '') { $condition[] = [ 'a.create_time', '<=', strtotime($end_date) ]; } $balance = new MemberBalance(); $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.state WHEN 1 WHEN 0 WHEN 2 END'; $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"; $res = $balance->getBalancePageList($condition, $page, $page_size, $order, $field, $alias = 'a', $join); $promotion_model = new PromotionModel(); $promotion_type_list = $promotion_model->getPromotionType('all'); if (!empty($res[ 'data' ][ 'list' ])) { foreach ($res[ 'data' ][ 'list' ] as $k => $v) { $res[ 'data' ][ 'list' ][ $k ][ 'promotion_type_name' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'title' ]; $res[ 'data' ][ 'list' ][ $k ][ 'promotion_type_icon' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'icon' ]; } } return $this->response($res); } /** *账户余额数据 */ public function balanceAccount() { $site_id = $this->site_id; $account = new MemberAccount(); //余额总额 $balance_money = $account->getAccountSum([ [ 'site_id', '=', $site_id ] ], 'balance_money')[ 'data' ]; $balance = $account->getAccountSum([ [ 'site_id', '=', $site_id ] ], 'balance')[ 'data' ]; //累计发放 $total_banance = $account->getMemberAccountSum([ [ 'site_id', '=', $site_id ], [ 'account_type', 'in', 'balance_money,balance' ], [ 'account_data', '>', '0' ] ], 'account_data')[ 'data' ]; //累计消耗 $use_total_banance = $account->getMemberAccountSum([ [ 'site_id', '=', $site_id ], [ 'account_type', 'in', 'balance_money,balance' ], [ 'account_data', '<', '0' ] ], 'account_data')[ 'data' ]; $data = []; $data[ 'balance_money' ] = $balance_money; $data[ 'balance' ] = $balance; $data[ 'total_banance' ] = $total_banance; $data[ 'use_total_banance' ] = abs($use_total_banance); return $this->response($this->success($data)); } /** * 余额流水 * @return mixed */ public function balanceLists() { $from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : ''; $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1; $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS; $start_date = isset($this->params[ 'start_date' ]) ? $this->params[ 'start_date' ] : ''; $end_date = isset($this->params[ 'end_date' ]) ? $this->params[ 'end_date' ] : ''; $search_text_type = isset($this->params[ 'search_text_type' ]) ? $this->params[ 'search_text_type' ] : ''; $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : ''; $type = isset($this->params[ 'type' ]) ? $this->params[ 'type' ] : ''; $condition = [ [ 'ma.site_id', '=', $this->site_id ], [ 'ma.account_type', 'in', [ 'balance', 'balance_money' ] ] ]; //来源类型 if ($from_type != '') { $condition[] = [ 'ma.from_type', '=', $from_type ]; } //发生时间 if ($start_date != '' && $end_date != '') { $condition[] = [ 'ma.create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ]; } else if ($start_date != '' && $end_date == '') { $condition[] = [ 'ma.create_time', '>=', strtotime($start_date) ]; } else if ($start_date == '' && $end_date != '') { $condition[] = [ 'ma.create_time', '<=', strtotime($end_date) ]; } if (!empty($search_text)) { if ($search_text_type == 'nickname') { $condition[] = [ 'm.nickname', 'like', "%" . $search_text . "%" ]; } else { $condition[] = [ 'm.mobile', 'like', "%" . $search_text . "%" ]; } } if ($type !== '') { if ($type == 3) {//获取 $condition[] = [ 'ma.account_data', '>', 0 ]; } if ($type == 4) {//消费 $condition[] = [ 'ma.account_data', '<', 0 ]; } } $join = [ [ 'member m', 'm.member_id = ma.member_id', 'left' ], ]; $field = 'ma.member_id,ma.fans_id,ma.account_type,ma.account_data,ma.from_type,ma.type_name,ma.remark,ma.create_time,m.nickname as m_nickname,m.headimg as m_headimg, m.mobile as m_mobile'; $member_account_model = new MemberAccount(); $res = $member_account_model->getMemberAccountPageList($condition, $page, $page_size, 'ma.create_time desc', $field, 'ma', $join); return $this->response($res); } }