Files
liche/api/controllers/wxapp/licheb/Sytactivity.php
T
2022-02-09 15:57:27 +08:00

226 lines
9.7 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
ini_set('display_errors', 'On');
error_reporting(E_ERROR);
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
/**
* Notes:私域通-活动
* Created on: 2022/1/14 20:16
* Created by: dengbw
*/
class Sytactivity extends Wxapp
{
private $biz_id;//门店id
private $cf_id = 35;//私域直播
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->majia_white = array('get');//超级管理员披上马甲权限控制
$this->load->model('app/licheb/syt_activity_model', 'mdSytActivity');
$this->load->model('app/licheb/syt_activity_kpidata_model', 'mdSytActivityKpiData');
$this->load->model('app/licheb/syt_biz_score_model', 'mdSytBizScore');
$this->load->model('app/app_weixin_users_model', 'mdWeixinUsers');
$this->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers');
$this->load->model("biz/biz_model", 'mdBiz');
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
}
/**
* Notes:顶部菜单
* Created on: 2022/1/14 9:40
* Created by: dengbw
* @return mixed
*/
protected function get_tabs()
{
$data['title'] = '私域通';
$bm_count = $this->mdSytActivityKpiData->count(['kpi' => 'enroll']);
$dd_count = $this->mdCustomers->count(['status' => 1, 'cf_id' => $this->cf_id]);
$xd_count = $this->mdCustomers->count(['status' => 2, 'cf_id' => $this->cf_id]);
$data['bg_img'] = 'https://qs.haodian.cn/wechat_app/lichebao/siyutong/theme.jpg?v=220207';
$data['menus'] = array(array('title' => '报名', 'value' => $bm_count), array('title' => '到店', 'value' => $dd_count),
array('title' => '下定', 'value' => $xd_count));
return $data;
}
/**
* Notes:推广活动列表
* Created on: 2022/1/14 9:40
* Created by: dengbw
* @return mixed
*/
protected function get_list()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 3;
$where['status'] = 1;
$date = date('Y-m-d H:i:s');
$lists = array();
$total = $this->mdSytActivity->count($where);
if ($total) {
$res = $this->mdSytActivity->select($where, 'id DESC', $page, $size, 'id,title,s_time,e_time');
foreach ($res as $key => $value) {
$setValue = array();
$setValue['id'] = intval($value['id']);
$setValue['title'] = $value['title'];
$type_name = $color = '';
$type = 0;
$s_time = $value['s_time'];
$e_time = $value['e_time'];
if ($s_time > $date) {
$type = 1;
$type_name = '未开始';
$color = '#999';
} else if ($s_time <= $date && $e_time >= $date) {
$type = 2;
$type_name = '进行中';
$color = '#ff842d';
} else if ($e_time < $date) {
$type = 3;
$type_name = '已结束';
$color = '#996c6c';
}
$setValue['type'] = $type;
$setValue['type_name'] = $type_name;
$setValue['color'] = $color;
$lists[] = $setValue;
}
}
$data['list'] = $lists;
$data['total'] = $total;
return $data;
}
/**
* Notes:推广活动详情
* Created on: 2020/9/28 16:01
* Created by: dengbw
* @throws Hd_exception
*/
protected function get_detail()
{
$id = intval($this->input_param('id'));
if (!$id) {
throw new Hd_exception('参数错误!', API_CODE_INVILD_PARAM);
}
$re = $this->mdSytActivity->get(array("id" => $id, "status" => 1));
if (!$re) {
throw new Hd_exception('未找到活动!', API_CODE_INVILD_PARAM);
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : '';
$share_count = $this->mdSytActivityKpiData->count(['kpi' => 'share', 'a_id' => $id]);
$browse_count = $this->mdSytActivityKpiData->count(['kpi' => 'browse', 'a_id' => $id]);
$enroll_count = $this->mdSytActivityKpiData->count(['kpi' => 'enroll', 'a_id' => $id]);
$ranking = 0;
$re_biz_score = $this->mdSytBizScore->get(['a_id' => $id, 'biz_id' => $this->biz_id]);
if ($re_biz_score && $re_biz_score['score']) {
$ranking = $this->mdSytBizScore->count(['score >=' => $re_biz_score['score'], 'a_id' => $id]);
}
$data['bg_color'] = $jsondata['bg_color'] ? $jsondata['bg_color'] : '#000e66';
$data['id'] = intval($re['id']);
$data['img'] = $re['img'] ? build_qiniu_image_url($re['img']) : '';
$data['poster'] = $jsondata['posters'] ? build_qiniu_image_url($jsondata['posters'][0]['url']) : $data['img'];
$data['remark'] = $jsondata['remark'] ? $jsondata['remark'] : '';
$data['ranking'] = ['title' => '当前门店排名', 'value' => $ranking, 'url' => '/pages/siyutong/activityRanking/index?id=' . $id];
$data['menus'] = [['title' => '分享', 'value' => $share_count], ['title' => '浏览', 'value' => $browse_count]
, ['title' => '报名>', 'value' => $enroll_count, 'url' => '/pages/customer/filterList/index?a_id=' . $id]];
//生成分享连接
$this->load->library('MyEncryption');
$skey = $this->myencryption->base64url_encode("a_id={$id}&cf_uid={$this->myuid}&biz_id={$this->biz_id}&cf_share={$this->myencryption->random_string(6)}");
$myqrcode_url = http_host_com('home') . '/h5/syt/special?skey=' . $skey;
$share_url = http_host_com('home') . '/h5/syt/myqrcode/get?url=' . $myqrcode_url;
$btn_color = $jsondata['btn_color'] ? $jsondata['btn_color'] : '#ff7a28';//#aaa9a9(不可用)
$data['btn'] = ['title' => '马上邀请', 'value' => 1, 'color' => $btn_color, 'share_url' => $share_url];
return $data;
}
/**
* Notes:实时战报
* Created on: 2022/1/19 9:57
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function get_log()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 10;
$id = intval($this->input_param('id'));
if (!$id) {
throw new Hd_exception('参数错误!', API_CODE_INVILD_PARAM);
}
$lists = array();
$where = array('a_id' => $id, 'kpi<>' => 'share');
$total = $this->mdSytActivityKpiData->count($where);
if ($total) {
$res = $this->mdSytActivityKpiData->select($where, 'id DESC', $page, $size, 'uid,cf_uid,kpi,biz_id,c_time');
$uids_arr = array_unique(array_column($res, 'uid'));
$cf_uids_arr = array_unique(array_column($res, 'cf_uid'));
$uids = $this->mdWeixinUsers->get_map_by_ids($uids_arr, 'id,nickname');
$cf_uids = $this->mdLichebUsers->get_map_by_ids($cf_uids_arr, 'id,uname');
foreach ($res as $key => $value) {
$setValue = array();
if ($value['kpi'] == 'enroll') {
$content = "{$uids[$value['uid']][0]['nickname']}通过{$cf_uids[$value['cf_uid']][0]['uname']}报名了活动";
} else {
$content = "{$cf_uids[$value['cf_uid']][0]['uname']}邀请{$uids[$value['uid']][0]['nickname']}进入活动页";
}
$setValue['content'] = $content;
$setValue['c_time'] = friendly_date($value['c_time'], 'mohu');
$lists[] = $setValue;
}
}
$data['list'] = $lists;
$data['total'] = $total;
return $data;
}
/**
* Notes:活动排名
* Created on: 2022/1/19 14:25
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function get_ranking()
{
$id = intval($this->input_param('id'));
if (!$id) {
throw new Hd_exception('参数错误!', API_CODE_INVILD_PARAM);
}
$re = $this->mdSytActivity->get(array("id" => $id, "status" => 1));
if (!$re) {
throw new Hd_exception('未找到活动!', API_CODE_INVILD_PARAM);
}
$score = 0;
$ranking = [];
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : '';
$re = $this->mdSytBizScore->get(array("biz_id" => $this->biz_id));
$re['score'] && $score = $re['score'];
$res = $this->mdSytBizScore->select(['a_id' => $id], 'score DESC,id ASC', 0, 7, 'biz_id,score');
if ($res) {
$str_biz_ids = implode(',', array_column($res, 'biz_id'));
$map_biz = $this->mdBiz->map('id', 'biz_name', ["id in ({$str_biz_ids})" => null]);
foreach ($res as $key => $value) {
$num = $key + 1;
$ranking[] = ['num' => $num, 'biz_name' => $map_biz[$value['biz_id']], 'score' => $value['score'] . '分'];
}
}
$data['title'] = '活动排名';
$data['biz'] = ['title' => '我的直营店', 'value' => $score . '分'];
$data['ranking'] = $ranking;
$data['rule'] = ['title' => '积分规则>', 'value' => $jsondata['rule'] ? $jsondata['rule'] : ''];
return $data;
}
}