Files
liche/home/controllers/h5/market/sylive/Ucenter.php
T
xiaoyu 6a9316dd64 0507
2025-05-07 12:39:07 +08:00

223 lines
9.1 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once 'Common.php';
class Ucenter extends Wx{
private $a_id,$skey;
public function __construct(){
parent::__construct();
$this->load->model('market/market_sylive_items_model');
$this->load->model('market/market_sylive_order_model');
$this->load->model('market/market_sylive_activity_model');
$this->load->library('market/sylive_entity');
$this->skey = $this->input->get('skey');
$param = $this->myencryption->base64url_decode($this->skey);
$this->a_id = intval($param['a_id']);//活动id
$this->data['skey'] = $this->skey;
}
public function index(){
$params = $this->input->get();
$row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]);
if(!$row){
throw new Hd_exception('参数错误',400);
}
$jsondata = json_decode($row['jsondata'],true);
$lists = [];
$lists[] = ['title'=>'我的权益','url'=>"/h5/market/sylive/ucenter/orders?skey={$params['skey']}"];
$lists[] = ['title'=>'我的抽奖','url'=>"/h5/market/sylive/ucenter/win?skey={$params['skey']}"];
$jsondata['serviceLink'] && $lists[] = ['title'=>'联系客服','url'=>$jsondata['serviceLink']];
$user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg');
$info = [
'title' => $user['nickname'],
'logo' => $user['headimg'],
'list' => $lists
];
$this->data['info'] = $info;
$this->data['params'] = $params;
$this->show_view('h5/market/sylive/ucenter/index');
}
//我的抽奖
public function win(){
$this->show_view('h5/market/sylive/ucenter/win');
}
public function ajax_win(){
$params = $this->input->get();
$page = $params['page'] ? $params['page'] : 1;
$size = $params['size'] ? $params['size'] : 20;
$where = [
'activityId' => $this->a_id,
'userId' => $this->uid,
'win' => 1
];
$total = $this->market_sylive_order_model->count($where);;
$lists = [];
if($total){
$this->load->model('market/Market_sylive_activity_draw_model', 'mdSyliveActivityDraw');
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $this->a_id]);
$winTypeAry = [];
if ($re_draw && $re_draw['winType']) {
$json_winType = json_decode($re_draw['winType'], true);
foreach ($json_winType as $v) {
$v['img'] && $v['img'] = build_qiniu_image_url($v['img']);
$winTypeAry[$v['id']] = ['img' => $v['img'], 'tag' => $v['tag'], 'title' => $v['title']];
}
}
$rows = $this->market_sylive_order_model->select($where,'id desc',$page,$size,'id,winType');
foreach ($rows as $key => $val) {
$winTypeItem = $winTypeAry[$val['winType']];
if($winTypeItem){
$lists[] = [
'id' => $val['id'],
'img' => $winTypeItem['img'],
'title' => $winTypeItem['tag'],
'goods' => $winTypeItem['title']
];
}
}
}
$data = [
'total' => $total,
'lists' => $lists
];
$this->show_json($data,200);
}
//我的订单
public function orders(){
$this->show_view('h5/market/sylive/ucenter/orders');
}
//订单详情
public function detail(){
$oid = $this->input->get('id');
$order = $this->market_sylive_order_model->get(['id'=>$oid,'userId' => $this->uid]);
if(!$order){
throw new Hd_exception('参数错误',400);
}
$item = $this->market_sylive_items_model->get(['itemId'=>$order['itemId']]);
$validity = '';
if($item['useStart'] || $item['useEnd']){
$useTimeStart = date('Y-m-d',strtotime($item['useStart']));
$useTimeEnd = date('Y-m-d',strtotime($item['useEnd']));
$validity = "有效期 {$useTimeStart} - {$useTimeEnd}";
}
$order_jsondata = json_decode($order['jsondata'],true);
$order = [
'id' => $order['id'],
'uname' => $order['uname'] ? $order['uname'] : '',
'utel' => $order['mobile'] ? $order['mobile'] : '',
'slogan' => '尊享您的直播好礼',
'valid_time' => $validity,
'sid' => $order['sid'],
'c_time' => date('Y-m-d H:i:s'),
'region' => $order_jsondata['address']['region'] ? $order_jsondata['address']['region'] : '',
'detail' => $order_jsondata['address']['detail'] ? $order_jsondata['address']['detail'] : ''
];
$if_pid = 0;
$ac_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$this->a_id],'channelId');
$ac_user['channelId'] && $pid_user = $this->user_model->get(['userId'=>$ac_user['channelId']],'uname,organizationId,mobile,headimg');
$logo = $gw_tel = $gw_slogan = $gw_title = '';
if($ac_user['channelId'] && $pid_user['organizationId']>0){
$group_id = $this->sylive_entity->get_level($pid_user['organizationId']);
if($group_id==3){ //顾问
$if_pid = 1;
$where = [
"organizationId in (select parentId from lc_market_sylive_organization where organizationId={$pid_user['organizationId']})" => null
];
$org = $this->market_sylive_organization_model->get($where);
}elseif($group_id==2){ //店长
$if_pid = 1;
$where = [
"organizationId" => $pid_user['organizationId']
];
$org = $this->market_sylive_organization_model->get($where);
}
$gw_title = $pid_user['uname'];
$gw_slogan = $org['organizationName'];
$gw_tel = $pid_user['mobile'];
$logo = $pid_user['headimg'];
}
$info = [
'bg' => "https://qs.liche.cn/web/images/project/H5-ShiYu/mine-bg.jpg",
'logo' => $logo,
'if_pid' => $if_pid,
'title' => $gw_title,
'slogan' => $gw_slogan,
'cust_tel' => $gw_tel,
'introTitle' => '权益说明',
'content' => $item['descrip'] ? $item['descrip'] : '',
'order' => $order,
'skey' => $this->data['skey'],
'ifAddress' => $item['ifAddress']
];
$this->data['info'] = $info;
$this->show_view('h5/market/sylive/ucenter/detail');
}
public function ajax_order(){
$params = $this->input->get();
$page = $params['page'] ? $params['page'] : 1;
$size = $params['size'] ? $params['size'] : 20;
$where = [
'activityId' => $this->a_id,
'userId' => $this->uid,
'type' => 0,
'status' => 1
];
$total = $this->market_sylive_order_model->count($where);
$lists = [];
if($total){
$rows = $this->market_sylive_order_model->select($where,'id desc',$page,$size);
$item_ids = implode(',',array_unique(array_column($rows,'itemId')));
$item_rows = [];
if($item_ids){
$item_rows = $this->market_sylive_items_model->map('itemId','',["itemId in ({$item_ids})"],'',0,0,'itemId,imgs');
}
foreach ($rows as $val) {
$item = $item_rows[$val['itemId']] ? $item_rows[$val['itemId']][0] : [];
$imgs = json_decode($item['imgs'],true);
$img = $imgs['banner'][0] ? build_qiniu_image_url($imgs['banner'][0]) : '';
$lists[] = [
'sid' => $val['sid'],
'img' => $img,
'title' => $val['itemTitle'],
'time' => date('Y.m.d H:i:s',strtotime($val['createTime'])),
'price' => $val['totalPrice'],
'url' => "/h5/market/sylive/ucenter/detail?skey={$this->skey}&id={$val['id']}"
];
}
}
$data = [
'total' => $total,
'lists' => $lists
];
$this->show_json($data,200);
}
//修改地址
public function edit_address(){
$params = $this->input->post();
if(!$params['region']||!$params['address']){
$this->show_json([],400,'参数错误');
}
$order = $this->market_sylive_order_model->get(['userId'=>$this->uid,'status'=>1,'id'=>$params['id']]);
if(!$order){
$this->show_json([],400,'订单不存在');
}
$jsondata = json_decode($order['jsondata'],true);
$jsondata['address']['region'] = $params['region'];
$jsondata['address']['detail'] = $params['address'];
$update = [
'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE)
];
$this->market_sylive_order_model->update($update,['id'=>$order['id']]);
$this->show_json([],200,'保存成功');
}
}