412 lines
18 KiB
PHP
412 lines
18 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once 'Common.php';
|
|
|
|
class Biz extends Admin {
|
|
|
|
private $group_id;
|
|
private $liche_img = 'https://qs.haodian.cn/web/images/project/H5-ShiYu/default-avatar.jpg?v=1';
|
|
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->load->model('market/market_sylive_organization_model');
|
|
$this->load->model('market/market_sylive_activity_model');
|
|
$this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData');
|
|
$this->load->model('market/market_sylive_activity_orders_model','mdSytActivityOrders');
|
|
$this->load->library('market/sylive_entity');
|
|
$this->load->library('MyEncryption');
|
|
$this->group_id = $this->sylive_entity->get_level($this->session['org_id']);
|
|
}
|
|
|
|
public function index(){
|
|
if($this->group_id>3){
|
|
throw new Hd_exception('权限不足',400);
|
|
}
|
|
$this->data['area_id'] = $this->input->get('area_id');
|
|
if($this->group_id==2){
|
|
$biz_id = $this->session['org_id'];
|
|
}elseif($this->group_id==3) {
|
|
$biz_row = $this->market_sylive_organization_model->get(['organizationId'=>$this->session['org_id']]);
|
|
$biz_id = $biz_row['parentId'];
|
|
}else{
|
|
$biz_id = $this->input->get('biz_id');
|
|
}
|
|
$this->data['biz_id'] = $biz_id;
|
|
$this->data['group_id'] = $this->group_id;
|
|
$row = $this->market_sylive_organization_model->get(['organizationId'=>$biz_id]);
|
|
$this->data['headimg'] = $this->liche_img;
|
|
$this->data['biz_name'] = $row['organizationName'];
|
|
//微信分享
|
|
$wx_info = $this->share_info();
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->show_view('h5/market/sylive/biz/index');
|
|
}
|
|
|
|
//店铺列表
|
|
public function lists(){
|
|
if($this->group_id>1){
|
|
throw new Hd_exception('权限不足',400);
|
|
}
|
|
$area_id = $this->input->get('area_id');
|
|
$this->data['area_id'] = $area_id;
|
|
$this->data['group_id'] = $this->group_id;
|
|
//微信分享
|
|
$wx_info = $this->share_info();
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->show_view('h5/market/sylive/biz/lists');
|
|
}
|
|
//大区列表
|
|
public function brands(){
|
|
if($this->group_id!=0){
|
|
throw new Hd_exception('权限不足',400);
|
|
}
|
|
//微信分享
|
|
$wx_info = $this->share_info();
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->show_view('h5/market/sylive/biz/brands');
|
|
}
|
|
//顾问
|
|
public function detail(){
|
|
if($this->group_id!=3){
|
|
throw new Hd_exception('权限不足',400);
|
|
}
|
|
//微信分享
|
|
$wx_info = $this->share_info();
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->show_view('h5/market/sylive/biz/detail');
|
|
}
|
|
public function nav(){
|
|
if($this->group_id>1){
|
|
$this->show_json([],200);
|
|
}
|
|
$area_id = $this->input->get('area_id');
|
|
$user = $this->user_model->get(['userId'=>$this->uid]);
|
|
$data = [
|
|
'nickname' => $user['nickname'],
|
|
'headimg' => $this->liche_img
|
|
];
|
|
if($this->group_id==1 || $area_id){ //所有店铺
|
|
!$area_id && $area_id = $this->session['org_id'];
|
|
$where = [
|
|
'status' => 0,
|
|
"parentId" => $area_id
|
|
];
|
|
$count_biz = $this->market_sylive_organization_model->count($where); //门店
|
|
$where = [
|
|
'status' => 0,
|
|
"organizationId in (select organizationId from lc_market_sylive_organization where
|
|
parentId in (select organizationId from lc_market_sylive_organization where parentId={$area_id} and status=0)
|
|
)" => null
|
|
];
|
|
$count_gw = $this->user_model->count($where); //顾问
|
|
$where = [
|
|
'status' => 0,
|
|
"activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$area_id})" => null
|
|
];
|
|
$count_live = $this->market_sylive_activity_model->count($where);
|
|
$where = [
|
|
'kpi' => 'order',
|
|
"area_id" => $area_id
|
|
];
|
|
$count_order = $this->mdSytActivityKpiData->count($where);
|
|
$count = [
|
|
['title' => '门店','num' => $count_biz,'icon' => 'icon-mendian'],
|
|
['title' => '顾问','num' => $count_gw,'icon' => 'icon-wode'],
|
|
['title' => '活动','num' => $count_live,'icon' => 'icon-zhibo'],
|
|
['title' => '订单','num' => $count_order,'icon' => 'icon-dingdan'],
|
|
];
|
|
$tab = [
|
|
['id' => 1, 'title' => '门店',],
|
|
['id' => 2, 'title' => '活动',],
|
|
];
|
|
}else{ //所有大区
|
|
$count_dq = $this->market_sylive_organization_model->count(['parentId'=>$this->session['org_id'],'status'=>0]);
|
|
$where = [
|
|
'status' => 0,
|
|
"parentId in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0) and status=0" => null
|
|
];
|
|
$count_biz = $this->market_sylive_organization_model->count($where);
|
|
$where = [
|
|
'status' => 0,
|
|
"activityId in (select activityId from lc_market_sylive_activity_biz where
|
|
areaId in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)
|
|
)" => null
|
|
];
|
|
$count_live = $this->market_sylive_activity_model->count($where);
|
|
$where = [
|
|
'kpi' => 'order',
|
|
" area_id in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)" => null
|
|
];
|
|
$count_order = $this->mdSytActivityKpiData->count($where);
|
|
$count = [
|
|
['title' => '区域','num' => $count_dq,'icon' => 'icon-quyu'],
|
|
['title' => '门店','num' => $count_biz,'icon' => 'icon-mendian'],
|
|
['title' => '活动','num' => $count_live,'icon' => 'icon-zhibo'],
|
|
['title' => '订单','num' => $count_order,'icon' => 'icon-dingdan'],
|
|
];
|
|
$tab = [
|
|
['id' => 1, 'title' => '区域',],
|
|
['id' => 2, 'title' => '活动',],
|
|
];
|
|
}
|
|
$data['count'] = $count;
|
|
$data['tab'] = $tab;
|
|
$this->show_json($data,200);
|
|
}
|
|
|
|
//大区列表
|
|
public function area_lists(){
|
|
$page = $this->input->get('page');
|
|
!$page && $page = 1;
|
|
$size = 10;
|
|
$where = [
|
|
'parentId' => $this->session['org_id'],
|
|
'status' => 0,
|
|
];
|
|
$total = $this->market_sylive_organization_model->count($where);
|
|
$lists = [];
|
|
if($total){
|
|
$rows = $this->market_sylive_organization_model->select($where,'sortNumber asc,organizationId desc',$page,$size,'organizationId,parentId,organizationName');
|
|
foreach ($rows as $val) {
|
|
$where = [
|
|
'status' => 0,
|
|
"activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$val['organizationId']})" => null
|
|
];
|
|
$activitynum = $this->market_sylive_activity_model->count($where);
|
|
$temp = [
|
|
'title' => $val['organizationName'],
|
|
'storenum' => $this->market_sylive_organization_model->count(['parentId'=>$val['organizationId'],'status'=>0]),
|
|
'activitynum' => $activitynum,
|
|
'url' => '/h5/market/sylive/biz/lists?area_id='.$val['organizationId'],
|
|
'state' => [],
|
|
];
|
|
$lists[] = $temp;
|
|
}
|
|
}
|
|
$data['list'] = $lists;
|
|
$data['total'] = $total;
|
|
$this->show_json($data,200);
|
|
}
|
|
//门店列表
|
|
public function biz_lists(){
|
|
$area_id = $this->input->get('area_id');
|
|
!$area_id && $area_id = 0;
|
|
$page = $this->input->get('page');
|
|
!$page && $page = 1;
|
|
$size = 10;
|
|
$where = [
|
|
'status' => 0,
|
|
];
|
|
if($this->group_id==1){
|
|
$where['parentId'] = $this->session['org_id'];
|
|
}else{
|
|
$where['parentId'] = $area_id;
|
|
}
|
|
$total = $this->market_sylive_organization_model->count($where);
|
|
$lists = [];
|
|
if($total){
|
|
$rows = $this->market_sylive_organization_model->select($where,'sortNumber asc,organizationId desc',$page,$size,'organizationId,parentId,organizationName');
|
|
foreach ($rows as $val) {
|
|
$where = [
|
|
'status' => 0,
|
|
"activityId in (select activityId from lc_market_sylive_activity_biz where bizId={$val['organizationId']})" => null
|
|
];
|
|
$activitynum = $this->market_sylive_activity_model->count($where);
|
|
$where = [
|
|
'status' => 0,
|
|
"organizationId in (select organizationId from lc_market_sylive_organization where parentId={$val['organizationId']})" => null
|
|
];
|
|
$storenum = $this->user_model->count($where);//顾问
|
|
$temp = [
|
|
'title' => $val['organizationName'],
|
|
'storenum' => $storenum,
|
|
'activitynum' => $activitynum,
|
|
'url' => '/h5/market/sylive/biz?biz_id='.$val['organizationId'].'&area_id='.$area_id,
|
|
'state' => [],
|
|
];
|
|
$lists[] = $temp;
|
|
}
|
|
}
|
|
$data['list'] = $lists;
|
|
$data['total'] = $total;
|
|
$this->show_json($data,200);
|
|
}
|
|
//活动列表
|
|
public function act_list(){
|
|
$area_id = $this->input->get('area_id');
|
|
$biz_id = $this->input->get('biz_id');
|
|
$page = $this->input->get('page');
|
|
!$page && $page = 1;
|
|
$size = 10;
|
|
$where = [
|
|
'status' => 0,
|
|
];
|
|
if($this->group_id==3){ //顾问
|
|
$where["activityId in (select activityId from lc_market_sylive_activity_biz where
|
|
bizId in (select parentId from lc_market_sylive_organization where organizationId={$this->session['org_id']} and status=0)
|
|
)"] = null;
|
|
}elseif($this->group_id==2){ //当前店铺
|
|
$where["activityId in (select activityId from lc_market_sylive_activity_biz where bizId={$this->session['org_id']})"] = null;
|
|
}elseif($this->group_id==1) { //所有店铺
|
|
$where["activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$this->session['org_id']})"] = null;
|
|
}elseif(!$this->group_id && $biz_id){
|
|
$where["activityId in (select activityId from lc_market_sylive_activity_biz where bizId={$biz_id})"] = null;
|
|
}elseif (!$this->group_id && $area_id) {
|
|
$where["activityId in (select activityId from lc_market_sylive_activity_biz where areaId={$area_id} and status=0)"] = null;
|
|
}else{ //所有大区
|
|
$where["activityId in (select activityId from lc_market_sylive_activity_biz where
|
|
areaId in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)
|
|
)"] = null;
|
|
}
|
|
$total = $this->market_sylive_activity_model->count($where);
|
|
$lists = [];
|
|
if($total){
|
|
$rows = $this->market_sylive_activity_model->select($where,'timeStart desc',$page,$size,'activityId,title,timeStart,timeEnd,jsondata');
|
|
foreach ($rows as $val) {
|
|
$jsondata = json_decode($val['jsondata'],true);
|
|
$s_time = strtotime($val['timeStart']);
|
|
$e_time = strtotime($val['timeEnd']);
|
|
$n_time = time();
|
|
if($n_time>=$s_time&&$n_time<=$e_time){
|
|
$state = ['title'=>'活动进行中','class'=>'bg-fe9538'];
|
|
}elseif($n_time<$s_time){
|
|
$state = ['title'=>'活动预热中','class'=>'bg-ff5a5a'];
|
|
}else{
|
|
$state = ['title'=>'活动已结束','class'=>'bg-fccba0'];
|
|
}
|
|
//判断是否支付
|
|
$pay = $jsondata['pay'] ? $jsondata['pay'] : [];
|
|
$way = $pay['way'] ? intval($pay['way']) : 1; //1厂商支付 2 经销商支付
|
|
$skey = $this->myencryption->base64url_encode("a_id=" . $val['activityId']);
|
|
$pay_status = 1;
|
|
$url = '/h5/market/sylive/act?skey='.$skey;
|
|
$stat_url = '/h5/market/sylive/stic?skey='.$skey;
|
|
if($way==2 && in_array($this->group_id,[2,3])){
|
|
$where = [
|
|
'activityId' => $val['activityId'],
|
|
'status' => 1
|
|
];
|
|
if($this->group_id==3){ //顾问
|
|
$biz_row = $this->market_sylive_organization_model->get(['organizationId'=>$this->session['org_id']],'parentId');
|
|
$biz_id = $biz_row['parentId'];
|
|
}else{
|
|
$biz_id = $this->session['org_id'];
|
|
}
|
|
$where['bizId'] = $biz_id;
|
|
$pay_row = $this->mdSytActivityOrders->count($where);
|
|
if(!$pay_row){
|
|
$pay_status = 0;
|
|
if($this->group_id==3){
|
|
$url = $stat_url = '';
|
|
}else{
|
|
$url = $stat_url = '/h5/market/sylive/biz/pay?skey='.$skey;
|
|
}
|
|
}
|
|
}
|
|
|
|
$temp = [
|
|
'title' => $val['title'],
|
|
'time' => date('m-d H:i',$s_time).'~'.date('m-d H:i',$e_time),
|
|
'url' => $url,
|
|
'stat_url' => $stat_url,
|
|
'state' => $state,
|
|
'pay_status' => $pay_status,
|
|
];
|
|
$lists[] = $temp;
|
|
}
|
|
}
|
|
$data['list'] = $lists;
|
|
$data['total'] = $total;
|
|
$this->show_json($data,200);
|
|
}
|
|
|
|
//活动支付页面
|
|
public function pay(){
|
|
$skey = $this->input->get('skey');
|
|
$param = $this->myencryption->base64url_decode($skey);
|
|
$a_id = intval($param['a_id']);//活动id
|
|
$row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]);
|
|
if(!$row){
|
|
throw new Hd_exception('参数错误',400);
|
|
}
|
|
if($this->group_id!=2){
|
|
throw new Hd_exception('权限不足',400);
|
|
}
|
|
$jsondata = json_decode($row['jsondata'],true);
|
|
//判断是否支付
|
|
$pay = $jsondata['pay'] ? $jsondata['pay'] : [];
|
|
$way = $pay['way'] ? intval($pay['way']) : 1; //1厂商支付 2 经销商支付
|
|
$img = $pay['img'] ? $pay['img'] : $row['bgImg'];
|
|
$btntx = '已支付';
|
|
$pay_status = 1;
|
|
$where = [
|
|
'activityId' => $a_id,
|
|
'bizId' => $this->session['org_id'],
|
|
'status' => 1,
|
|
];
|
|
$pay_row = $this->mdSytActivityOrders->count($where);
|
|
if($way==2 && !$pay_row){
|
|
$pay_status = 0;
|
|
$btntx = "{$pay['price']}元立即支付";
|
|
}
|
|
$info = [
|
|
'status' => $pay_status,
|
|
'img' => build_qiniu_image_url($img),
|
|
'btntx' => $btntx,
|
|
'skey' => $skey,
|
|
];
|
|
$this->data['info'] = $info;
|
|
$wx_info = $this->share_info();
|
|
$this->data['sign_package'] = $wx_info['sign_package'];
|
|
$this->show_view('h5/market/sylive/biz/pay');
|
|
}
|
|
|
|
//创建支付订单
|
|
public function c_order(){
|
|
if($this->group_id!=2){
|
|
$this->show_json('',400,'权限不足');
|
|
}
|
|
$skey = $this->input->post('skey');
|
|
$param = $this->myencryption->base64url_decode($skey);
|
|
$a_id = intval($param['a_id']);//活动id
|
|
$row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]);
|
|
if(!$row){
|
|
$this->show_json('',400,'参数错误');
|
|
}
|
|
$jsondata = json_decode($row['jsondata'],true);
|
|
$pay = $jsondata['pay'] ? $jsondata['pay'] : [];
|
|
//判断是否已支付
|
|
$pay_row = $this->mdSytActivityOrders->count(['activityId'=>$a_id,'status'=>1,'bizId'=>$this->session['org_id']]);
|
|
if($pay_row){
|
|
$this->show_json('',400,'已支付,请勿重复支付');
|
|
}
|
|
$pay_price = $pay['price'];
|
|
if($pay_price<=0){
|
|
$this->show_json('',400,'无需支付');
|
|
}
|
|
$unpay = $this->mdSytActivityOrders->get(['activityId'=>$a_id,'status'=>0,'bizId'=>$this->session['org_id'],'expireTime>'=>time()]);
|
|
if(!$unpay){
|
|
$this->load->helper('order');
|
|
$unpay = [
|
|
'sid' => create_order_no('350200','market'),
|
|
'activityId' => $a_id,
|
|
'userId' => $this->uid,
|
|
'bizId' => $this->session['org_id'],
|
|
'totalPrice' => $pay_price,
|
|
'expireTime' => time()+30*60,//订单过期时间
|
|
'createTime' => date('Y-m-d H:i:s')
|
|
];
|
|
$oid = $this->mdSytActivityOrders->add($unpay);
|
|
if(!is_numeric($oid)){
|
|
$this->show_json('',400,'创建订单失败');
|
|
}
|
|
}
|
|
$user = $this->user_model->get(['userId'=>$this->uid]);
|
|
$notify_url = http_host_com('home').'/h5/market/sylive/notify/biz';
|
|
$result = $this->unorder($unpay['sid'],$unpay['totalPrice'],$user['openid'],$row['title'],$notify_url,$unpay['expireTime']);
|
|
if(!$result['code']){
|
|
$this->show_json('',400,$result['msg']);
|
|
}
|
|
$this->show_json($result['data'],200,'操作成功');
|
|
}
|
|
} |