pushVersion(); //$act_list = session('act_list'); //$menu_list = getMenuList($act_list); //$this->assign('menu_list',$menu_list); $admin_info = getAdminInfo($admin_id); $order_amount = M('order')->where("order_status=0 and (pay_status=1 or pay_code='cod') ".getStoWhere())->count(); $this->assign('order_amount',$order_amount); $this->assign('admin_info',$admin_info); $this->assign('menu',getMenuArr($admin_info)); $this->assign('stoid',getAdmStoId()); /*--客服权限--*/ $is_chat = tpCache("basic.is_chat", getAdmStoId()); $isin = false; if($admin_info['is_custom_service']==1){ $rs= M('storage_recharge_detail')->where('admin_id',$admin_id) ->where('end_time>'.time())->find(); if($rs) $isin = true; } //--当是qq客服 和 开启客户聊天 if ($isin && $is_chat) { $this->assign('iskefu', 1); } else { $this->assign('iskefu', 0); } $admin_id=getAdminId(); $this->assign('admin_id',$admin_id); return $this->fetch('',getAdmStoId()); } public function welcome() { $config = getManagerConf(); $this->assign('basiclist', $config); $this->assign('sys_info', $this->get_sys_info()); $today = strtotime(date('Y-m-d')); $is_accesswelcome=0; $act_list = session('act_list'); if (empty($act_list)) { $res = M('admin')->alias('a')->join('role b', 'a.role_id=b.role_id and a.store_id=b.store_id', 'left')->where(array('a.store_id'=>getAdmStoId(),'a.admin_id'=>getAdminId()))->find(); if ($res) { session('last_login_time', time()); session('admin_id', $res['admin_id']); session('last_login_ip', getIP()); session('act_list', $res['act_list']); session('get_vip_base',get_vip_base()); session('is_server', $res['is_custom_service']); $act_list=$res['act_list']; } } $act_list1=",".$act_list.","; $getwelcomeid=M('system_menu')->where('name','商城概览')->find(); if ($getwelcomeid) { $getwelcomeid=$getwelcomeid['id']; } if ($act_list=="all" || strpos(",".$act_list1,",".$getwelcomeid.",")) { $is_accesswelcome=1; } $this->assign('is_accesswelcome', $is_accesswelcome); if ($is_accesswelcome) { $storeinfo = M('store')->where('store_id', getAdmStoId())->field('smsqty')->find(); if ($storeinfo) { $count['smsqty'] = $storeinfo['smsqty']; } //会员总数 $count['users'] = M('users')->where("1=1 and erpvipid<>'' and erpvipid is not null and mobile is not null and mobile<>'' " . getStoWhere())->count(); //今日访问 $count['today_login'] = M('users') ->where("erpvipid<>'' and erpvipid is not null and mobile is not null and mobile<>''") ->where("last_login>$today " . getStoWhere())->count(); //新增会员 $count['new_users'] = M('users') ->where("erpvipid<>'' and erpvipid is not null and mobile is not null and mobile<>''") ->where("reg_time>$today " . getStoWhere())->count(); $now = time(); //上架数 $count['sjs'] = M('goods')->where("(down_time=0 or $now<=down_time) and on_time<=$now " . getStoWhere())->count(); //下架数 $count['xjs'] = $count['goods'] - $count['sjs']; //无库存数 $count['wkcs'] = M('goods')->where('store_count = 0 ' . getStoWhere())->count(); //今日销售额 upload_ylp_log('后台欢迎页面'); $fx_exists = M('storage_recharge') ->where('recharge_state', 1) ->where(array('store_id' => getAdmStoId())) ->where( "type=1 or type=5 or type=21") ->count(); $this->assign('fx_exists', $fx_exists ? $fx_exists : 0); //先判断缴费记录是否有该商家的记录 $rss = M('store_module_endtime')->where('store_id=' . getAdmStoId())->find(); if ($rss) { $this->assign('is_module_open', 1); } else { $rs = M('store_module')->where('type=0 and store_id=' . getAdmStoId())->find(); if ($rs) { $this->assign('is_module_open', 1); $this->assign('is_module_uu', 1); } else { $this->assign('is_module_open', 0); } } } return $this->fetch('',getAdmStoId()); } public function get_sys_info(){ $sys_info['os'] = PHP_OS; $sys_info['zlib'] = function_exists('gzclose') ? 'YES' : 'NO';//zlib $sys_info['safe_mode'] = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off $sys_info['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone"; $sys_info['curl'] = function_exists('curl_init') ? 'YES' : 'NO'; $sys_info['web_server'] = $_SERVER['SERVER_SOFTWARE']; $sys_info['phpv'] = phpversion(); $sys_info['ip'] = GetHostByName($_SERVER['SERVER_NAME']); $sys_info['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown'; $sys_info['max_ex_time'] = @ini_get("max_execution_time").'s'; //脚本最大执行时间 $sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false; $sys_info['domain'] = $_SERVER['HTTP_HOST']; $sys_info['memory_limit'] = ini_get('memory_limit'); $sys_info['version'] = file_get_contents(APP_PATH.'admin/conf/version.php'); $mysqlinfo = Db::query("SELECT VERSION() as version"); $sys_info['mysql_version'] = $mysqlinfo[0]['version']; if(function_exists("gd_info")){ $gd = gd_info(); $sys_info['gdinfo'] = $gd['GD Version']; }else { $sys_info['gdinfo'] = "未知"; } return $sys_info; } // 在线升级系统 public function pushVersion() { if(!empty($_SESSION['isset_push'])) return false; $_SESSION['isset_push'] = 1; error_reporting(0);//关闭所有错误报告 $app_path = dirname($_SERVER['SCRIPT_FILENAME']).'/'; $version_txt_path = $app_path.'/application/admin/conf/version.php'; $curent_version = file_get_contents($version_txt_path); $vaules = array( 'domain'=>$_SERVER['SERVER_NAME'], 'last_domain'=>$_SERVER['SERVER_NAME'], 'key_num'=>$curent_version, 'install_time'=>INSTALL_DATE, 'serial_number'=>SERIALNUMBER, ); $url = "http://service.tp-shop.cn/index.php?m=Home&c=Index&a=user_push&".http_build_query($vaules); stream_context_set_default(array('http' => array('timeout' => 3))); file_get_contents($url); } /** * ajax 修改指定表数据字段 一般修改状态 比如 是否推荐 是否开启 等 图标切换的 * table,id_name,id_value,field,value */ public function changeTableVal() { $table = I('table'); // 表名 $id_name = I('id_name'); // 表主键id名 $id_value = I('id_value'); // 表主键id值 $field = I('field'); // 修改哪个字段 $field1 = explode(",", $field); //将多行数据分开 $value = urldecode(I('value')); // 修改字段值 foreach ($field1 as $myfield) { $data[$myfield]=$value; } $res=M($table)->where("$id_name = $id_value")->save($data); // 根据条件保存修改的数据 $getremark = ""; switch ($table) { case "storage_category": $getremark = "门店分类"; break; case "pick_up": $getremark = "门店列表"; break; case "integral_buy": $getremark = "积分购"; break; case "wx_sendlist": $getremark = "微信模板列表"; break; case "ad": $getremark = "广告列表"; break; case "goods": $getremark = "商品列表"; break; case "brand": $getremark = "品牌列表"; break; case "goods_category": $getremark = "商品分类"; break; case "flash_sale": $getremark = "秒杀列表"; break; case "group_buy": $getremark = "团购活动列表"; break; case "teamlist": $getremark = "天天拼单列表"; break; case "nation": $getremark = "国别列表"; break; default; break; } if ($getremark) { adminLog("修改" . $getremark . "编号【" . $id_value . "】,字段为【" . $field . "】值为" . $value); } /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH."/".getAdmStoId()); } public function get_post() { // echo md5("erpid=ppt&erpuser=admin&erpname=超级用户&key=wxdkey123456");die; // $str=file_get_contents("php://input"); Post $ismobile=I('ismobile/d',0); $str = strtolower(I('url')); $str = str_replace('data=', '', $str); $str = urldecode($str); $iserp=0; mlog($str, "get_post"); // $str=I("data"); $fieldstr=""; if ($str != "") { $sReqData1 = explode('&', $str); $ary = array(); $arrlength = count($sReqData1); for ($i = 0; $i < $arrlength; $i++) { $ar = explode('=', $sReqData1[$i]); $k = $ar[0]; if ($k=="erpid") { $iserp=1; } $v = $ar[1]; $ary[$k] = $v; if ($i<$arrlength-1) { $fieldstr.=($i==0?"":"&").$k."=".strtolower(urlencode($v)); } } $fieldstr.="&key=".getErpKey(); //如果key不相等,报错 if ($ary['key'] !=md5($fieldstr)) { if ($ismobile==1) { goUrl('/err_mobile.html?msg=' . urlencode("Key值有误!")); } else { goUrl('/err.html?msg=' . urlencode("Key值有误!")); } } //账套商城 if ($iserp) { $condition = "c.ERPId='" . $ary['erpid'] . "' and a.ERPUser='" . $ary['erpuser'] . "'"; }else { $condition = "c.reg_mobile='" . $ary['mobile'] . "' and a.ERPUser='" . $ary['erpuser'] . "'"; } //手机商城 $condition .= " and c.is_audit=1"; $res = M('admin')->alias('a')->join('role b', 'a.role_id=b.role_id and a.store_id=b.store_id', 'left') ->join('store c', ' c.store_id=a.store_id', 'left')->where($condition) ->field('a.admin_id,a.store_id,c.supplyid,a.ERPUser, b.act_list,c.ylp_token,c.ylp_refreshtoken,c.ylp_expiresin,c.ERPId,c.store_name,c.store_contact,c.store_tel,a.is_custom_service')->find(); if ($res) { Cookie::set("newshop_admin_id", $res['admin_id']); Cookie::set("newshop_admin_stoid", $res['store_id']); Cookie::set("newshop_admin_erpid", $ary['erpid']); Cookie::set("newshop_admin_supplyid", $res['supplyid']); Cookie::set("newshop_admin_erpuser", $res['ERPUser']); session('last_login_time', time()); session('admin_id', $res['admin_id']); session('last_login_ip', getIP()); session('act_list', $res['act_list']); session('get_vip_base',get_vip_base()); session('is_server', $res['is_custom_service']); adminLog("用户登录"); $system = new \app\admin\controller\System(); $system->login_task(); // 管理员登录后 处理相关操作 } else { Cookie::clear(); if ($ismobile==1) { goUrl('/err_mobile.html?msg=' . urlencode("商户未审核或用户不存在!")); }else { goUrl('/err.html?msg=' . urlencode("商户未审核或用户不存在!")); } } if ($ismobile==1) { $this->redirect('mchat/mindex/index'); } else { $this->redirect('admin/index/index'); } } } public function apitest() { $ylp_postdata["token"] = getylp_token('ppt'); $resource["resourceName"]="测试商品1"; $resource["resourceType"]="GOODS"; $resource["resourceCode"]="zyy666"; $resource["resourcePrice"]=1.0; $resource["surplusStock"]=0; $resource["resourceImages"]=array(['imageLink'=>'http://201442.image.myqcloud.com/201442/0/bfb1277f-9fe6-45d3-b42d-1831ceec55e9/original']); $ylp_postdata["resource"]=json_encode($resource); $ylpres = httpRequest(YLPZY_URL . "/source/resource/add", 'POST', $ylp_postdata); return $ylpres; } public function ylp_lplist() { $ylp_postdata["token"] = getylp_token('ppt'); $ylp_postdata["page"]=1; $url=parameter_connect($ylp_postdata); $ylpres = httpRequest(YLPZY_URL . "/source/resource/list/?".$url, 'get'); return $ylpres; } //消息框 public function conversation(){ return $this->fetch('',getAdmStoId()); } //增加(recharge_state=0)的充值流水 public function recharge_add($param=[]) { /*$data['trxNo'] ='EMRE180118004492291'; $data['payUrl'] ='weixin://wxpay/bizpayurl?pr=dfMFxHs'; $data['recharge_no']='201801181353338'; $data['bankOrderNo']='EMRE180118004492291'; $data['buy_num']=3; $data['buy_money']=1200; $data['type']= 0;*/ $data = I('post.'); if (!empty($param)){ $data = $param; } //防止二维码生成后又清空缓存后再支付 if (!Cookie::has('newshop_admin_stoid') || Cookie("newshop_admin_stoid")==''){ return json(['code'=>-1,'msg'=>'登录信息有误,请重新登录后再试!']); } $data['store_id'] = Cookie("newshop_admin_stoid"); $data['store_name'] = M('store')->where('store_id',$data['store_id'])->find()['store_name']; $data['erpid'] = Cookie("newshop_admin_erpid"); $data['admin_id'] = Cookie("newshop_admin_id"); $data['admin_man'] = Cookie("newshop_admin_erpuser"); $data['admin_type'] = 0; //支付类型 0:扫码支付,1:手工续费 $data['billdate'] = time(); $data['add_time'] = $data['billdate']; $data['end_time'] = strtotime("+1 year"); //3=购买模板、4=客服缴费 if (($data['type']==3) || ($data['type']==1) || ($data['type']==5)){ unset($data['add_time']); unset($data['end_time']); } else if ($data['type']==4){ unset($data['add_time']); } $data['recharge_state'] = 0; //支付状态 $r = M('storage_recharge')->where('trxNo',$data['trxNo'])->select(); if (empty($r)){ $res=M('storage_recharge')->save($data); // 根据条件保存修改的数据 if ($res){ return json(['code'=> 1,'msg'=>'添加成功!']); } else { return json(['code'=>-1,'msg'=>'添加失败!']); } } return json(['code'=>-1,'msg'=>'网络繁忙!']); } //支付回调 public function notify(){ //$aaa = '{"user_no":"E8882016072010006184","status":"100","transaction_id":"4200000461201912092666245661","bankOrderNo":"EMRE1912090426857073","transaction_pay_time":"2019-12-09 11:46:36","trx_no":"EMRE1912090426857073","order_no":"201912091146238542135","amount":"1.000000","create_time":"2019-12-09 11:46:23","reconsider":"false"}'; //$parm = json_decode($aaa,true); $parm = I('param.'); mlog('支付回调返回参数'."\r\n".json_encode($parm),'notify'); if ($parm['status'] == 100) { $map = [ 'a.recharge_no' => $parm['order_no'], 'a.trxNo' => $parm['trx_no'], ]; $cs = Db::name('storage_recharge')->alias('a')->join('store b','a.store_id=b.store_id','left') ->field('a.*,b.reg_mobile') ->where($map)->select(); if (empty($cs)){ mlog('未查找到支付记录'."\r\n".json_encode($map),'notify'); return json(['code'=>-1,'msg'=>'未查找到支付记录']); die; } if (count($cs)!=1){ mlog('支付记录不唯一'."\r\n".json_encode($map),'notify'); return json(['code'=>-1,'msg'=>'支付记录不唯一']); die; } if ($cs[0]['recharge_state']!=0){ mlog('支付状态已完成'."\r\n".json_encode($map),'notify'); return json(['code'=>-1,'msg'=>'支付状态已完成']); die; } $data['id'] = $cs[0]['id']; $data['transaction_id'] = $parm['transaction_id']; $data['recharge_state'] = 1; Db::startTrans(); try { $r1 = 0; $r2 = 0; $r1 = Db::name('storage_recharge')->update($data); // if (substr($parm['order_no'],0,1) == 'm'){ if ($cs[0]['type']==3){ //购买模板 $r2 = 1; //模板购买的表记录 $ss= M("store_renew_module")->where('module_id',$cs[0]['module_id']) ->where('store_id',$cs[0]['store_id'])->find(); $upd['end_time']=$cs[0]['end_time']; if($ss){ M("store_renew_module")->where('module_id',$cs[0]['module_id'])->where('store_id',$cs[0]['store_id']) ->save($upd); }else{ $upd['module_id']=$cs[0]['module_id']; $upd['store_id']=$cs[0]['store_id']; $upd['beg_time']=time(); M("store_renew_module")->save($upd); } } else if ($cs[0]['type']==4){ //续费客服 $ids = explode(",",$cs[0]['ids']); if ($ids){ $map = [ 'store_id'=> $cs[0]['store_id'], 'admin_id'=> ['in',$ids], ]; $r2 = Db::name('storage_recharge_detail')->where($map) ->update([ 'end_time' => ['exp','UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(end_time), INTERVAL 1 YEAR))'] ]); } $tt=time(); foreach ($ids as $kk=>$vv){ $rr=Db::name('storage_recharge_detail')->where('admin_id',$vv) ->where('store_id',$cs[0]['store_id'])->find(); $d['rec_id']= $data['id']; $d['admin_id']=$vv; $d['add_time']=$tt; $time1=$rr['end_time']; $d['end_time']=$time1; $d['pernum']=$rr['per_money']; $d['store_id']=$rr['store_id']; Db::name('storage_renew')->save($d); } } else if ($cs[0]['type']==2){ //开通客服 $detail = array(); for ($i=0; $i<$cs[0]['buy_num']; $i++) { $detail[$i]['store_id'] = $cs[0]['store_id']; $detail[$i]['store_name'] = $cs[0]['store_name']; $detail[$i]['add_time'] = $cs[0]['add_time']; $detail[$i]['end_time'] = $cs[0]['end_time']; $detail[$i]['erpid'] = $cs[0]['erpid']; $detail[$i]['fromid'] = $cs[0]['id']; $detail[$i]['per_money'] = $cs[0]['buy_money']/$cs[0]['buy_num'] ; }; $r2 = Db::name('storage_recharge_detail')->insertAll($detail); } else if ($cs[0]['type']==5 || $cs[0]['type']==1 ){ //要增加会员的人数 $u=M('distri_price')->where('id',$cs[0]['distri_price_id'])->find(); $num = $u['user_num']; $map = [ 'store_id'=> $cs[0]['store_id'], ]; //重来都没分销记录的 $rs_distri=Db::name('store_distribut') ->where($map)->find(); if($rs_distri){ $old_num=$rs_distri['distribut_num']; //如果有结束时间,就代表了是续期 if( $cs[0]['end_time']) {$old_num=0;} $r2 = Db::name('store_distribut') ->where($map)->save(['distribut_num' => $num+$old_num]); }else{ Db::name('store_distribut') ->save(['distribut_num' => $num,'store_id'=> $cs[0]['store_id']]); } //---如果有时间,才会把时间进行修改--- if( $cs[0]['end_time']) { //把到期时间弄到模块到期时间表 $stoid=$cs[0]['store_id']; $where='type=2'; //0自定义模板 1送礼 2分销 $type=$cs[0]['type']; $rh = M("store_module_endtime")->where('store_id', $stoid)->where($where)->find(); if ($rh) { $dd['end_time'] = $cs[0]['end_time']; $dd['is_sy'] = 0; M("store_module_endtime")->where('id', $rh['id'])->where('store_id', $stoid)->save($dd); } else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $cs[0]['end_time']; $data0['is_sy'] = 0; $data0['type'] = 2; //2是分销 $rh = M("store_module_endtime")->save($data0); } } } //自定义模板 送礼神器 京东到家 小程序 else if ($cs[0]['type']==6 || $cs[0]['type']==7 || $cs[0]['type']==10 || $cs[0]['type']==10 || $cs[0]['type']==11){ $tty=0; if ($cs[0]['type']==6){ $tty=0; }else if ($cs[0]['type']==7){ $tty=1; } else if ($cs[0]['type']==10){ $tty=4; } else if ($cs[0]['type']==11){ $tty=5; } //自定义模板收费 $stoid=$cs[0]['store_id']; $rh=M("store_module_endtime")->where('store_id',$stoid)->where('type',$tty)->find(); if($rh){ $dd['end_time']=$cs[0]['end_time']; $dd['is_sy']=0; M("store_module_endtime")->where('id',$rh['id'])->where('store_id',$stoid)->save($dd); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $cs[0]['end_time']; $data0['is_sy'] = 0; $data0['type'] = $tty; $rh=M("store_module_endtime")->save($data0); } } else if ($cs[0]['type']==8){ //要判断会员是重新购买,还是补充人数 $u = M('dj_price')->where('id', $cs[0]['dj_price_id'])->find(); $num = $u['user_num']; $map = [ 'store_id' => $cs[0]['store_id'], ]; //重来都没等级记录的 $rs_distri = Db::name('store_config')->where($map)->find(); if ($rs_distri) { $old_num=$rs_distri['dj_num']; if ($rs_distri['dj_num'] > 0) { if( $cs[0]['end_time']) {$old_num=0;} //--回调人数要叠加-- $r2 = Db::name('store_config') ->where($map)->save(['dj_num' => $num+$old_num]); } else { //开启erp开关 $tk = M("store")->where("store_id", $cs[0]['store_id'])->field("api_token")->find(); $data['IsMem'] = 1; $mrs = getApiData("wxd.base.sys.edit", $tk['api_token'], array($data)); $storeconfig = M('store_config')->where("store_id", $cs[0]['store_id'])->field('switch_list')->find(); $rank_switch = json_decode($storeconfig['switch_list'], true); $rank_switch['rank_switch'] = 2; $r2 = Db::name('store_config') ->where($map)->save(['dj_num' => $num, 'switch_list' => json_encode($rank_switch)]); $r2str = Db::name('store_config')->fetchSql(true) ->where($map)->save(['dj_num' => $num, 'switch_list' => json_encode($rank_switch)]); mlog(r2str, 'notify/' . $cs[0]['store_id']); } } else { //开启erp开关 $tk = M("store")->where("store_id", $cs[0]['store_id'])->field("api_token")->find(); $data['IsMem'] = 1; $mrs = getApiData("wxd.base.sys.edit", $tk['api_token'], array($data)); $storeconfig = M('store_config')->where("store_id", $cs[0]['store_id'])->field('switch_list')->find(); $rank_switch = json_decode($storeconfig['switch_list'], true); $rank_switch['rank_switch'] = 2; $r2 = Db::name('store_config') ->where($map)->save(['dj_num' => $num, 'switch_list' => json_encode($rank_switch)]); $r2str = Db::name('store_config')->fetchSql(true) ->where($map)->save(['dj_num' => $num, 'switch_list' => json_encode($rank_switch)]); mlog(r2str, 'notify/' . $cs[0]['store_id']); } //把到期时间弄到模块到期时间表 $stoid = $cs[0]['store_id']; $where = 'type=3'; //0自定义模板 1送礼 2分销 $type = $cs[0]['type']; //--判断是否由新的到期的时间,等级卡续费是不补充到期的延长-- if( $cs[0]['end_time']) { $rh = M("store_module_endtime")->where('store_id', $stoid)->where($where)->find(); if ($rh) { $dd['end_time'] = $cs[0]['end_time']; $dd['is_sy'] = 0; M("store_module_endtime") ->where('id', $rh['id']) ->where('store_id', $stoid)->save($dd); } else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $cs[0]['end_time']; $data0['is_sy'] = 0; $data0['type'] = 3; //3是等级卡 $rh = M("store_module_endtime")->save($data0); } } } //充值 短信 else if ($cs[0]['type']==9) { $u=M('sms_cztype')->where('id',$cs[0]['dj_price_id'])->find(); if ($u) { $store_id=$cs[0]['store_id']; $qty = $u['user_num']; //更新商家短信数量 $store = M('store')->where('store_id',$store_id)->find(); if ($store) { $smsqty = $store['smsqty']; $smsqty = $smsqty + $qty; $store['smsqty'] = $smsqty; M('store')->where('store_id', $store_id)->update($store); //插入到短信操作记录表 smsHandle($store_id, "短信充值"); //插入短信充值记录表 $sms_data['store_id'] = $store_id; $sms_data['qty'] = $qty; $sms_data['add_time'] = time(); $sms_data['type'] =1; $sms_data['manager_id'] =$cs[0]['admin_id']; $sms_data['add_ip'] = getIP(); $r = D('sms_addlist')->add($sms_data); /*--清理缓存数据--*/ $arr = getCachaArr($store_id); foreach ($arr as $b) { Cache::rm($b); } delFile(TEMP_PATH . "/" . $store_id); } } } //等级卡续期 else if ($cs[0]['type']==20) { $u=M('dj_price')->where('id',$cs[0]['dj_price_id'])->find(); $num = $u['user_num']; $map = [ 'store_id'=> $cs[0]['store_id'], ]; //重来都没等级记录的 $rs_distri=Db::name('store_config')->where($map)->find(); if($rs_distri){ if($rs_distri['dj_num']>0) { if($num>$rs_distri['dj_num']) $r2 = Db::name('store_config')->where($map)->save(['dj_num' => $num]); }else{ //开启erp开关 $tk = M("store")->where("store_id", $cs[0]['store_id'])->field("api_token")->find(); $data['IsMem']=1; $mrs = getApiData("wxd.base.sys.edit", $tk['api_token'],array($data)); $storeconfig=M('store_config')->where("store_id",$cs[0]['store_id'])->field('switch_list')->find(); $rank_switch=json_decode($storeconfig['switch_list'],true); $rank_switch['rank_switch']=2; $r2 = Db::name('store_config') ->where($map)->save(['dj_num' => $num,'switch_list'=>json_encode($rank_switch)]); $r2str = Db::name('store_config')->fetchSql(true) ->where($map)->save(['dj_num' => $num,'switch_list'=>json_encode($rank_switch)]); mlog($r2str,'notify/'.$cs[0]['store_id']); } }else{ //开启erp开关 $tk = M("store")->where("store_id", $cs[0]['store_id'])->field("api_token")->find(); $data['IsMem']=1; $mrs = getApiData("wxd.base.sys.edit", $tk['api_token'],array($data)); $storeconfig=M('store_config')->where("store_id",$cs[0]['store_id'])->field('switch_list')->find(); $rank_switch=json_decode($storeconfig['switch_list'],true); $rank_switch['rank_switch']=2; $r2 = Db::name('store_config') ->where($map)->save(['dj_num' => $num,'switch_list'=>json_encode($rank_switch)]); $r2str = Db::name('store_config')->fetchSql(true) ->where($map)->save(['dj_num' => $num,'switch_list'=>json_encode($rank_switch)]); mlog($r2str,'notify/'.$cs[0]['store_id']); } //把到期时间弄到模块到期时间表 $stoid=$cs[0]['store_id']; $where='type=3'; //0自定义模板 1送礼 2分销 $type=$cs[0]['type']; $rh=M("store_module_endtime")->where('store_id',$stoid)->where($where)->find(); if($rh){ $dd['end_time']=$cs[0]['end_time']; $dd['is_sy']=0; M("store_module_endtime")->where('id',$rh['id'])->where('store_id',$stoid)->save($dd); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $cs[0]['end_time']; $data0['is_sy'] = 0; $data0['type'] = 3; //3是等级卡 $rh=M("store_module_endtime")->save($data0); } } else if ($cs[0]['type']==21 ){ $u=M('distri_price')->where('id',$cs[0]['distri_price_id'])->find(); $num = $u['user_num']; $map = [ 'store_id'=> $cs[0]['store_id'], ]; //重来都没分销记录的 $rs_distri=Db::name('store_distribut') ->where($map)->find(); if($rs_distri){ $r2 = Db::name('store_distribut') ->where($map)->save(['distribut_num' => $num]); }else{ Db::name('store_distribut') ->save(['distribut_num' => $num,'store_id'=> $cs[0]['store_id']]); } //把到期时间弄到模块到期时间表 $stoid=$cs[0]['store_id']; $where='type=2'; //0自定义模板 1送礼 2分销 $type=$cs[0]['type']; $rh=M("store_module_endtime")->where('store_id',$stoid)->where($where)->find(); if($rh){ $dd['end_time']=$cs[0]['end_time']; $dd['is_sy']=0; M("store_module_endtime")->where('id',$rh['id'])->where('store_id',$stoid)->save($dd); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $cs[0]['end_time']; $data0['is_sy'] = 0; $data0['type'] = 2; //2是分销 $rh=M("store_module_endtime")->save($data0); } } Db::commit(); $wareid=""; if($cs[0]['type']==1 || $cs[0]['type']==5 || $cs[0]['type']==21){ $wareid="76D69994-6077-4D84-AAE6-F1331AC75066"; //分销 }else if($cs[0]['type']==2 || $cs[0]['type']==4){ $wareid="124C8E53-5933-4C69-924A-154545DFAB6C"; //在线客服 }else if($cs[0]['type']==3 || $cs[0]['type']==6){ $wareid='45D4CE52-E1DF-4E2F-90B9-C9078B2CE140'; //模板 }else if($cs[0]['type']==8 || $cs[0]['type']==20) { $wareid='870E3A7C-58B6-4CBB-83A7-40A7CEED80CD'; //等级卡 } else if ($cs[0]['type']==9) { $wareid='59B13F1F-A381-465A-BAE1-8609FF8AD1D8';//充值短信 } else if($cs[0]['type']==10){ $wareid='0469449C-D8EA-443B-99D7-5FCF11DE3361';//充值京东 } else if($cs[0]['type']==11){ $wareid='E9089CDD-43E4-47AA-9F2F-DF00D8AFD383';//充值小程序 } $remark=""; $accdb=""; if(!empty($cs[0]['erpid'])) { //待入OA接口 $accdb = $cs[0]['erpid']; }else{ $remark="线上商家".$cs[0]['store_name']." ID:".$cs[0]['store_id']; $accdb="cdzy"; //固定值 if ($cs[0]['type']==9) { $remark="【已充值】线上商家".$cs[0]['store_name']."(".$cs[0]['reg_mobile'].") ID:".$cs[0]['store_id']; } } mlog('remark:' . $remark, 'notify/' . $cs[0]['store_id']); //正式环境才需要传OA //if (post_oa_url) { $pd['Number'] = $cs[0]['recharge_no']; $pd['BillDate'] = date("Y-m-d H:i:s"); $pd['alipay_trade_no'] = $parm['transaction_id']; $pd['accdb'] = $accdb; $pd['WareId'] = $wareid; //接口要带入的商品ID $pd['Qty'] = $cs[0]['buy_num']; //购买数量 $pd['Price'] = $cs[0]['buy_money'] / $cs[0]['buy_num'];//购买金额 $pd['remark'] = $remark; //$url="http://em.it250.cn:6081/data/exec?access_token=wxdoa.trade.add&token=CE4416DC64C6C5B9A4247579555A2FF1"; //$rs = http_post_json(post_oa_url, json_encode($pdd)); $url = "http://open.xinda100.com/api/wxd/order/insert"; $res = httpRequest($url, "POST", $pd); $pdd[] = $pd; mlog('post:' . json_encode($res), 'notify/' . $cs[0]['store_id']); //} echo 'SUCCESS'; } catch (\Exception $e) { Db::rollback(); echo 'fail'; } } else { echo "SUCCESS"; } } //删除未充值的记录 public function recharge_del(){ $map = [ 'recharge_state' => 0, 'store_id' => getAdmStoId(), ]; $r = M('storage_recharge')->where($map)->select(); if ($r){ mlog('删除未充值的记录'."\r\n".json_encode($r),'recharge_del'); $res = M('storage_recharge')->where($map)->delete(); } } //有效客服人数 public function useful_kf($type='json'){ $time = time(); $map = [ 'store_id' => getAdmStoId(), 'add_time' => ['<',$time], 'end_time' => ['>',$time], ]; $count = M('storage_recharge_detail')->where($map)->count(); if ($type=='json'){ return json(['code'=>1,'msg'=>$count]); } else { return ['code'=>1,'msg'=>$count]; } } //客服续费 public function show_Customer() { $map = [ 'a.store_id' => getAdmStoId(), 'a.is_custom_service' => ['=',1], ]; $keywords = I('keywords'); if ($keywords){ $map['a.ERPName'] = ['like',"%$keywords%"]; } $order = ['b.end_time asc']; $r = M('admin')-> alias('a') -> join('(select admin_id,add_time,end_time,per_money from wxd_storage_recharge_detail where store_id='.getAdmStoId().') as b','a.admin_id=b.admin_id','right') -> field('b.per_money,a.admin_id,a.ERPUser,a.ERPName,FROM_UNIXTIME(b.add_time) as add_time,FROM_UNIXTIME(b.end_time) as end_time') -> where($map) -> order($order) -> select(); $count = count($r); $this -> assign('count',$count); $this -> assign('adminlist',$r); return $this->fetch('search_chat'); } //购买分销人数前校验是否已经开通分销功能 public function check_distribution($type='json'){ return ['code'=>1]; } //分销 public function show_distribution(){ $ucount=M('users')->where("store_id",getAdmStoId())->where('is_distribut',1)->count(); $dis_config=M("store_distribut")->where('store_id',getAdmStoId())->find(); $old_max_num=$dis_config['distribut_num']; $this->assign('old_max_num', $old_max_num); $this->assign('ucount',$ucount); $yy=M("storage_recharge")->where("store_id",getAdmStoId())->where('recharge_state',1)->order('buy_money desc,distri_price_id desc') ->where("distri_price_id>0")->field('distri_price_id')->select(); $aarr = M("distri_price")->order('type desc,money desc,id desc')->select(); $barr = null; //--续期--- $is_xuqi=I("is_xuqi"); if($is_xuqi){ $this->assign("is_xuqi",$is_xuqi); } if($yy) { $this->assign("is_buyed",1); //--计算剩余月数-- $Max_end_time=M("storage_recharge")->where("store_id", getAdmStoId())->where('recharge_state', 1) ->where("distri_price_id>0")->max("end_time"); //--当用户的功能还没有到期-- if($Max_end_time>time()){ $this->assign('Max_end_time', $Max_end_time); //--是不是续期-- if($is_xuqi){ $exp_date=strtotime("+1 years ",$Max_end_time); $this->assign("exp_date",$exp_date); }else{ $two_time=two_time($Max_end_time); $this->assign('two_time', $two_time); } } //--如果不是--- else{ $exp_date=strtotime("+1 years ",time()); $this->assign("exp_date",$exp_date); $this->assign('ucount', $ucount); } $has_buy=0; foreach ($aarr as $k => $v) { //也就是曾经买过的 if($v['id']==$yy[0]['distri_price_id']){ $v['is_buy']=1;$has_buy=1; } //---还没有过期的情况下,的人数计算--- if($is_xuqi && $Max_end_time>time()){ if ($v['user_num'] >= $old_max_num && $v['type'] == 0) { if ($v['money'] <= 0) continue; $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; continue; } }else{ if ($v['user_num'] > $ucount && $v['type'] == 0) { if ($v['money'] <= 0) continue; $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; continue; } } } if(!$has_buy) $barr[0]['is_buy']=1; }else{ $exp_date=strtotime("+1 years ",time()); $this->assign("exp_date",$exp_date); //看是不是有体验了 $ty=M("store_module_endtime")->where('is_sy',1)->where("store_id",getAdmStoId())->where('type',2)->find(); if($ty){ foreach ($aarr as $k => $v) { if ( $v['type'] == 0) { if ($v['money'] <= 0) continue; $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; continue; } } $barr[0]['is_buy']=1; $this->assign('ucount', $ucount); }else{ $barr=$aarr; $barr[0]['is_buy']=1; $this->assign('ucount', 0); } } if($barr){ $this -> assign('price_arr',array_reverse($barr)); } if($yy){ if($Max_end_time){ if($is_xuqi) return $this->fetch('distribution2', getAdmStoId()); else return $this->fetch('distribution', getAdmStoId()); } return $this->fetch('distribution', getAdmStoId()); } return $this->fetch('distribution2',getAdmStoId()); } //充值短信 public function show_smscz(){ $barr=array(); $barr=M('sms_cztype')->select(); $this -> assign('price_arr',$barr); return $this->fetch(''); } public function Create_QRCode() { $buy_num = (int)I('buy_num');//数量 $buy_money = 0;//金额 if (empty($buy_num) || ($buy_num<=0)){ return json(['code'=>-1,'msg'=>'数量不正确!']); } $payWay = I('payWay'); if ($payWay==''||($payWay!='ALIPAY' && $payWay!='WEIXIN')){ return json(['code'=>-1,'msg'=>'支付方式不正确!']); } $type = I('type');//1分销推广(总后台) 2客服开通 3自定义模板缴费 4客服续费 5分销推广(续费支付购买) $mid = I('mid');//模板ID $ids=I('ids'); $pid=0; $is_deng_xufei=0; if ($type==''){ return json(['code'=>-1,'msg'=>'类型不正确!']); } else { switch ($type){ case 2://客服人员开通 $temp = $this -> useful_kf('array'); $num=$temp['msg']+$buy_num; if ($num<3){ $buy_money = $buy_num * 500; } else { $buy_money = $buy_num * 400; } break; case 3://自定义模板缴费 $muu=M('store_module')->where('id',$mid)->find(); if($muu){ $buy_money=$muu['money']; }else{ return json(['code'=>-1,'msg'=>'未找到模板!']); } break; case 4://客服续费 $where=" admin_id in(".$ids.")"; $buy_money=M('storage_recharge_detail')->where($where) ->where('store_id',getAdmStoId())->sum('per_money'); break; case 1: case 5://分销人员续费 $pid=I('pid'); $pp=M('distri_price')->where('type',0)->where('id',$pid)->find(); if(empty($pp)) return json(['code'=>-1,'msg'=>'未找到支付金额!']); $buy_money=$pp['money']; $buy_num=1; //--计算剩余月数-- $Max_end_time=M("storage_recharge")->where("store_id", getAdmStoId())->where('recharge_state', 1) ->where("distri_price_id>0")->max("end_time"); if($Max_end_time>time()) { $two_time = two_time($Max_end_time); $buy_money= floor($buy_money/12 *$two_time*100)/100; $is_distri_xufei=1; } break; case 6://自定义模板的功能 $buy_money=388; break; case 7://自定义模板的功能 $buy_money=688; break; case 8://等级卡功能开通 //计算钱的功能要修改下 $pid = I('pid'); $pp = M('dj_price')->where('type', 0)->where('id', $pid)->find(); if (empty($pp)) return json(['code' => -1, 'msg' => '未找到支付金额!']); $buy_money = $pp['money']; $buy_num = 1; //--计算剩余月数-- $Max_end_time=M("storage_recharge")->where("store_id", getAdmStoId())->where('recharge_state', 1) ->where("dj_price_id>0")->max("end_time"); if($Max_end_time>time()) { $two_time = two_time($Max_end_time); $buy_money= floor($buy_money/12 *$two_time*100)/100; $is_deng_xufei=1; } break; case 9://充值短信 $pid=I('pid'); $pp=M('sms_cztype')->where('id',$pid)->find(); if(empty($pp)) return json(['code'=>-1,'msg'=>'未找到支付金额!']); $buy_money=$pp['money']; break; case 10://充值京东 $buy_money=1980; break; case 11://充值小程序 $pid=I('pid'); $pp=M('wxapp_price')->where('type',0)->where('id',$pid)->find(); if(empty($pp)) return json(['code'=>-1,'msg'=>'未找到支付金额!']); $buy_money=$pp['money']; $buy_num=1; break; case 20://等级卡续期 $pid=I('pid'); $pp=M('dj_price')->where('type',0)->where('id',$pid)->find(); if(empty($pp)) return json(['code'=>-1,'msg'=>'未找到支付金额!']); $buy_money=$pp['money']; $buy_num=1; break; case 21://分销续期 $pid=I('pid'); $pp=M('distri_price')->where('type',0)->where('id',$pid)->find(); if(empty($pp)) return json(['code'=>-1,'msg'=>'未找到支付金额!']); $buy_money=$pp['money']; $buy_num=1; break; default: return json(['code'=>-1,'msg'=>'购买类型不正确!']); }; } if (empty($buy_money) || ($buy_money<=0)){ return json(['code'=>-1,'msg'=>'金额不正确!']); } $NotifyUrl = curHostURL().'/admin/Index/notify'; $orderNo = $this -> get_orderNo(); $param = "businessType=ERP_MALL_RCG".//业务类型 "¬ifyUrl=$NotifyUrl".//回调地址 "&orderNo=$orderNo".//订单号 "&payWay=$payWay".//支付方式 "&price=$buy_money".//金额 //"&price=0.01".//金额 "&productName=ERP_MALL_RCG". "&userNo=".pay_userNo; $sign = '&sign='.strtoupper(md5($param.'&key='.pay_key)); $url = pay_url.'?'.$param.$sign; // $header[0] = "Content-Type:application/json;charset=UTF-8"; // $header[1] = "Accept:application/json;charset=UTF-8"; // $para=parameter_connect($para); //支付接口 $data = httpRequest($url,'GET',''); $r = json_decode(urldecode($data),true); //成功返回参数 //{"code":0,"msg":"Success","data":{"amount":0.01,"trxNo":"EMRE1801300638889157","orderNo":"201801301550351456021","bankOrderNo":"EMRE1801300638889157","payUrl":"https://qr.alipay.com/bax046347msbc8nauage00f2"}} if ($r['code']!=0){ return json(['code'=>-1,'msg'=>$r['msg']]); } /*生成状态为0的充值记录*/ $payWay = $payWay == 'WEIXIN' ? 1 : 2; $data = [ 'trxNo'=> $r['data']['trxNo'],//流水号 'payUrl'=> $r['data']['payUrl'],//支付链接 'recharge_no'=> $r['data']['orderNo'],//传入的orderNo 'bankOrderNo'=> $r['data']['bankOrderNo'],//银行订单号=流水号 'buy_num'=> $buy_num,//数量 'buy_money'=> $buy_money,//金额 'recharge_type'=> $payWay,//支付方式 'type'=> $type,//开通类型 ]; //防止二维码生成后又清空缓存后再支付 if (!Cookie::has('newshop_admin_stoid') || Cookie("newshop_admin_stoid")==''){ return json(['code'=>-1,'msg'=>'登录信息有误,请重新登录后再试!']); } //删除24小时之前的未支付数据 M('storage_recharge')->where(array('store_id'=>getAdmStoId(),'recharge_state'=>0,'billdate'=>array('elt',strtotime("-1 day"))))->delete(); $data['store_id'] = Cookie("newshop_admin_stoid"); $data['store_name'] = M('store')->where('store_id',$data['store_id'])->find()['store_name']; $data['erpid'] = Cookie("newshop_admin_erpid"); $data['admin_id'] = Cookie("newshop_admin_id"); $data['admin_man'] = Cookie("newshop_admin_erpuser"); $data['admin_type'] = 0; //支付类型 0:扫码支付,1:手工续费 $data['billdate'] = time(); $data['add_time'] = $data['billdate']; if(!$is_deng_xufei & ($type==8 || $type==20)) { $data['end_time'] = strtotime("+1 year"); }else if(!$is_distri_xufei && ($type==1 || $type==5 || $type==21 )) { $data['end_time'] = strtotime("+1 year"); }else if($type!=8 && $type!=20 && $type!=1 && $type!=5 && $type!=21 ){ $data['end_time'] = strtotime("+1 year"); } if($pid && ($type==1 || $type==5 || $type==21 )) { $data['distri_price_id'] = $pid; //记录购买的价格ID } else if($pid && ($type==8 || $type==20)) { $data['dj_price_id'] = $pid; //记录购买的价格ID }else if ($pid && $type==9) { $data['dj_price_id'] = $pid; //记录购买的价格ID } /*--购买金额和购买数量--*/ $data['buy_money'] = $buy_money; $data['buy_num'] = $buy_num; $data['ids']=$ids;// $data['module_id']=$mid; //处理分销到期时间 if($data['type']==21) { $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',2)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } //处理购买模板的到期时间 if($data['type']==3){ $ttyy=0; $md=M("store_module")->where('id',$mid)->find(); $ss=M("store_renew_module")->where('module_id',$mid) ->where('store_id',getAdmStoId())->find(); $days=$md['days']; if($days) { if ($ss) { if ($ss['end_time'] <= time()) { $ttyy = strtotime("+$days day", time()); } else { $ttyy = strtotime("+$days day", $ss['end_time']); } } else { $ttyy = strtotime("+$days day", time()); } //时间处理 // $days=$md['days']; // $y = date("Y",$ttyy); $m = date("m",$ttyy);$d = date("d",$ttyy); // $end_time= mktime(0,0,0,$m,$d,$y); $data['end_time'] =$ttyy; }else{ $data['end_time'] =0; } } /*---如果是自定义模板功能,老用户从5.1开始算时间---*/ if($data['type']==6){ $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',0)->find(); if($rs0){ $time2=0; if($rs0['is_sy']==1){ $time2=strtotime('+1 year'); } else{ if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } if($data['type']==7){ $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',1)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } //等级卡,如果是升级,就不要填写到期时间 if($data['type']==8 && !$is_deng_xufei){ $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',3)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } //---等级的续期---- if($data['type']==20){ $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',3)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } //京东到家 if($data['type']==10){ $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',4)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } //小程序 if($data['type']==11){ $rs0=M("store_module_endtime") ->where('store_id',getAdmStoId())->where('type',5)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime('+1 year',$rs0['end_time']); }else{ $time2=strtotime('+1 year',time()); } $data['end_time']=$time2; }else{ $time2=strtotime('+1 year'); $data['end_time']=$time2; } } $data['recharge_state'] = 0; //支付状态 $r = M('storage_recharge')->where('trxNo',$data['trxNo'])->field('trxNo')->select(); if (empty($r)){ $res=M('storage_recharge')->save($data); // 根据条件保存修改的数据 if ($res){ return json([ 'code'=> 1, 'msg'=>'添加成功!', 'payUrl'=>$data['payUrl'], 'orderNo'=>$data['recharge_no'], 'bankOrderNo'=>$data['bankOrderNo'], 'trxNo'=>$data['trxNo'], ]); } else { return json(['code'=>-1,'msg'=>'添加失败!']); } } return json(['code'=>-1,'msg'=>'网络繁忙!']); } function get_orderNo(){ $timestamp = date('Y-m-d H:i:s');//当前时间 $timestamp = str_replace(":", "", $timestamp); $timestamp = str_replace("-", "", $timestamp); $timestamp = str_replace(" ", "", $timestamp); $rand = rand(1000000,9999999); return $timestamp.$rand; } //获取购买模板到期时间 function useful_module(){ $type=I("type"); switch ($type){ case "6":$type=0;break; case "7":$type=1;break; case "8":$type=3;break; case "10":$type=4;break; case "11":$type=5;break; } //先判断缴费记录是否有该商家的记录 $rss=M('store_module_endtime')->where('store_id='.getAdmStoId())->where('type',$type) ->where('is_sy',0)->find(); if($rss){ $end_time=strtotime('+1 year',$rss['end_time']); $end_time=date("Y-m-d H:i:s",$end_time); return json(['code'=>1,'end_time'=>$end_time]); }else{ $end_time=strtotime('+1 year',time()); $end_time=date("Y-m-d H:i:s",$end_time); return json(['code'=>1,'end_time'=>$end_time]); } } //免费体验 function mfty(){ $stoid=getAdmStoId(); //先判断缴费记录是否有该商家的记录 $rh=M("store_module_endtime")->where('store_id',$stoid) ->where('type',0)->find(); if($rh){ return json(['code'=>-1]); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = strtotime('+1 month',time()); $data0['is_sy'] = 1; $rh=M("store_module_endtime")->save($data0); return json(['code'=>1]); } } //--显示等级卡的购买列表-- function show_dj() { //$ucount = M('users')->where("store_id", getAdmStoId()) // ->where("card_field<>''")->count(); //$this->assign('ucount', $ucount); $s_config=M("store_config")->where('store_id',getAdmStoId())->find(); $store_m=M('store_module_endtime')->where('store_id',1)->where('type',3)->find(); //$ucount=$s_config['dj_num']; $old_max_num=$s_config['dj_num']; $this->assign('old_max_num', $old_max_num); //--看商品买了哪个最高挡位-- $yy = M("storage_recharge")->where("store_id", getAdmStoId())->where('recharge_state', 1) ->where("dj_price_id>0")->field('dj_price_id')->order('buy_money desc,dj_price_id desc')->select(); $aarr = M("dj_price")->order('type desc,money desc')->select(); $barr = null; //--续期--- $is_xuqi=I("is_xuqi"); if($is_xuqi){ $this->assign("is_xuqi",$is_xuqi); } //---有买过的时候---- if ($yy) { //-- 已用人数要调用线下 -- $erp = tpCache("shop_info.ERPId",getAdmStoId()); //$datap['EndDate']= date("Y-m-d", $store_m['end_time']); $rs=getApiData_java_p("/api/erp/vip/mem/card/count",$erp,null,1,1); if($rs){ $rs=json_decode($rs,true); if($rs['code']==0){ if($rs['data'] && is_array($rs['data'])){ $ucount=$rs['data']['SumTotal']; } } $this->assign('ucount', $ucount); }else{ $this->assign('ucount', 0); } $this->assign("is_buyed",1); //--计算剩余月数-- $Max_end_time=M("storage_recharge")->where("store_id", getAdmStoId())->where('recharge_state', 1) ->where("dj_price_id>0")->max("end_time"); //--当用户的功能还没有到期-- if($Max_end_time>time()){ $this->assign('Max_end_time', $Max_end_time); //--是不是续期-- if($is_xuqi){ $exp_date=strtotime("+1 years ",$Max_end_time); $this->assign("exp_date",$exp_date); }else{ $two_time=two_time($Max_end_time); $this->assign('two_time', $two_time); } } //--如果不是--- else{ $exp_date=strtotime("+1 years ",time()); $this->assign("exp_date",$exp_date); $this->assign('ucount', $ucount); } $has_buy=0; foreach ($aarr as $k => $v) { //也就是曾经买过的 if($v['id']==$yy[0]['dj_price_id']) { $v['is_buy']=1;$has_buy=1; } //---还没有过期的情况下,的人数计算--- if($is_xuqi && $Max_end_time>time()){ if ($v['user_num'] >= $old_max_num && $v['type'] == 0) { if ($v['money'] <= 0) continue; $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; continue; } }else{ if ($v['user_num'] > $ucount && $v['type'] == 0) { if ($v['money'] <= 0) continue; $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; continue; } } } if(!$has_buy) $barr[0]['is_buy']=1; }else { $exp_date=strtotime("+1 years ",time()); $this->assign("exp_date",$exp_date); //看是不是有体验了 $ty=M("store_module_endtime")->where('is_sy',1)->where("store_id",getAdmStoId())->where('type',3)->find(); if($ty){ foreach ($aarr as $k => $v) { if ( $v['type'] == 0) { if ($v['money'] <= 0) continue; $barr[] = $v; } else { if ($v['type'] == 1) $barr[] = $v; continue; } } $barr[0]['is_buy']=1; //-- 已用人数要调用线下 -- $erp = tpCache("shop_info.ERPId",getAdmStoId()); $rs=getApiData_java_p("/api/erp/vip/mem/card/count",$erp,null,1,1); if($rs){ $rs=json_decode($rs,true); if($rs['code']==0){ if($rs['data'] && is_array($rs['data'])){ $ucount=$rs['data']['SumTotal']; } } $this->assign('ucount', $ucount); }else{ $this->assign('ucount', 0); } }else{ $barr = $aarr; $barr[0]['is_buy']=1; $this->assign('ucount', 0); } } if ($barr) { $this->assign('price_arr', array_reverse($barr)); } if($yy){ if($Max_end_time){ if($is_xuqi) return $this->fetch('show_dj2', getAdmStoId()); else return $this->fetch('', getAdmStoId()); } return $this->fetch('', getAdmStoId()); } else return $this->fetch('show_dj2', getAdmStoId()); } //免费体检 function free_tast(){ $tk = M("store_config")->where("store_id", getAdmStoId()) ->field("dj_num,switch_list")->find(); $rank_switch=json_decode($tk['switch_list'],true); if($tk['dj_num']>0){ return json(['code'=>-1,'msg'=>'您已经体验过了']); }else{ $tk = M("store")->where("store_id", getAdmStoId())->field("api_token")->find(); $data['IsMem']=1; $mrs = getApiData("wxd.base.sys.edit", $tk['api_token'],array($data)); M("store_config")->where("store_id", getAdmStoId()) ->save(["dj_num"=>10]); $data0['store_id'] = getAdmStoId(); $data0['beg_time'] = time(); $data0['is_sy'] = 1; $data0['type'] = 3; //3是等级卡 $rh = M("store_module_endtime")->save($data0); $rank_switch['rank_switch']=2; $r2 = M('store_config') ->where("store_id",getAdmStoId())->save(['switch_list'=>json_encode($rank_switch)]); return json(['code'=>1,'msg'=>'提交体验成功']); } } //免费体检分销 function free_tast_distri(){ $tk = M("store_distribut")->where("store_id", getAdmStoId()) ->field("distribut_num")->find(); $rh = M("store_module_endtime")->where("type",2)->where("store_id", getAdmStoId())->find(); if($rh){ return json(['code'=>-1,'msg'=>'您已经体验过了']); }else{ if($tk){ M("store_distribut")->where("store_id", getAdmStoId()) ->save(["dj_num"=>10]); }else{ M("store_distribut") ->save(["dj_num"=>10,"store_id"=>getAdmStoId()]); } $data0['store_id'] = getAdmStoId(); $data0['beg_time'] = time(); $data0['is_sy'] = 1; $data0['type'] = 2; //3是等级卡 $rh = M("store_module_endtime")->save($data0); return json(['code'=>1,'msg'=>'提交体验成功']); } } public function recharge_query(){ $back_no=I('bankOrderNo'); $rs=M("storage_recharge")->where('bankOrderNo',$back_no) ->field('recharge_state')->find(); if($rs){ if($rs['recharge_state']==1){ return json(['code'=>0,'data'=>['status'=>100]]); }else{ return json(['code'=>-1]); } }else{ return json(['code'=>-1]); } } //显示小程序的购买列表 function show_wxapp(){ $yy=M("storage_recharge")->where("store_id",getAdmStoId())->where('recharge_state',1) ->where("wxapp_price_id>0")->field('dj_price_id')->select(); $aarr = M("wxapp_price")->where(array('id'=>array('neq',1)))->order('type desc,money desc')->select(); $barr = null; if($yy) { foreach ($aarr as $k => $v) { if($v['type']==0){ if($v['money']<=0) break; else{} $barr[]=$v; }else{ if($v['type']==1) $barr[]=$v; else break; } } }else{ $barr=$aarr; } if($barr){ $this -> assign('price_arr',array_reverse($barr)); } //先判断缴费记录是否有该商家的记录 $rss=M('store_module_endtime')->where('store_id='.getAdmStoId())->where('type',5) ->where('is_sy',0)->find(); if($rss){ $end_time=strtotime('+1 year',$rss['end_time']); $end_time=date("Y-m-d H:i:s",$end_time); $this->assign('tt_end_time',$end_time); }else{ $end_time=strtotime('+1 year',time()); $end_time=date("Y-m-d H:i:s",$end_time); $this->assign('tt_end_time',$end_time); } return $this->fetch('',getAdmStoId()); } }