where("user_id", $user['user_id'])->where("store_id", $sid)->find();
session('user', $user0); //覆盖session 中的 user
$this->user = $user0;
$this->user_id = $user0['user_id'];
$this->assign('user', $user0); //存储用户信息
} else {
$usrid = Cookie::get('user_id');
if ($usrid) {
$user0 = M('users')->where("user_id", $usrid)->where("store_id", $sid)->find();
session('user', $user0); //覆盖session 中的 user
$this->user = $user0;
$this->user_id = $user0['user_id'];
$this->assign('user', $user0); //存储用户信息
}
}
$nologin = ['voiceVerify', 'login', 'pop_login', 'do_login', 'logout', 'verify', 'set_pwd', 'finished', 'is_distribut', 'verifyHandle', 'reg', 'send_sms_reg_code', 'find_pwd', 'check_validate_code', 'forget_pwd', 'check_captcha', 'check_username', 'send_validate_code', 'express', 'ajax_get_pick', 'ajax_get_category', 'get_the_Store', 'vipcard'];
if (!$this->user_id && !in_array(ACTION_NAME, $nologin)) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
if (!in_array(ACTION_NAME, $nologin)) {
if (($this->pm_erpid && (!$user || !$user['erpvipid'])) || (empty($this->pm_erpid) && !$user || !$user['mobile'])) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
} else if (ACTION_NAME != 'vipcard') //已绑定会员
{
$storeconfig = M('store_config')->where("store_id", getMobileStoId())->field('switch_list')->find();
$rank_switch = json_decode($storeconfig['switch_list'], true)['rank_switch'];
if ($rank_switch == 1 && empty($this->user['card_field']))//要求商城会员必须开通等级卡(商家开启等级卡)
{
$this->redirect(U('mobile/User/vipcard', array('stoid' => getMobileStoId())));
exit;
}
}
}
$order_status_coment = array(
'WAITPAY' => '待付款 ', //订单查询状态 待支付
'WAITSEND' => '待发货', //订单查询状态 待发货
'WAITRECEIVE' => '待收货', //订单查询状态 待收货
'WAITCCOMMENT' => '待评价', //订单查询状态 待评价
);
$this->assign('order_status_coment', $order_status_coment);
$this->assign('pstore_id', getMobileStoId());
}
/*
* 用户中心首页
*/
public function index()
{
$stoid = getMobileStoId();
//循环更新订单状态,以及库存
$odr_arr = M('order')
->where('store_id', $stoid)
->where('user_id', $this->user_id)
->where('order_amount', 0)
->where('(pay_status=0 and pt_prom_id=0) or (pt_status=0 and pt_prom_id>0)')
->where('order_status=0 or order_status=1')
->field('order_sn')->select();
foreach ($odr_arr as $k => $v) {
update_pay_status2($v['order_sn'], 1);
}
$current_money = $this->user['user_money'];
$lc_mon = $this->user['frozen_money'];
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$liudong_money = $current_money - $locking_money - $lc_mon; //流动资金
$rs0 = M('rebate_log')->where(array('user_id' => $this->user_id, 'status' => 2))->sum('money');
if ($rs0) {
$rs0 = $rs0;
} else {
$rs0 = 0.00;
}
$this->assign('liudong_money', number_format($liudong_money + $rs0, 2));
$goods_collect_count = M('return_goods')->where("user_id", $this->user_id)->count(); // 我的商品收藏
$level_name = M('user_level')->where("level_id", $this->user['level'])->getField('level_name'); // 等级名称
$fahuo = M('order')->where("user_id=" . $this->user_id . " AND (pay_status=1 OR pay_code='cod') AND shipping_status=0 AND order_status in(0,1)")->count(); //待发货
$count_return = M('return_goods')->where("user_id=$this->user_id")->count(); //售后
$wait_pay = M('order')->where("user_id=$this->user_id and pay_status =0 and order_status = 0 and pay_code != 'cod'")->count(); //我的待付款 (改)
$wait_receive = M('order')->where("user_id=$this->user_id and order_status= 1 and shipping_status= 1")->count(); //我的待收货 (改)
$pj_num = M('order')->where("user_id=$this->user_id and order_status= 2")->count(); //我的待评价 (改)
$this->assign('level_name', $level_name);
$this->assign('goods_collect_count', $goods_collect_count);
$disname = tpCache('distribut.name', $stoid);
$this->assign('disname', $disname);
$mz_switch = tpCache('shopping.is_beauty', $stoid);
if (!empty($mz_switch)) {
$this->assign('mz_vip', $this->user['is_mzvip']);
}
$switch_list = tpCache('basic.switch_list', $stoid);
//等级卡
$rank_switch = json_decode($switch_list, true)['rank_switch'];
$vipcard = 0;
$card_out = 0;
if ($rank_switch == 2)//默认商城(商家开启等级卡)
{
if (empty($this->user['card_field'])) {
$this->assign('cardvip', 1); //为1表示当前会员可购买等级卡
} else {
$vipcard = 1;
$this->assign('vipcard', 1);//当前会员是等级卡会员
if (strtotime($this->user['card_expiredate']) < time()) {
$card_out = 1;
$this->assign('card_out', 1);
}
}
}
//APP
$getylpres = getylapp_res($stoid, '2');
if ($getylpres) {
$this->assign('ylpres', $getylpres);
}
//是否有卡包
$stoid_card = M('store_wxcard')->where(array('store_id' => $stoid, 'state' => 1, 'card_id' => array('neq', '')))->find();
$this->assign('stoid_card', $stoid_card);
$this->assign('wait_pay', $wait_pay);
$this->assign('fahuo', $fahuo);
$this->assign('wait_receive', $wait_receive);
$this->assign('pj_num', $pj_num);
$this->assign('count_return', $count_return);
//$this->assign('count_sundry_status', $count_sundry_status); //各种数量
$data['storeId'] = $stoid;
//后台是否开启了初始化
$init_data = getApiData_mini("/api/weshop/users/grade/vip/init/get",$data,$stoid);
$isBool = 0;
if ($init_data) {
$init_data = json_decode($init_data, true);
if ($init_data['code'] === 0 && $init_data['data']) {
$isBool = $init_data['data']['isBool'];
$this->assign('isBool', $init_data['data']['isBool']);
}
}
//会员中心工具及服务
$usertool = M("user_tool")->order('ordid asc,id asc')->select();
$usertool_new = array();
$getdistribut_switch = tpCache('distribut.switch', $stoid);
//过滤工具要显示的条件
foreach ($usertool as $k => $v) {
//--判断分销---
if (str_is_has($v['url'], 'Distribut') && $getdistribut_switch != 1) {
continue;
}
//--判断等级卡--
if (str_is_has($v['url'], 'cardinfo') && ($vipcard != 1 || $card_out == 1)) {
continue;
}
//--收入卡包--
if (str_is_has($v['url'], 'addCard') && !$stoid_card) {
continue;
}
//我的权益
if (str_is_has($v['url'], 'gorw_up') && !$isBool) {
continue;
}
//我的权益(旧)
if (str_is_has($v['url'], 'vipqy') && $isBool) {
continue;
}
$usertool_new[] = $v;
}
$this->assign('usertool', $usertool_new);
//--工具总后台的开关---
$swith_usertool = json_decode($switch_list, true)['usertool'];
if ($swith_usertool != "null" && $swith_usertool) {
$this->assign('swith_usertool', json_decode($swith_usertool));
}
//客服
$is_chat = tpCache("basic.is_chat", $stoid);
$rs_server = M('storage_recharge_detail')->where('store_id', $stoid)->where('admin_id<>0')->where('end_time>' . time())->find();
$this->assign('is_chat', $is_chat && $rs_server);
upload_ylp_log('用户会员中心');
return $this->fetch('', $stoid);
}
public function logout()
{
upload_ylp_log('用户退出');
//session_unset();
//session_destroy();
unset($_SESSION['user']);
setcookie('cn', '', time() - 3600, '/');
setcookie('user_id', '', time() - 3600, '/');
//$this->success("退出成功",U('mobile/Index/index'));
header("Location:" . U('mobile/Index/index', array('stoid' => getMobileStoId())));
exit();
}
/*
* 账户资金
*/
public function account()
{
$tyear = date("Y-m-d", strtotime("-20 year"));
$hyear = date("Y-m-d", strtotime("20 year"));
$this->assign('tyear', $tyear);
$this->assign('hyear', $hyear);
$user = session('user');
//获取账户资金记录
//$logic = new UsersLogic();
//$data = $logic->get_account_log($this->user_id, I('get.type'));
//$account_log = $data['result'];
$this->assign('user', $user);
//$this->assign('account_log', $account_log);
//$this->assign('page', $data['show']);
//if ($_GET['is_ajax']) {
// return $this->fetch('ajax_account_list', getMobileStoId());
//exit;
//}
upload_ylp_log('账户资金页面');
return $this->fetch('', getMobileStoId());
}
/*--不可用金额--*/
public function account_unable()
{
$tyear = date("Y-m-d", strtotime("-20 year"));
$hyear = date("Y-m-d", strtotime("20 year"));
$this->assign('tyear', $tyear);
$this->assign('hyear', $hyear);
$user = session('user');
$this->assign('user', $user);
upload_ylp_log('不可用资金页面');
return $this->fetch('', getMobileStoId());
}
/**
* 登录
*/
public function login11()
{
if ($this->user_id > 0) {
//
// header("Location: " . U('mobile/User/index'));
}
$referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U("mobile/User/index/", array('stoid' => getMobileStoId()));
$this->assign('referurl', $referurl);
return $this->fetch('', getMobileStoId());
}
/**
* 登录
*/
public function do_login()
{
$username = I('post.username');
$stoid = I('post.stoid');
$username = trim($username);
$logic = new UsersLogic();
$res = $logic->login($username, $stoid);
if ($res['status'] == 1) {
$res['url'] = urldecode(I('post.referurl'));
session('user', $res['result']);
setcookie('user_id', $res['result']['user_id'], null, '/');
setcookie('is_distribut', $res['result']['is_distribut'], null, '/');
$nickname = empty($res['result']['nickname']) ? $username : $res['result']['nickname'];
setcookie('uname', $nickname, null, '/');
setcookie('cn', 0, time() - 3600, '/');
$cartLogic = new \app\home\logic\CartLogic();
$cartLogic->login_cart_handle($this->session_id, $res['result']['user_id']); //用户登录后 需要对购物车 一些操作
}
exit(json_encode($res));
}
/**
* 注册
*/
public function register()
{
return $this->fetch('', getMobileStoId());
}
/**
* 注册
*/
public function login()
{
$getstoid = getMobileStoId();
$erpid = tpCache('shop_info.ERPId', $getstoid);
$user = M('users')->alias('a')
->field('a.*')
->where('user_id', $this->user_id)->find();
if ($user) {
if (($this->pm_erpid && $user['erpvipid']) || (empty($this->pm_erpid) && $user['mobile'])) {
$this->redirect(U('mobile/User/index', array('stoid' => getMobileStoId())));
exit;
}
}
$storeconfig = M('store_config')->where('store_id', $getstoid)->field('reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
$reg_sms_enable = tpCache('sms.regis_sms_enable', $getstoid);
$reg_smtp_enable = tpCache('sms.regis_smtp_enable', $getstoid);
$s_list = $storeconfig['switch_list'];
if ($s_list) {
$s_list = json_decode($s_list, true);
$this->assign('s_list', $s_list);
}
//提交注册
$is_ajax = I('is_ajax/d');
$username = I('post.username', '');
if ($is_ajax == 1 && $username != "") {
if (!check_mobile($username)) {
return array('status' => -1, 'msg' => "请输入正确的手机号");
exit;
}
$logic = new UsersLogic();
$username = I('post.username', '');
$reg_data = array();
$reg_data['erpuuid'] = I('post.erpuuid');
mlog("2-0-0:" . json_encode($storeconfig), 'smslog/' . $getstoid);
//获取商家自定义的字段
if ($storeconfig['reg_type'] == 1) {
$reg_data['name'] = I('post.name', '');
$reg_data['birthday'] = I('post.birthday', '');
$reg_data['islunar'] = I('post.islunar', '') == '1' ? 1 : 0;
$reg_data['idcard'] = I('post.idcard', '');
$reg_data['address'] = I('post.address', '');
$reg_data['pickup_id'] = I('post.pickup_id', '');
//性别、介绍人
$reg_data['sex'] = I('post.sex', 0);
$fromuser_id = I('post.tjrname', '');
if ($fromuser_id != '') {
$rss = M('users')->where('erpvipno|mobile', $fromuser_id)
->where('store_id', getMobileStoId())->field('user_id,erpvipid')->find();
if ($rss) {
$reg_data['fromuser_id'] = $rss['user_id'];
$reg_data['IntroducerVIPID'] = $rss['erpvipid'];
} else {
return array('status' => -1, 'msg' => "介绍人必须是会员的手机号/卡号");
exit;
}
}
if (!empty($reg_data['birthday'])) {
$bird = trim($reg_data['birthday']);
$year = substr($bird, 0, 4);
$nyear = date("Y");
if (($nyear - $bird) < 10) {
return array('status' => -1, 'msg' => "会员生日不能小于10岁");
}
if (($nyear - $bird) > 70) {
return array('status' => -1, 'msg' => "会员生日不能大于70岁");
}
}
}
mlog("2-0:" . json_encode($reg_data), 'smslog/' . $getstoid);
//是否开启注册验证码机制
$code = I('post.mobile_code', '');
$session_id = session_id();
if ($getstoid != "1") {
$check_code = $logic->check_validate_code($code, $username, $session_id);
if ($check_code['status'] != 1) {
return array('status' => -1, 'msg' => $check_code['msg']);
exit;
}
}
$open_id = $_SESSION['openid'];
$data = $logic->reg($username, $getstoid, $open_id, $reg_data);
if ($data['status'] != 1) {
return array('status' => -1, 'msg' => $data['msg']);
exit;
}
session('user', $data['result']);
setcookie('user_id', $data['result']['user_id'], null, '/');
setcookie('is_distribut', $data['result']['is_distribut'], null, '/');
//season 删除验证码
M('sms_log')->where(array('mobile' => $username, 'store_id' => $getstoid, 'status' => 1))->delete();
$cartLogic = new \app\home\logic\CartLogic();
$cartLogic->login_cart_handle($this->session_id, $data['result']['user_id']); //用户登录后 需要对购物车 一些操作
return array('status' => 1, 'msg' => $data['msg']);
exit;
}
$user_openid = $user['openid'];
$this->assign("user_openid", $user_openid);
$user_openidkey = md5($user_openid . "&" . getErpKey());
$this->assign("user_openid", $user_openid);
$this->assign("user_openidkey", $user_openidkey);
$getylpres = getylapp_res(getMobileStoId(), '2');
if ($getylpres && $erpid != "ppt") {
$this->redirect($getylpres['downLoadUrl']);
exit;
}
//后台是否开启了初始化
$gdata['storeId'] = $getstoid;
$init_data = getApiData_mini("/api/weshop/users/grade/vip/init/get",$gdata,$getstoid);
$isBool = 0;
if ($init_data) {
$init_data = json_decode($init_data, true);
if ($init_data['code'] === 0 && $init_data['data']) {
try{
$isBool = $init_data['data']['isBool'];
$this->assign('isBool', $init_data['data']['isBool']);
}catch (\Exception $ex){}
}
}
//门店分类
$storetype = M('storage_category')->where(array('store_id' => $getstoid, 'is_show' => 1))->order('sort asc')->select();
$this->assign('storetype', $storetype);
//查询二维码来源
$wxopen = M('wx_openlist')->where(array('store_id' => $getstoid, 'wxopenid' => $this->user['openid']))->find();
if ($wxopen) {
if ($wxopen['staffno']) {
$pickupinfo = M('pick_up')->where(array('store_id' => $getstoid, 'pickup_no' => $wxopen['staffno'], 'isstop' => 0))->find();
if ($pickupinfo) {
$this->assign('pickupinfo', $pickupinfo); //关注标识码
}
}
}
if ($storeconfig['reg_type'] == 1) {
} else {
$this->assign('storejs', "-1"); //选取门店
}
$sms_time_out = tpCache('sms.sms_time_out', $getstoid) > 0 ? tpCache('sms.sms_time_out', $getstoid) : 120;
$this->assign('sms_time_out', $sms_time_out); // 手机短信超时时间
$sms_send_type = json_decode($storeconfig['sms_send_type'], true);
$this->assign('s_type', $sms_send_type['type'] ? $sms_send_type['type'] : 0);
$this->assign('s_time_out', $sms_send_type['time_out'] ? $sms_send_type['time_out'] : 60);
$this->assign('is_verifycode', $sms_send_type['is_verifycode'] ? $sms_send_type['is_verifycode'] : 0);
//判断商家是否自定义注册信息
if ($storeconfig['reg_type'] == 1) {
$reg_info = json_decode($storeconfig['reg_info'], true);
$config['name'] = $reg_info['name'];
$config['name_state'] = $reg_info['name_state'];
$config['name_val_type'] = $reg_info['name_val_type'];
$config['birthday'] = $reg_info['birthday'];
$config['birthday_state'] = $reg_info['birthday_state'];
$config['birthday_type'] = $reg_info['birthday_type'];
$config['idcard'] = $reg_info['idcard'];
$config['idcard_state'] = $reg_info['idcard_state'];
$config['idcard_type'] = $reg_info['idcard_type'];
$config['address'] = $reg_info['address'];
$config['address_state'] = $reg_info['address_state'];
$config['address_type'] = $reg_info['address_type'];
$config['pick'] = $reg_info['pick'];
$config['pick_state'] = $reg_info['pick_state'];
$config['pick_type'] = $reg_info['pick_type'];
$config['sex'] = $reg_info['sex'];
$config['sex_state'] = $reg_info['sex_state'];
$config['sex_state_type'] = $reg_info['sex_state_type'];
$config['introducer'] = $reg_info['introducer'];
$config['introducer_state'] = $reg_info['introducer_state'];
$config['introducer_type'] = $reg_info['introducer_type'];
if ($reg_info['reginfo_coupon']) {
$coupon = M("coupon")->where("id", $reg_info['reginfo_coupon'])->find();
$mhtm = "注册成功即可获得一张" . $coupon['money'] . "元优惠券";
}
$this->assign('mhtm', $mhtm);
$this->assign('reg', $config);
} else {
$def = $storeconfig['reg_default'];
$ddef = json_decode($def, true);
$ty = $ddef['reg_def_ty'];
if ($ty == 1) {
$qno = $ddef['coupon'];
$coupon = M("coupon")->where("id", $qno)->find();
$mhtm = "注册成功即可获得一张" . $coupon['money'] . "元优惠券";
}
if ($ty == 2) {
if ($ddef['reg_cz']) {
$mhtm = "注册成功即可获得" . $ddef['reg_cz'] . "成长值";
}
}
else {
if ($ddef['jf']) {
$mhtm = "注册成功即可获得" . $ddef['jf'] . "积分";
}
}
$this->assign('mhtm', $mhtm);
}
//选择门店新版
$is_newchoosestore = json_decode($storeconfig['switch_list'], true)['is_newchoosestore'];
if (empty($is_newchoosestore)) {
$is_newchoosestore = 0;
}
$this->assign('is_newchoosestore', $is_newchoosestore);
//等级卡项目
$rank_switch = json_decode($storeconfig['switch_list'], true)['rank_switch'];
$this->assign('rank_switch', $rank_switch);
//生日
$is_brithday = json_decode($storeconfig['switch_list'], true)['is_brithday'];
$this->assign('is_brithday', $is_brithday);
$this->assign('erpuuid', uuid());
$this->assign('user_info', $user);
return $this->fetch('', getMobileStoId());
}
/*
* 订单列表
*/
public function order_list()
{
//循环更新订单状态,以及库存
$odr_arr = M('order')
->where('store_id', getMobileStoId())
->where('user_id', $this->user_id)
->where('order_amount', 0)
->where('(pay_status=0 and pt_prom_id=0) or (pt_status=0 and pt_prom_id>0)')
->where('order_status=0 or order_status=1')
->field('order_sn')->select();
foreach ($odr_arr as $k => $v) {
mlog("order_list:".$v['order_sn'],"update_pay_status2/".getMobileStoId());
update_pay_status2($v['order_sn'], 1);
}
$where = ' user_id=' . $this->user_id;
/*---条件搜索
if (in_array(strtoupper(I('type')), array('WAITCCOMMENT', 'COMMENTED'))) {
$where .= " AND order_status in(1,4) "; //代评价 和 已评价
}---*/
$type = I('type');
if (!empty($type))
$where .= C(strtoupper($type));
//自动评价
//$this->autopj();
$keyword = urldecode(trim(I('key', ''))); // 关键字搜索
if (!empty($keyword)) {
// $sql='select distinct order_id from __PREFIX__order_goods WHERE goods_sn like "%'.$keyword.'%" or goods_name like "%'.$keyword.'%" or order_sn like "%'.$keyword.'%"';
$order_goods = M('order_goods')->where('goods_sn like "%' . $keyword . '%" or goods_name like "%' . $keyword . '%" or order_sn like "%' . $keyword . '%"')->distinct(true)->getfield('order_id', true);
// $order_goods=DB::query($sql);
// foreach ($order_goods as $v){
// $list[]=$v['order_id'];
// }
$count = M('order')->where($where)->where('order_id', 'in', implode(',', $order_goods))->where('isdel=0')->count();
$Page = new Page($count, 10);
$order_list = M('order')->order('order_id DESC')->where($where)->where('order_id', 'in', implode(',', $order_goods))
->where('isdel=0')->limit($Page->firstRow . ',' . $Page->listRows)->select();
} else {
$count = M('order')->where($where)->where('isdel=0')->count();
$Page = new Page($count, 10);
$order_list = M('order')->order('order_id DESC')->where($where)
->where('isdel=0')->limit($Page->firstRow . ',' . $Page->listRows)->select();
}
//dump($order_list); exit;
//获取订单商品
$model = new UsersLogic();
foreach ($order_list as $k => $v) {
$order_list[$k] = set_btn_order_status($v); // 添加属性 包括按钮显示属性 和 订单状态显示属性
//$order_list[$k]['total_fee'] = $v['goods_amount'] + $v['shipping_fee'] - $v['integral_money'] -$v['bonus'] - $v['discount']; //订单总额
if ($type)
$data = $model->get_order_goods($v['order_id']);
else
$data = $model->get_order_goods1($v['order_id'], $v);
$order_list[$k]['goods_list'] = $data['result'];
$rf_num = M('return_goods')->where('order_id', $v['order_id'])->count();
$order_list[$k]['rf_num'] = $rf_num;
}
//统计订单商品数量
foreach ($order_list as $key => $value) {
$count_goods_num = '';
foreach ($value['goods_list'] as $kk => $vv) {
$count_goods_num += $vv['goods_num'];
if (($vv['prom_type'] == 3 && $value['discount_amount'] > 0)
|| ($vv['prom_type'] == 3 && $vv['goods_price'] <= 0)
) {
$order_list[$key]['is_prom'] = 1;
}
if ($vv['prom_type'] == 5) {
$order_list[$key]['is_prom'] = 1;
}
}
$order_list[$key]['count_goods_num'] = $count_goods_num;
}
$this->assign('order_status', C('ORDER_STATUS'));
$this->assign('shipping_status', C('SHIPPING_STATUS'));
$this->assign('pay_status', C('PAY_STATUS'));
//$this->assign('page', $show);
$this->assign('lists', $order_list);
$this->assign('active', 'order_list');
$this->assign('active_status', I('get.type'));
if ($_GET['is_ajax']) {
return $this->fetch('ajax_order_list', getMobileStoId());
exit;
}
$p = I("p/d", 1);
if ($count <= $p * 10) {
$this->assign('mshow', 0);
} else {
$this->assign('mshow', 1);
}
upload_ylp_log('订单列表');
return $this->fetch('', getMobileStoId());
}
//自动评价
public function autopj()
{
$getstoid = getMobileStoId();
$is_autopj = 0;
$tp_config = tpCache('shopping', getMobileStoId());
$is_autopj = $tp_config['is_autopj'];
//是否开启自动评价
if ($is_autopj == 1) {
$auto_pjday = $tp_config['auto_pjday'];
$auto_pjremark = $tp_config['auto_pjremark'];
$logic = new UsersLogic();
//几天前
$et = strtotime('-' . $auto_pjday . ' day');
$sql = "select a.store_id,a.order_id,a.is_comment,a.goods_id,b.confirm_time,b.user_id,b.consignee from wxd_order_goods a left join wxd_order b on a.order_id=b.order_id where a.store_id=" . $getstoid . " and a.is_comment=0 and b.order_status=2 and b.confirm_time>0 and b.shipping_status=1 and b.confirm_time<" . $et;
$auto_order = DB::query($sql);
foreach ($auto_order as $key => $value) {
$add['goods_id'] = $value['goods_id'];
if ($value['consignee']) {
$add['username'] = $value['consignee'];
} else {
$add['username'] = $value['mobile'];
}
$add['content'] = $auto_pjremark;
$add['deliver_rank'] = 5;
$add['add_time'] = time();
$add['ip_address'] = getIP();
$add['is_show'] = 1;
$add['user_id'] = $value['user_id'];
$add['order_id'] = $value['order_id'];
$add['goods_rank'] = 5;
$add['service_rank'] = 5;
$add['isauto'] = 1;
$add['store_id'] = $getstoid;
//添加评论
$row = $logic->add_comment($add);
}
}
}
/*
* 订单列表
*/
public function ajax_order_list()
{
}
/*
* 订单详情
*/
public function order_detail()
{
$id = I('get.id/d');
$map['order_id'] = $id;
$map['user_id'] = $this->user_id;
$order_info = M('order')->where($map)->find();
if ($order_info['order_amount'] <= 0 && in_array($order_info['order_status'],[0,1])) {
if ($order_info['is_zsorder'] == 0 && $order_info['pay_status'] == 0) {
update_pay_status2($order_info['order_sn'], 1);
$order_info = M('order')->where($map)->find();
}
if ($order_info['is_zsorder'] > 1 && $order_info['pt_status'] == 0) {
update_pay_status2($order_info['order_sn'], 1);
$order_info = M('order')->where($map)->find();
}
}
//如果是包邮券的话
if ($order_info['coupon_no'] && $order_info['coupon_price'] <= 0) {
//拿出包邮券
$wh['a.user_id'] = $this->user_id;;
$wh['a.store_id'] = getMobileStoId();
$wh['a.no'] = $order_info['coupon_no'];
$bylist = M("user_feemail")->alias('a')->join('coupon b', 'a.fmid=b.id')
->where($wh)
->field("a.no,b.condition,b.use_start_time,b.use_end_time")
->find();
$this->assign('bylist', $bylist);
}
$order_info = set_btn_order_status($order_info); // 添加属性 包括按钮显示属性 和 订单状态显示属性
if (!$order_info) {
$this->error('没有获取到订单信息');
exit;
}
$rf_num = M('return_goods')->where('order_id', $id)->count();
$order_info['rf_num'] = $rf_num;
$r = M('pick_up')->where('pickup_id', $order_info['pickup_id'])->find();
if ($r) {
$this->assign('pname', $r['pickup_name']);
$this->assign('paddr', $r['pickup_address']);
}
//获取订单商品
$model = new UsersLogic();
$ord_g = M("order_goods")->where('order_id', $id)->count();
/*---当一单里面有多个商品的时候---*/
if ($ord_g > 1) {
$data = $model->get_order_goods($order_info['order_id']);
} else {
$data = $model->get_order_goods1($order_info['order_id']);
}
//$data = $model->get_order_goods($order_info['order_id']);
$order_info['goods_list'] = $data['result'];
foreach ($order_info['goods_list'] as $val) {
if (($val['prom_type'] == 3 && $order_info['discount_amount'] > 0)
|| ($val['prom_type'] == 3 && $val['goods_price'] <= 0)
) {
$order_info['is_prom'] = 1;
}
if ($val['prom_type'] == 5) {
$order_info['is_prom'] = 1;
}
}
//$order_info['total_fee'] = $order_info['goods_price'] + $order_info['shipping_price'] - $order_info['integral_money'] -$order_info['coupon_price'] - $order_info['discount'];
//$order_info['order_prom_amount'] += $order_info['discount_amount'];//再加上优惠促销的
$region_list = get_region_list();
$invoice_no = M('DeliveryDoc')->where("order_id", $id)->getField('invoice_no', true);
$order_info['invoice_no'] = implode(' , ', $invoice_no);
if ($order_info['is_zsorder'] == 4) {
$order_info['goods_price'] = 0;
foreach ($order_info['goods_list'] as $k => $v) {
$order_info['goods_price'] += $v['member_goods_price'] * $v['goods_num'];
}
}
$order_info['user_money0'] = $order_info['user_money'];
if ($order_info['pt_status'] == 4 || $order_info['pt_status'] == 5) {
if ($order_info['tail_pay_type'] == 1) {
$order_info['user_money0'] = $order_info['user_money'] + $order_info['pt_tail_money'];
}
}
$order_info['order_amount0'] = $order_info['order_amount'];
if ($order_info['pt_status'] == 4 || $order_info['pt_status'] == 5) {
if ($order_info['tail_pay_type'] == 0) {
$order_info['order_amount0'] = $order_info['order_amount'] + $order_info['pt_tail_money'];
}
}
if (empty($order_info['order_status_desc']) || $order_info['order_status_desc'] == '已取消') {
switch ($order_info['pt_status']) {
case "1":
$order_info['order_status_desc'] = "待成团";
break;
case "2":
if ($order_info['is_zsorder'] == 4)
$order_info['order_status_desc'] = "待付尾款";
else
$order_info['order_status_desc'] = "已成团";
break;
case "3":
$order_info['order_status_desc'] = "拼团失败";
break;
case "4":
$order_info['order_status_desc'] = "已支付尾款";
break;
case "5":
$order_info['order_status_desc'] = "所有尾款完成";
break;
}
}
//获取订单操作记录
$order_action = M('order_action')->where(array('order_id' => $id))->select();
$this->assign('order_status', C('ORDER_STATUS'));
$this->assign('shipping_status', C('SHIPPING_STATUS'));
$this->assign('pay_status', C('PAY_STATUS'));
$this->assign('region_list', $region_list);
$this->assign('order_info', $order_info);
$this->assign('order_action', $order_action);
if (I('waitreceive')) { //待收货详情
return $this->fetch('wait_receive_detail', getMobileStoId());
}
upload_ylp_log('订单详情');
return $this->fetch('', getMobileStoId());
}
public function express()
{
$order_id = I('get.order_id/d');
$order_goods = M('order_goods')->where("order_id", $order_id)->select();
$delivery = M('delivery_doc')->where("order_id", $order_id)->find();
if ($delivery) {
$exp = M("shipping")->where("shipping_code", $delivery["shipping_code"])->find();
$expimg = $exp['shipping_logo'];
$this->assign('expimg', $expimg);
}
$this->assign('order_goods', $order_goods);
$this->assign('delivery', $delivery);
return $this->fetch('', getMobileStoId());
}
/*
* 取消订单
*/
public function cancel_order()
{
upload_ylp_log('取消订单');
$id = I('get.id/d');
//检查是否有积分,余额支付
$logic = new UsersLogic();
$data = $logic->cancel_order($this->user_id, $id);
if ($data['status'] < 0)
$this->error($data['msg']);
$this->success($data['msg']);
}
/*
* 用户地址列表
*/
public function address_list()
{
$address_lists = get_user_address_list($this->user_id);
$region_list = get_region_list();
$this->assign('region_list', $region_list);
$this->assign('lists', $address_lists);
upload_ylp_log('用户地址');
return $this->fetch('', getMobileStoId());
}
/*
* 添加地址
*/
public function add_address()
{
upload_ylp_log('添加地址');
if (IS_POST) {
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, I('post.'));
if ($data['status'] != 1)
$this->error($data['msg']);
$this->success($data['msg'], U('/mobile/User/address_list', array('stoid' => I('get.stoid'))));
exit();
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
return $this->fetch('', getMobileStoId());
}
/*
* 地址编辑
*/
public function edit_address()
{
upload_ylp_log('编辑地址');
$id = I('id/d');
$address = M('user_address')->where(array('address_id' => $id, 'user_id' => $this->user_id))->find();
if (IS_POST) {
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, $id, I('post.'));
$this->success($data['msg'], U('/mobile/User/address_list', array('stoid' => I('get.stoid'))));
exit();
}
//获取省份
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$c = M('region')->where(array('parent_id' => $address['province'], 'level' => 2))->select();
$d = M('region')->where(array('parent_id' => $address['city'], 'level' => 3))->select();
$data['province'] = $p;
$data['city'] = $c;
$data['district'] = $d;
if (empty($data['district'])) {
$e = M('region')->where(array('parent_id' => $address['city'], 'level' => 4))->select();
$data['twon'] = $e;
} else {
$e = M('region')->where(array('parent_id' => $address['district'], 'level' => 4))->select();
$data['twon'] = $e;
}
$region_list = get_region_list();
$areaname = $region_list[$address['province']]['name'] . "-" . $region_list[$address['city']]['name'];
if (!empty($address['district']))
$areaname .= "-" . $region_list[$address['district']]['name'];
if (!empty($address['twon']))
$areaname = $areaname . "-" . $region_list[$address['twon']]['name'];
$address['addname'] = $areaname;
$this->assign('areaname', $areaname);
$this->assign('province', $p);
$this->assign('city', $c);
$this->assign('district', $d);
$this->assign('address', $address);
$this->assign('jdata', json_encode(['data' => $data, 'data2' => $address]));
return $this->fetch('', getMobileStoId());
}
/*
* 设置默认收货地址
*/
public function set_default()
{
$id = I('get.id');
//$source = I('get.source');
M('user_address')->where(array('user_id' => $this->user_id))->save(array('is_default' => 0));
$row = M('user_address')->where(array('user_id' => $this->user_id, 'address_id' => $id))->save(array('is_default' => 1));
if ($row) {
return json(['code' => 0, 'msg' => '设置默认地址成功']);
} else {
return json(['code' => -1, 'msg' => '设置默认地址失败']);
}
}
/*
* 地址删除
*/
public function del_address()
{
upload_ylp_log('删除地址');
$id = I('get.id');
$address = M('user_address')->where("address_id", $id)->find();
$row = M('user_address')->where(array('user_id' => $this->user_id, 'address_id' => $id))->delete();
// 如果删除的是默认收货地址 则要把第一个地址设置为默认收货地址
if ($address['is_default'] == 1) {
$address2 = M('user_address')->where("user_id", $this->user_id)->find();
$address2 && M('user_address')->where("address_id", $address2['address_id'])->save(array('is_default' => 1));
}
if (!$row)
$this->error('操作失败', U('User/address_list', array('stoid' => I('get.stoid'))));
else
$this->success("操作成功", U('User/address_list', array('stoid' => I('get.stoid'))));
}
/*
* 地址删除
*/
public function deladdress()
{
upload_ylp_log('删除地址');
$id = I('get.id');
$address = M('user_address')->where("address_id", $id)->find();
$row = M('user_address')->where(array('user_id' => $this->user_id, 'address_id' => $id))->delete();
// 如果删除的是默认收货地址 则要把第一个地址设置为默认收货地址
if ($address['is_default'] == 1) {
$address2 = M('user_address')->where("user_id", $this->user_id)->find();
$address2 && M('user_address')->where("address_id", $address2['address_id'])->save(array('is_default' => 1));
}
if (!$row)
return json(['code' => -1]);
else
return json(['code' => 1]);
}
/*--ajax返回--*/
public function ajaxaddressreturn()
{
$address_lists = get_user_address_list($this->user_id);
$region_list = get_region_list();
$this->assign('region_list', $region_list);
$this->assign('lists', $address_lists);
return $this->fetch('', getMobileStoId());
}
/*
* 评论晒单
*/
public function comment()
{
upload_ylp_log('评论晒单');
$user_id = $this->user_id;
$status = I('get.status');
$order_sn = I('order_sn');
$logic = new UsersLogic();
$result = $logic->get_comment($user_id, $status,$order_sn); //获取评论列表
$comlist = $result['result'];
if ($comlist) {
foreach ($comlist as $k => $v) {
//获取回复
$rep = M('comment')->where('parent_id', $v['comment_id'])->select();
if ($rep) {
$comlist[$k]['rep'] = $rep;
}
$gd = M('goods')->where('goods_id', $v['goods_id'])->find();
$comlist[$k]['original_img'] = $gd['original_img'];
}
}
$this->assign('comment_list', $comlist);
$this->assign("isshow", $result['isshow']);
if ($_GET['is_ajax']) {
return $this->fetch('ajax_comment_list', getMobileStoId());
exit;
}
return $this->fetch('', getMobileStoId());
}
/*
*查看评价
*/
public function view_comment()
{
$rec_id = I('rec_id');
$order_goods = M('order_goods')->where("rec_id", $rec_id)->find();
$goods = M('goods')->where('goods_id', $order_goods['goods_id'])->find();
//评论表
$comment = M("comment")
->where("order_id", $order_goods['order_id'])
->where("goods_id", $order_goods['goods_id'])
->where("user_id", $this->user_id)->find();
$source_type = $comment['source_type'];//来源:0=微信公众号 1=微信小程序
$comment['weapp_img'] = json_decode($comment['weapp_img'], true);//小程序json格式转换成数组
$comment['img'] = unserialize($comment['img']);//微信公众号:序列化转换成数组
//评价有礼活动接口调用
$data['orderGoodsId'] = $order_goods['goods_id'];//商品id
$data['orderNumber'] = $order_goods['order_id'];//商品订单号
$data['orderType'] =1;//评价类型 1=商城订单评价 2=美容师评价
$data['storeId'] = $order_goods['store_id'];//商家id
$data['userId'] = $this->user_id;;//用户id
$is_ceremony = getApiData_mini("/api/weshop/marketing/comment/act/judge", $data, getMobileStoId, 'GET');
if($is_ceremony){
$is_ceremony = json_decode($is_ceremony, true);
if($is_ceremony && $is_ceremony['code']==0 && $is_ceremony['data']){
$this->assign('is_ceremony', 1);
$this->assign('ceremony', $is_ceremony['data']);
}
}
//返回参数
$this->assign('order_goods', $order_goods);
$this->assign('goods', $goods);
$this->assign('comment', $comment);
$this->assign('user_id', $this->user_id);
return $this->fetch('', getMobileStoId());
}
/*
*添加评论
*/
public function add_comment()
{
upload_ylp_log('添加评论');
$isajax = I('isajax');
if ($isajax) {
$user_info = session('user');
$logic = new UsersLogic();
$add['goods_id'] = I('goods_id');
$add['email'] = $user_info['email'];
$hide_username = I('hide_username');
if (empty($hide_username)) {
$add['username'] = $user_info['nickname'];
}
$add['content'] = I('content');
$add['deliver_rank'] = I('deliver_rank');
$add['add_time'] = time();
$add['ip_address'] = getIP();
$add['is_show'] = 1;
$add['user_id'] = $this->user_id;
$add['order_id'] = I('order_id');
$add['goods_rank'] = I('goods_rank');
$add['service_rank'] = I('service_rank');
$add['store_id'] = getMobileStoId();
//添加评论
$row = $logic->add_comment($add);
if ($row['status'] == 1) {
return array('status' => 1, 'msg' => '评论成功', 'data' => $row);
//$this->success('评论成功', U('/mobile/Goods/goodsInfo', array('id' => $add['goods_id'], 'stoid' => getMobileStoId())));
exit();
} else {
return array('status' => -1, 'msg' => '评论失败', 'result' => '');
//$this->error($row['msg']);
exit();
}
}
$rec_id = I('rec_id');
$order_goods = M('order_goods')->where("rec_id", $rec_id)->find();
if($order_goods['prom_type']==4){
$ord=M("order")->where('order_id',$order_goods['order_id'])->find();
$order_goods['integral']=$ord['integral'];
}
$goods = M('goods')->where('goods_id', $order_goods['goods_id'])->find();
$this->assign('order_goods', $order_goods);
$this->assign('goods', $goods);
return $this->fetch('', getMobileStoId());
}
/*
* 个人信息
*/
public function userinfo()
{
upload_ylp_log('个人信息');
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->join('pick_up p', 'p.pickup_id=a.pickup_id', 'left')
->field('a.*,b.api_token,p.pickup_name')
->where("a.user_id", $this->user_id)->find();
$storeconfig = M('store_config')->where('store_id', getMobileStoId())->field('cardimg,reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
if ($storeconfig['reg_type'] == 1) {
$reg_info = json_decode($storeconfig['reg_info'], true);
$this->assign('reg_info', $reg_info);
}
if (IS_POST) {
I('post.nickname') ? $post['nickname'] = I('post.nickname') : false; //昵称
I('post.sex') ? $post['sex'] = I('post.sex') : $post['sex'] = 0; // 性别
I('post.birthday') ? $post['birthday'] = strtotime(I('post.birthday')) : false; // 生日
I('post.islunar') ? $post['islunar'] = I('post.islunar') : false; // 新农历
I('post.pickup_id') ? $post['pickup_id'] = I('post.pickup_id') : false; //门店ID
I('post.idcard') ? $post['idcard'] = I('post.idcard/s') : false; //身份证
I('post.vipname') ? $post['vipname'] = I('post.vipname') : false; //姓名
I('post.address') ? $post['address'] = I('post.address') : false; //地址
$jifen = 0;$czz=0;
if ($storeconfig['reg_type'] == 1) {
$reg_info = json_decode($storeconfig['reg_info'], true);
//姓名
if ($reg_info['name_state'] == 1 && I('post.vipname') && empty($user_info['vipname'])) {
if($reg_info['name_val_type']){
$czz+=$reg_info['name'];
}else {
$jifen += $reg_info['name'];
}
}
//生日
if ($reg_info['birthday_state'] == 1 && I('post.birthday') && empty($user_info['birthday'])) {
if($reg_info['birthday_type']){
$czz+=$reg_info['birthday'];
}else {
$jifen += $reg_info['birthday'];
}
}
//身份证ID卡
if ($reg_info['idcard_state'] == 1 && I('post.idcard') && empty($user_info['idcard'])) {
if($reg_info['idcard_type']){
$czz+=$reg_info['idcard'];
}else {
$jifen += $reg_info['idcard'];
}
}
//地址
if ($reg_info['address_state'] == 1 && I('post.address') && empty($user_info['address'])) {
if($reg_info['address_type']){
$czz+=$reg_info['address'];
}else {
$jifen += $reg_info['address'];
}
}
//门店
if ($reg_info['pick_state'] == 1 && I('post.pickup_id') && empty($user_info['pickup_id'])) {
if($reg_info['pick_type']){
$czz+=$reg_info['pick'];
}else {
$jifen += $reg_info['pick'];
}
}
//性别
if ($reg_info['sex_state'] == 1 && I('post.sex') && empty($user_info['sex'])) {
if($reg_info['sex_state_type']){
$czz+=$reg_info['sex'];
}else {
$jifen += $reg_info['sex'];
}
}
}
//调用线下接口,更新会员信息
$pickup_id = I('pickup_id');
$pick = M("pick_up")->where("pickup_id", $pickup_id)
->where('store_id', getMobileStoId())->find();//获取线上门店信息
//有账套
if ($this->pm_erpid) {
if (empty($user_info['erpvipid'])) {
$this->error("会员信息错误");
}
$id = $user_info['erpvipid'];
$id = $id;
$where['Id'] = array('=', $id);
$store = I('stoid');
$data = array(
'Id' => $id,
'VIPNo' => $user_info['erpvipno'],
'Editer' => '微系统自助修改',
'IsLunar' => I('post.islunar') == 1 ? 1 : 0,
);
//完善信息,判断是否有值
if ($post['sex']) $data['Sex'] = $post['sex'] == 1 ? '男' : '女';
if ($post['birthday']) $data['BirthDate'] = I('post.birthday');
if (I('post.vipname')) $data['VIPName'] = I('post.vipname');
if (I('post.idcard/s')) $data['IDCard'] = I('post.idcard/s');
if (I('post.address')) $data['Address'] = I('post.address');
if ($pick['keyid']) $data['StoragesId'] = $pick['keyid'];
if (I('vipnopwd')) {
$data['VIPPass'] = I('vippass');
$data['PassValidate'] = 1;
} else {
$data['PassValidate'] = 0;
$data['VIPPass'] = substr($user_info['mobile'], -6);
}
mlog("提交值:" . json_encode($data), "userinfo/" . getMobileStoId());
$aa = getApiData("wxd.vip.vipinfo.edit", $user_info['api_token'], array($data));
$rs = [$aa, 1];
if (!$rs[0]) {
$this->error("服务器繁忙, 请联系管理员!");
}
$qlist = json_decode(urldecode($rs[0]), true);
if (($qlist['code']) == "-1") {
$this->error($qlist['msg']);
}
}
//
if ($jifen > 0) {
//有账套
if ($this->pm_erpid) {
/*----
$data = array(
'Id' => $user_info["erpvipid"],//会员id
'Integral' => $jifen,//积分
'Remark' => '完善信息送积分',
);
$add_rs = getApiData("wxd.vip.addreduce", $user_info['api_token'], array($data));
$msg = $add_rs;
$add_rs = json_decode($add_rs, true);
if ($add_rs['code'] != 1) {
mlog($msg, 'userinfo/' . $user_info['user_id']);
}--*/
$add_rs= com_update_integral($this->pm_erpid,$user_info,$jifen,"完善信息送积分",$module="mobile/user");
if (!$add_rs) {
mlog("完善送积分失败", 'userinfo/' . $user_info['user_id']);
}
} else {
accountLog($user_info["user_id"], 0, $jifen, '完善信息送积分', 0, getMobileStoId(), $user_info["pay_points"]);//线上表
}
}
$userLogic = new UsersLogic();
if ($czz > 0){
if ($this->pm_erpid) {
$userLogic->send_czz($user_info['erpvipid'], $czz, $this->pm_erpid, "完善信息送成长值");
}
}
if (!$userLogic->update_info($this->user_id, $post))
$this->error("保存失败");
$this->success("操作成功");
exit;
}
if ($user_info) {
$stoid = getMobileStoId();
$rank_switch = json_decode($storeconfig['switch_list'], true)['rank_switch'];
//有账套
if ($this->pm_erpid) {
//----有账套才来读取卡的内容----
$card_field = $user_info['card_field'];
if ($card_field) {
//----读取等级卡标签---
$all_card = get_plus_price_arr($stoid);
if ($all_card) {
//--读取卡的分类---
$new_card_dd = null;
foreach ($all_card as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
$s_card_label = $card_label = $new_card_dd[$card_field];
$len = mb_strlen($card_label, "utf-8");
if ($len > 6)
$card_label = mb_substr($s_card_label, 0, 6, "utf-8");
$this->assign('card_label', $card_label);
}
}
$mapuser['VIPId'] =urlencode($user_info['erpvipid']);
$user_rs = getApiData_java_p("/api/erp/vip/info/page", $this->pm_erpid, $mapuser, 1, 10, null, "GET");
mlog("读线下信息:" . $user_rs, "userinfo/" . getMobileStoId());
$user_rs = json_decode($user_rs, true);
//调用接口错误,提示错误信息
if ($user_rs) {
if ($user_rs["code"] == 0) {
if ($user_rs['data']['pageData']) {
$new_user_info = $user_rs['data']['pageData'][0];
if ($new_user_info) {
$updateuser['erpvipno'] = $new_user_info['VIPNo'];
}
//地址、生日、身份证、地址、所属门店
if ($new_user_info['Sex'] == '男')
$updateuser['sex'] = 1;
else if ($new_user_info['Sex'] == '女')
$updateuser['sex'] = 2;
else $updateuser['sex'] = 0;
$updateuser['birthday'] = strtotime($new_user_info['BirthDate']);
$updateuser['islunar'] = $new_user_info['islunar'];
$updateuser['idcard'] = $new_user_info['IDCard'];
$updateuser['address'] = $new_user_info['Address'];
$updateuser['mobile'] = $new_user_info['MobileTel'];
if ($new_user_info['VIPName'] != $user_info['mobile'] && $new_user_info['VIPName'] && $new_user_info['VIPName'] != $user_info['vipname']) {
$updateuser['vipname'] = $new_user_info['VIPName'];
}
if ($new_user_info['StoragesId']) {
$pick = M("pick_up")->where("keyid", $new_user_info['StoragesId'])->where('store_id', getMobileStoId())->find();
if ($pick) {
$updateuser['pickup_id'] = $pick['pickup_id'];
}
}
if ($rank_switch==2 && empty($user_info['card_field']) && $new_user_info['GradeCardID']) {
$Cardwhere['CardId'] = $new_user_info['GradeCardID'];
if($Cardwhere['CardId']) {
$rs_cardset = getApiData_java_p("/api/erp/vip/mem/bership/get", $this->pm_erpid, $Cardwhere, 1, 10, null, "GET");
if ($rs_cardset && $rs_cardset['code']===0) {
$rs_cardset = json_decode($rs_cardset, true);
$rs_cardset_data = $rs_cardset['data'];
$getcard_field = "cardprice1";
switch ($rs_cardset_data['CorrPrice']) {
case "Price1":
$getcard_field = "cardprice1";
break;
case "Price2":
$getcard_field = "cardprice1";
break;
case "Price3":
$getcard_field = "cardprice1";
break;
}
$updateuser['card_expiredate'] = $new_user_info['ExpiryDate'];
$updateuser['card_field'] = $getcard_field;
}
}
}
$falg = M('users')->where('user_id', $user_info['user_id'])->save($updateuser);
if ($falg) {
//重新赋值
$user_info['erpvipno'] = $new_user_info['VIPNo'];
$user_info['sex'] = $new_user_info['Sex'] == '男' ? 1 : $new_user_info['Sex'] == '女' ? 2 : 0;
$user_info['birthday'] = strtotime($new_user_info['BirthDate']);
$user_info['address'] = $new_user_info['Address'];
$user_info['idcard'] = $new_user_info['IDCard'];
}
// 暂时不用
// if ($user_info['card_field'] <> '' && $rank_switch == 2) {
// /*--判断是否等级卡--*/
// $where['VIPId'] = $user_info['erpvipid'];
// $cardinfo = getApiData("wxd.mem.vipinfo.list.get", $user_info['api_token'], null, $where);
//
// $cardinfo = json_decode($cardinfo, true);
// if ($cardinfo['code'] != 1 || $cardinfo['data'][0]['GradeCardID'] == '') {
// $cardinfo = '';
// } else {
// $cardinfo = $cardinfo['data'][0];
// $expiredate = $cardinfo['ExpiryDate'];
// $expireday = $cardinfo['YExpiryDate'];
// $cardinfo['newexpiredate'] = date("Y-m-d", strtotime("$expiredate +$expireday day"));
//
// if (empty($cardinfo['cardfee']))
// $cardinfo['cardfee'] = "0.00";
// $cardinfo['cardfee'] = number_format($cardinfo['cardfee'], 2, '.', '');
//
// $key = md5($cardinfo['GradeCardID'] . $cardinfo['cardfee'] . getErpKey());
// $cardinfo['keys'] = $key;
// }
// }
if ($rank_switch == 2)//商家开通等级卡
{
$cardimg = $storeconfig['cardimg'];
if ($cardimg) {
$cardimg = getImg($cardimg, '/public/images/default_goods_image_240.gif');
} else {
$cardimg = "/template/mobile/new/static/images/user/nonecard.jpg";
}
}
//消费密码
if ($new_user_info['PassValidate']) {
$user_info['vipnopwd'] = 1;
$user_info['vippass'] = $new_user_info['VIPPass'];
} else {
$user_info['vipnopwd'] = 0;
}
/*--如果openid不等的话--*/
if ($new_user_info['property1'] != $this->user['openid']) {
$id = $user_info['erpvipid'];
$data = array(
'Id' => $id,
'property1' => $this->user['openid']
);
mlog("提交值:" . json_encode($data), "userinfo/" . getMobileStoId());
$aa = getApiData("wxd.vip.vipinfo.edit", $user_info['api_token'], array($data));
}
} else {
$updateuser['erpvipid'] = "";
$falg = M('users')->where('user_id', $user_info['user_id'])->save($updateuser);
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
}
} else {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
} else {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
}
//后台是否开启了初始化
$init_url = Mini_Host() . "/api/weshop/users/grade/vip/init/get?storeId=" . getMobileStoId();
$init_data = httpRequest($init_url);
if ($init_data) {
$init_data = json_decode($init_data, true);
if (is_array($init_data) && array_key_exists('data', $init_data) && is_array($init_data['data']) && array_key_exists('isBool', $init_data['data'])) {
$this->assign('init_data', $init_data);
if ($init_data['data']['isBool']) {
$post_usr = Mini_Host() . '/api/weshop/users/grade/aftervipinfo/get?storeId=' . $stoid . "&userId=" . $user_info['user_id'];
$post_usr = httpRequest($post_usr);
if ($post_usr) {
$i_data = json_decode($post_usr, true);
if (is_array($i_data) && array_key_exists('data', $i_data) && is_array($i_data['data'])) {
if (array_key_exists('GradeName', $i_data['data']) && $i_data['data']['GradeName']) {
$str_data = $i_data['data']['GradeName'];
$len = mb_strlen($str_data, "utf-8");
if ($len > 6) {
$str_data = mb_substr($str_data, 0, 6, "utf-8");
}
$this->assign('GradeName', $str_data);
}
}
}
}
}
}
}
$pickup_name = $user_info['pickup_name'];
$this->assign('user_info', $user_info);
// $this->assign('cardinfo', $cardinfo);
//
// $this->assign('cardimg', $cardimg);
$this->assign('sex', C('SEX'));
$this->assign('pickup_name', $pickup_name);
$this->assign('birthday', (empty($user_info['birthday']) ? '' : date('Y-m-d', $user_info['birthday']))); //生日
$this->assign('BillDate', date('Y-m-d', $user_info['reg_time'])); //绑定时间
//从哪个修改用户信息页面进来,
$dispaly = I('action');
if ($dispaly != '') {
return $this->fetch("$dispaly", getMobileStoId());
exit;
}
$stoid = getMobileStoId();
/*查看商家是否开启自定义标签*/
$switch_list= $storeconfig['switch_list'];
$switch_list=json_decode($switch_list,true);
$user_label_set=$switch_list['user_label_set'];//是否开启会员标签的名称
$this->assign('user_label_set',$user_label_set);
/*获取会员标签*/
if($user_label_set==1) {
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
$user = session('user');
if ($user['erpvipid']) {
$data['VIPId'] = urlencode($user['erpvipid']);
$vip_user = getApiData_java_p("/api/erp/marketing/vip/interest/label/get", $accdb, $data, 1, 1000, null, "GET");
if ($vip_user) {
$vip_user = json_decode($vip_user, true);
$label_data = $vip_user['data'];
$label_id = $label_data['VipLabelId'];
$label_name = $label_data['VipLabel'];
$label_name = explode(",", $label_name);
$this->assign('label_name', $label_name);
}
}
}
return $this->fetch('', getMobileStoId());
}
/*
*我的等级卡
*/
public function cardinfo()
{
$user_info = M('users')->alias('a')
->field('a.*')
->where("a.user_id", $this->user_id)->find();
$istransmoney = I('ist');
$stoid = getMobileStoId();
$accdb = tpCache('shop_info.ERPId', $stoid);
//---邀请他人个数及霍格奖励金额---,需要金额判断
$where['VIPId'] = urlencode($user_info['erpvipid']);
$rt = getApiData_java_p("/api/erp/vip/mem/referee/money", $accdb, $where);
$rt = json_decode($rt, true);
if ($rt['code'] === 0) {
$rt = $rt['data'][0];
}
if ($istransmoney == 1) //转换余额,ajax调用
{
$money = I('money');
//$money=10;
$ordersn = 'cm' . date("YmdHis") . rand(1000, 9999);
if ($money && $money <= $rt['BlanMoney']) {
$data['user_id'] = $user_info['user_id'];
$data['create_time'] = time();
$data['money'] = $money;
$data['remark'] = '等级卡奖励金额转换余额';
$data['store_id'] = getMobileStoId();
$data['order_sn'] = $ordersn;
$data['type'] = 5;
$order_id = M('withdrawals')->add($data);//生成线上单
//线下扣除
unset($data);
$data['VIPId'] = urlencode($user_info['erpvipid']);//会员ID
$data['ExpMoney'] = $money;//转换奖励金
$data['Number'] = $ordersn;
$data['Remark'] = '奖励金转换为线上余额';
//$rs = getApiData("wxd.mem.vip.referee.money.add", $user_info['api_token'], $data);
$rs = getApiData_java_p("/api/erp/vip/mem/referee/money/add", $accdb, $data, 1, 10, null, "POST");
$mrs = json_decode($rs, true);
//更新会员余额
if ($mrs['code'] === 0) {
M('withdrawals')->where(['user_id' => $user_info['user_id'], 'id' => $order_id])->save(['status' => 1]);//更新余额表
$updata['user_money'] = $user_info['user_money'] + $money;
M('users')->where('user_id', $user_info['user_id'])->save($updata);//更新会员信息表
return json(['code' => 1, 'msg' => '转换余额成功']);
} else {
return json(['code' => 1, 'msg' => '转换余额失败,请重试']);
}
} else {
return json(['code' => 1, 'msg' => '当前无可转换奖励金']);
}
}
//---会员等级卡信息---
$cardinfo = getApiData_java_p("/api/erp/vip/mem/list", $accdb, $where);
$cardinfo = json_decode($cardinfo, true);
if ($cardinfo['code'] !== 0 || $cardinfo['data'][0]['GradeCardID'] == '') {
$cardinfo = '';
} else {
$cardinfo = $cardinfo['data'][0];
$expiredate = $cardinfo['ExpiryDate'];
$expireday = $cardinfo['YExpiryDate'];
$cardinfo['newexpiredate'] = date("Y-m-d", strtotime("$expiredate +$expireday day"));
if (empty($cardinfo['cardfee']))
$cardinfo['cardfee'] = "0.00";
$cardinfo['cardfee'] = number_format($cardinfo['cardfee'], 2, '.', '');
$key = md5($cardinfo['GradeCardID'] . $cardinfo['cardfee'] . getErpKey());
$cardinfo['keys'] = $key;
if (strtotime($expiredate) < time()) {
$this->assign("is_guo_qi", 1);
}
}
$cardinfo['RefereeNumber'] = $rt['RefereeNumber'];
$cardinfo['BlanMoney'] = $rt['BlanMoney'];
$cardinfo['VIPRebate'] = $rt['VIPRebate'];
//--等级卡卡类列表---
$plusinfo = getApiData_java_p("/api/erp/vip/mem/bership/list", $accdb, null, 1, 10, null, "GET");
if ($plusinfo) {
$plusinfo = json_decode($plusinfo, true);
$arrlist = $plusinfo;
$free_price = null;
$curr_card_img = null;
$f_color = null;
if (isset($arrlist['data']) && $arrlist['data']) {
foreach ($arrlist['data'] as $k => $v) {
$fee = number_format($v['CardFee'], 2, ".", "");
$fileds_key = md5($v['CardId'] . $fee . $v['ExpiryDate'] . getErpKey());
$arrlist[$k]['keys'] = $fileds_key;
$free_price[] = ['index' => $k, 'fee' => $fee];
if (empty($v['CardImg'])) $arrlist['data'][$k]['CardImg'] = QCLOUD_IMGURL . "/miniapp/images/plus/bg" . ($k + 1) . ".jpg?v=1";
if (empty($v['CardColor'])) $arrlist['data'][$k]['CardColor'] = "#ecba95";
if ($v['CardId'] == $cardinfo['GradeCardID']) {
$curr_card_img = $v['CardImg'];
$f_color = $v['CardColor'];
}
}
if (empty($f_color)) $f_color = "#ecba95";
$cardfield = $user_info['card_field'];
$num = str_replace("cardprice", "", $cardfield);
if (empty($curr_card_img)) $curr_card_img = QCLOUD_IMGURL . "/miniapp/images/plus/bg" . $num . ".jpg?v=1";
//---价格的排序---
$last_names = array_column($free_price, 'fee');
array_multisort($last_names, SORT_DESC, $free_price);
//--固定的是优惠多少钱---
//获取出最大价格的卡的id及index变量用与取值
$max_free_index = $free_price[0]['index'];
//用上面的变量参数来获取最大价格的卡
$max_card = $arrlist['data'][$max_free_index];
$this->assign('max_card', $max_card);
$this->assign('curr_card_img', $curr_card_img);
$this->assign('f_color', $f_color);
}
$this->assign('cardinfo', $cardinfo);
}
//把二维码图片转换成64
$getcardrules = tpCache('basic.cardrules', $stoid);
$this->assign("cardrules", $getcardrules);
$shareurl = curHostURL() . '/index.php/mobile/user/vipcard/stoid/' . $stoid . '/plus_leader/' . $this->user_id;
$this->assign('shareurl', $shareurl);
$qc = new \app\home\controller\Index();
$shareurl = $qc->qr_code_64($shareurl);
$this->assign('shareurlimg', $shareurl);
//引用基类MobilBase中的方法可以映射出用户图片的64为转码后的图片
$this->buy_page_assign();
return $this->fetch('', getMobileStoId());
}
//等级会员邀请列表明细
public function ajax_invitation_list()
{
$page = $_GET['p'];
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token')
->where("a.user_id", $this->user_id)->find();
$where['VIPId'] = urlencode($user_info['erpvipid']);
$accdb = tpCache("shop_info.ERPId", getMobileStoId());
$data["user_id"] = $user_info['user_id'];
//邀请会员列表
$rs = getApiData_java_p("/api/erp/vip/mem/referee/page", $accdb, $where, $page, 20);
$rs = json_decode($rs, true);
if ($rs['code'] == 0) {
$rs = $rs['data'];
}
$this->assign('list', $rs);
return $this->fetch();
}
//邀请会员明细查询
public function change_detailed()
{
$stoid = getMobileStoId();
$accdb = tpCache("shop_info.ERPId", $stoid);
$this->buy_page_assign();
//--等级卡卡类列表---
$arrlist = getApiData_java_p("/api/erp/vip/mem/bership/list", $accdb, null, 1, 10, null, "GET");
$arrlist = json_decode($arrlist, true);
if (isset($arrlist['data']) && $arrlist['data']) {
foreach ($arrlist['data'] as $k => $v) {
$fee = number_format($v['CardFee'], 2, ".", "");
$free_price[] = ['index' => $k, 'fee' => $fee];
if (empty($v['CardImg'])) $arrlist['data'][$k]['CardImg'] = QCLOUD_IMGURL . "/miniapp/images/plus/bg" . ($k + 1) . ".jpg?v=1";
if (empty($v['CardColor'])) $arrlist['data'][$k]['CardColor'] = "#ecba95";
}
//---价格的排序---
$last_names = array_column($free_price, 'fee');
array_multisort($last_names, SORT_DESC, $free_price);
//--固定的是优惠多少钱---
//获取出最大价格的卡的id及index变量用与取值
$max_free_index = $free_price[0]['index'];
//用上面的变量参数来获取最大价格的卡
$max_card = $arrlist['data'][$max_free_index];
$this->assign('max_card', $max_card);
$shareurl = curHostURL() . '/index.php/mobile/user/vipcard/stoid/' . $stoid . '/first_leader/' . $this->user_id;
$this->assign('shareurl', $shareurl);
$qc = new \app\home\controller\Index();
$shareurl = $qc->qr_code_64($shareurl);
$this->assign('shareurlimg', $shareurl);
}
return $this->fetch("", $stoid);
}
/*
* 邮箱验证
*/
public function email_validate()
{
$userLogic = new UsersLogic();
$user_info = $userLogic->get_info($this->user_id); // 获取用户信息
$user_info = $user_info['result'];
$step = I('get.step', 1);
//验证是否未绑定过
if ($user_info['email_validated'] == 0)
$step = 2;
//原邮箱验证是否通过
if ($user_info['email_validated'] == 1 && session('email_step1') == 1)
$step = 2;
if ($user_info['email_validated'] == 1 && session('email_step1') != 1)
$step = 1;
if (IS_POST) {
$email = I('post.email');
$code = I('post.code');
$info = session('email_code');
if (!$info)
$this->error('非法操作');
if ($info['email'] == $email || $info['code'] == $code) {
if ($user_info['email_validated'] == 0 || session('email_step1') == 1) {
session('email_code', null);
session('email_step1', null);
if (!$userLogic->update_email_mobile($email, $this->user_id))
$this->error('邮箱已存在');
$this->success('绑定成功', U('Home/User/index'));
} else {
session('email_code', null);
session('email_step1', 1);
redirect(U('Home/User/email_validate', array('step' => 2)));
}
exit;
}
$this->error('验证码邮箱不匹配');
}
$this->assign('step', $step);
return $this->fetch('', getMobileStoId());
}
/*
* 手机验证
*/
public function mobile_validate()
{
$userLogic = new UsersLogic();
$user_info = $userLogic->get_info($this->user_id); // 获取用户信息
$user_info = $user_info['result'];
$step = I('get.step', 1);
//验证是否未绑定过
if ($user_info['mobile_validated'] == 0)
$step = 2;
//原手机验证是否通过
if ($user_info['mobile_validated'] == 1 && session('mobile_step1') == 1)
$step = 2;
if ($user_info['mobile_validated'] == 1 && session('mobile_step1') != 1)
$step = 1;
if (IS_POST) {
$mobile = I('post.mobile');
$code = I('post.code');
$info = session('mobile_code');
if (!$info)
$this->error('非法操作');
if ($info['email'] == $mobile || $info['code'] == $code) {
if ($user_info['email_validated'] == 0 || session('email_step1') == 1) {
session('mobile_code', null);
session('mobile_step1', null);
if (!$userLogic->update_email_mobile($mobile, $this->user_id, 2))
$this->error('手机已存在');
$this->success('绑定成功', U('Home/User/index'));
} else {
session('mobile_code', null);
session('email_step1', 1);
redirect(U('Home/User/mobile_validate', array('step' => 2)));
}
exit;
}
$this->error('验证码手机不匹配');
}
$this->assign('step', $step);
return $this->fetch('', getMobileStoId());
}
/**
* 用户收藏列表
*/
public function collect_list()
{
upload_ylp_log('用户收藏列表');
$userLogic = new UsersLogic();
$data = $userLogic->get_goods_collect($this->user_id);
$this->assign('page', $data['show']);// 赋值分页输出
$this->assign('total', $data['total']);// 赋值分页输出
$this->assign('goods_list', $data['result']);
if (IS_AJAX) {//ajax加载更多
return $this->fetch('ajax_collect_list', getMobileStoId());
exit;
}
return $this->fetch('', getMobileStoId());
}
/*
*取消收藏
*/
public function cancel_collect()
{
upload_ylp_log('取消收藏');
$collect_id = I('collect_id');
$user_id = $this->user_id;
if (M('goods_collect')->where(['collect_id' => $collect_id, 'user_id' => $user_id])->delete()) {
$this->success("取消收藏成功", U('User/collect_list', array('stoid' => getMobileStoId())));
} else {
$this->error("取消收藏失败", U('User/collect_list', array('stoid' => getMobileStoId())));
}
}
/**
* 我的留言
*/
public function message_list()
{
upload_ylp_log('我的留言');
C('TOKEN_ON', true);
if (IS_POST) {
$this->verifyHandle('message');
$data = I('post.');
$data['user_id'] = $this->user_id;
$user = session('user');
$data['user_name'] = $user['nickname'];
$data['msg_time'] = time();
if (M('feedback')->add($data)) {
$this->success("留言成功", U('User/message_list', array('stoid' => getMobileStoId())));
exit;
} else {
$this->error('留言失败', U('User/message_list', array('stoid' => getMobileStoId())));
exit;
}
}
$msg_type = array(0 => '留言', 1 => '投诉', 2 => '询问', 3 => '售后', 4 => '求购');
$count = M('feedback')->where("user_id", $this->user_id)->count();
$Page = new Page($count, 100);
$Page->rollPage = 2;
$message = M('feedback')->where("user_id", $this->user_id)->limit($Page->firstRow . ',' . $Page->listRows)->select();
$showpage = $Page->show();
header("Content-type:text/html;charset=utf-8");
$this->assign('page', $showpage);
$this->assign('message', $message);
$this->assign('msg_type', $msg_type);
return $this->fetch('', getMobileStoId());
}
/*
* 密码修改
*/
public function password()
{
//检查是否第三方登录用户
$logic = new UsersLogic();
$data = $logic->get_info($this->user_id);
$user = $data['result'];
if ($user['mobile'] == '' && $user['email'] == '')
$this->error('请先到电脑端绑定手机', U('/mobile/User/index', array('stoid' => getMobileStoId())));
if (IS_POST) {
$userLogic = new UsersLogic();
$data = $userLogic->password($this->user_id, I('post.old_password'), I('post.new_password'), I('post.confirm_password')); // 获取用户信息
if ($data['status'] == -1)
$this->error($data['msg']);
$this->success($data['msg']);
exit;
}
return $this->fetch('', getMobileStoId());
}
function forget_pwd()
{
if ($this->user_id > 0) {
$this->redirect("User/Index", array('stoid' => getMobileStoId()));
// header("Location: " . U('User/Index'));`
}
$username = I('username');
if (IS_POST) {
if (!empty($username)) {
$this->verifyHandle('forget');
$field = 'mobile';
if (check_email($username)) {
$field = 'email';
}
$user = M('users')->where("email", $username)->whereOr('mobile', $username)->find();
if ($user) {
session('find_password', array('user_id' => $user['user_id'], 'username' => $username,
'email' => $user['email'], 'mobile' => $user['mobile'], 'type' => $field));
header("Location: " . U('User/find_pwd', array('stoid' => getMobileStoId())));
exit;
} else {
$this->error("用户名不存在,请检查");
}
}
}
return $this->fetch('', getMobileStoId());
}
function find_pwd()
{
if ($this->user_id > 0) {
header("Location: " . U('User/Index'));
}
$user = session('find_password');
if (empty($user)) {
$this->error("请先验证用户名", U('User/forget_pwd', array('stoid' => getMobileStoId())));
}
$this->assign('user', $user);
return $this->fetch('', getMobileStoId());
}
public function set_pwd()
{
if ($this->user_id > 0) {
// header("Location: " . U('User/Index'));
$this->redirect('mobile/User/Index', array('stoid' => getMobileStoId()));
}
$check = session('validate_code');
if (empty($check)) {
header("Location:" . U('User/forget_pwd', array('stoid' => getMobileStoId())));
} elseif ($check['is_check'] == 0) {
$this->error('验证码还未验证通过', U('User/forget_pwd', array('stoid' => getMobileStoId())));
}
if (IS_POST) {
$password = I('post.password');
$password2 = I('post.password2');
if ($password2 != $password) {
$this->error('两次密码不一致', U('User/forget_pwd', array('stoid' => getMobileStoId())));
}
if ($check['is_check'] == 1) {
//$user = get_user_info($check['sender'],1);
$user = M('users')->where("mobile", $check['sender'])->whereOr('email', $check['sender'])->find();
M('users')->where("user_id", $user['user_id'])->save(array('password' => encrypt($password)));
session('validate_code', null);
//header("Location:".U('User/set_pwd',array('is_set'=>1)));
$this->success('新密码已设置行牢记新密码', U('User/index', array('stoid' => getMobileStoId())));
exit;
} else {
$this->error('验证码还未验证通过', U('User/forget_pwd', array('stoid' => getMobileStoId())));
}
}
$is_set = I('is_set', 0);
$this->assign('is_set', $is_set);
return $this->fetch('', getMobileStoId());
}
//发送验证码
public function send_validate_code()
{
$type = I('type');
$send = I('send');
$logic = new UsersLogic();
$res = $logic->send_validate_code($send, $type);
$this->ajaxReturn($res);
}
public function check_validate_code()
{
$code = I('post.code');
$send = I('send');
$logic = new UsersLogic();
$res = $logic->check_validate_code($code, $send);
$this->ajaxReturn($res);
}
/**
* 验证码验证
* $id 验证码标示
*/
private function verifyHandle($id)
{
$verify = new Verify();
if (!$verify->check(I('post.verify_code'), $id ? $id : 'user_login')) {
$this->error("验证码错误");
}
}
/**
* 验证码获取
*/
public function verify()
{
//验证码类型
$type = I('get.type') ? I('get.type') : 'user_login';
$config = array(
'fontSize' => 40,
'length' => 4,
'useCurve' => true,
'useNoise' => false,
);
$Verify = new Verify($config);
$Verify->entry($type);
}
/**
* 账户管理
*/
public function accountManage()
{
return $this->fetch('', getMobileStoId());
}
/**
* 确定收货成功
*/
public function order_confirm()
{
$id = I('get.id/d', 0);
$data = confirm_order($id, $this->user_id);
if (!$data['status']) {
$this->error($data['msg']);
} else {
$order = $data['order'];
$model = new UsersLogic();
$order_goods = $model->get_order_goods($id);
$this->assign('order_goods', $order_goods);
return $this->fetch('', getMobileStoId());
exit;
}
}
/**
* 申请退货
*/
public function return_goods()
{
upload_ylp_log('申请退货');
$order_id = I('order_id/d', 0);
$order_sn = I('order_sn', 0);
$goods_id = I('goods_id/d', 0);
$is_replay = I('is_replay');
$isall = I('isall/d', 0);
//整单退的时候,有部分退款
if ($isall) {
$return_goods = M('return_goods')->where('order_id', $order_id)->where('status<3')->count();
if ($return_goods) {
$this->error('当前订单有部分退款不能整单退!',
U('mobile/User/order_list', array('order_detail' => $return_goods['id'], 'stoid' => getMobileStoId())));
exit;
}
}
$return_goods = null;
if ($goods_id) {
$return_goods = M('return_goods')
->where('order_id', $order_id)->where('goods_id', $goods_id)->where('user_id', $this->user_id)
->find();
} else {
$return_goods = M('return_goods')
->where('order_id', $order_id)->where('user_id', $this->user_id)
->find();
}
if ($return_goods) {
$cp = "r" . $return_goods['status'];
if ($cp == "r3") {
$is_replay = 1;
} else {
$this->error('已经提交过退货申请!',
U('mobile/User/order_list', array('order_detail' => $return_goods['id'], 'stoid' => getMobileStoId())));
exit;
}
}
$this->assign('is_replay', $is_replay);
/*---
$is_replay="".$is_replay;
mlog("is_re:".$is_replay,"return_goods/".getMobileStoId());
if (!empty($return_goods) && $is_replay != "1" ) {
}---*/
//判断是不是回退,再次申请退款
$is_tui = 0;
$re_list = M('return_goods')
->where(array('order_id' => $order_id, 'user_id' => $this->user_id))
->where('status<3')
->select();
if ($re_list) {
foreach ($re_list as $k => $v) {
if ($goods_id && strpos($v['goods_id_list'], $goods_id . '') !== false) {
$is_tui = 1;
break;
}
}
}
if ($is_tui == 1) {
$this->error('已经提交过退货申请!',
U('mobile/User/order_list', array('order_detail' => $return_goods['id'], 'stoid' => getMobileStoId())));
exit;
}
$id = I('id');
$rg = null;
if (!empty($id)) {
$rg = M('return_goods')->where("id", $id)->find();
$order_id = $rg['order_id'];
$goods_id = $rg['goods_id'];
$goods_id_list = $rg['goods_id_list'];
} else {
if ($is_replay == 1) {
$id = $return_goods['id'];
$rg = M('return_goods')->where("id", $id)->find();
$order_id = $rg['order_id'];
$goods_id = $rg['goods_id'];
$goods_id_list = $rg['goods_id_list'];
}
}
$c = M('order')->where(['order_id' => $order_id, 'user_id' => $this->user_id, 'is_bedistri' => 0, 'pay_status' => 1, 'order_status' => 1])->find();
if (empty($c)) {
$this->error('非法操作');
exit;
}
$order_sn = $c["order_sn"];
//判断ERP POS是否有取单
if ($goods_id) {
$goodsinfo = M('goods')->where("goods_id", $goods_id)->field('erpwareid')->find();
if ($goodsinfo) {
$where['wareid'] = $goodsinfo['erpwareid'];
}
}
$oglist = M('order_goods')->where('order_id', $order_id)->select();
if (count($oglist) == 1 || $isall == 1 || $rg['goods_id_list']) {
$maxb = $c["order_amount"] + $c["user_money"] + $c["pt_tail_money"];
mlog("1_all:" . $isall . "_sn:" . $order_sn . "_bk:" . $maxb, "return_goods/" . $c['store_id']);
} else if ($goods_id) {
$gorder = M('order_goods')->where(['order_id' => $order_id, 'goods_id' => $goods_id])->select();
if (empty($gorder)) {
$this->error('未找到商品');
exit;
}
$maxb = $gorder[0]["member_goods_price"] * $gorder[0]['goods_num'];
mlog("2:" . $goods_id . "_sn:" . $order_sn . "_bk:" . $maxb, "return_goods/" . $c['store_id']);
}
mlog("3_sn:" . $order_sn . "_bk:" . $maxb, "return_goods/" . $c['store_id']);
$this->assign('maxb', $maxb);
/*--积分支付--*/
if (!empty($c['integral'])) {
$this->assign('integral', $c['integral']);
}
$isajax = I('isajax');
if (!empty($isajax)) {
//判断ERP POS是否有取单
if ($goods_id) {
$goodsinfo = M('goods')->where("goods_id", $goods_id)->field('erpwareid')->find();
if ($goodsinfo) {
$where['wareid'] = $goodsinfo['erpwareid'];
}
}
if ($c['exp_type'] == 1 && $this->pm_erpid) { //自提
/*---
$where['OrdNo'] = $order_sn;
$user_info['api_token'] = tpCache('shop_info.api_token', getMobileStoId());
$offline = getApiData('wxd.pos.list.get', $user_info['api_token'], null, $where, 1, 10, '');
if (empty($offline))
{
return json(['code' => -2, 'msg' => '网络异常']);
}
$offline = json_decode($offline, true);
if ($offline['code'] == 1 && $offline['count'] && $offline['data']) {
$postStr = "{\"NUMBER\":\"" . $order_sn . "\"}";
httpRequest(curHostURL() . "/home/api/order", "POST", $postStr);
return json(['code' => -2, 'msg' => '此单已发货,无法申请此操作']);
}---*/
$accdb = tpCache("shop_info.ERPId", getMobileStoId());
$data["OrdNo"] = $order_sn;
$offline = getApiData_java_p("/api/erp/pos/page", $accdb, $data);
if (empty($offline)) {
return json(['code' => 0, 'msg' => '网络异常1']);
}
$offline = json_decode($offline, true);
if ($offline) {
if ($offline['code'] == 0 && $offline['data']) {
if ($offline['data']['pageData']) {
$postStr = "{\"NUMBER\":\"" . $order_sn . "\"}";
httpRequest(curHostURL() . "/home/api/order", "POST", $postStr);
return json(['code' => 0, 'msg' => '此单已发货,无法申请此操作']);
}
}
}
}
mlog("4_sn:" . $order_sn . "_bk:" . $maxb, "return_goods/" . $c['store_id']);
$data['store_id'] = getMobileStoId();
$data['order_id'] = $order_id;
$data['order_sn'] = $order_sn;
$data['addtime'] = time();
$data['user_id'] = $this->user_id;
$data['type'] = I('type'); // 服务类型 退货 或者 换货
$data['reason'] = I('reason'); // 问题描述
$data['spec_key'] = I('spec_key'); // 商品规格
$data['user_remark'] = I('user_remark'); // 用户说明
$data['back_money'] = $maxb;//返回金额
$data['back_integral'] = $c['integral'];
$data['status'] = 0;
$data['imgs'] = "";
if ($is_replay) {
$data['goods_id_list'] = $goods_id_list;
$data['goods_id'] = $goods_id;
} else {
/*如果是整单退*/
if ($isall) {
$gid_list = "";
foreach ($oglist as $kk => $vv) {
$gid_list .= $vv['goods_id'] . ",";
}
$gid_list = substr($gid_list, 0, strlen($gid_list) - 1);
$data['goods_id_list'] = $gid_list;
} /*--单件商品退--*/
else {
$data['goods_id'] = $goods_id;
}
}
$res = null;
if (empty($id)) {
if (I('refund_type')) {
$data['refund_type'] = I('refund_type');
} else {
$data['refund_type'] = 0;
}
$res = M('return_goods')->add($data);
$id = $res;
} else {
$data['goods_id'] = $rg['goods_id'];
$res = M('return_goods')->where('id', $id)->save($data);
}
if ($res) {
return json(['code' => 1, 'data' => ['rid' => $id]]);
} else {
return json(['code' => -1, 'msg' => '申请失败']);
}
exit();
} else {
if ($c['exp_type'] == 1) { //自提
/*----
$where['OrdNo'] = $order_sn;
$user_info['api_token'] = tpCache('shop_info.api_token', getMobileStoId());
$offline = getApiData('wxd.pos.list.get', $user_info['api_token'], null, $where, 1, 10, '');
if (empty($offline))
{
$this->error('网络异常!',
U('mobile/User/order_detail', array('id' => $c['order_id'], 'stoid' => getMobileStoId())));
exit;
}
$offline = json_decode($offline, true);
if ($offline['code'] == 1 && $offline['count'] && $offline['data']) {
$postStr = "{\"NUMBER\":\"" . $order_sn . "\"}";
httpRequest(curHostURL() . "/home/api/order", "POST", $postStr);
$this->error('此单已发货,无法申请此操作!',
U('mobile/User/order_detail', array('id' => $c['order_id'], 'stoid' => getMobileStoId())));
exit;
}--*/
$accdb = tpCache("shop_info.ERPId", getMobileStoId());
$data["OrdNo"] = $order_sn;
$offline = getApiData_java_p("/api/erp/pos/page", $accdb, $data);
if (empty($offline)) {
return json(['code' => 0, 'msg' => '网络异常2']);
}
$offline = json_decode($offline, true);
if ($offline) {
if ($offline['code'] == 0 && $offline['data']) {
if ($offline['data']['pageData']) {
$postStr = "{\"NUMBER\":\"" . $order_sn . "\"}";
httpRequest(curHostURL() . "/home/api/order", "POST", $postStr);
$this->error('此单已发货,无法申请此操作!',
U('mobile/User/order_detail', array('id' => $c['order_id'], 'stoid' => getMobileStoId())));
exit;
}
}
}
}
}
$this->assign('order_id', $order_id);
$this->assign('order_sn', $order_sn);
$this->assign('goods_id', $goods_id);
$this->assign('isall', $isall);
$this->assign('maxb', $maxb);
return $this->fetch('', getMobileStoId());
}
/**
* 退换货列表
*/
public function return_goods_list()
{
upload_ylp_log('退换货列表');
//退换货商品信息
$count = M('return_goods')->where("user_id", $this->user_id)->count();
$pagesize = C('PAGESIZE');
$page = new Page($count, 10);
$list = M('return_goods')->where("user_id", $this->user_id)->order("id desc")->limit("{$page->firstRow},{$page->listRows}")->select();
foreach ($list as $k => $v) {
$og = M('order_goods')->where('order_id', $v['order_id'])->select();
if (empty($v['goods_id_list'])) {
$goods = M('order_goods')->alias('a')->join('goods b', 'a.goods_id=b.goods_id', 'left')->where('order_id', $v['order_id'])->where("a.goods_id", $v['goods_id'])->field('b.*,a.member_goods_price,a.goods_num')->select();
$goodnum1 = $goods[0]['goods_num'];
if (count($og) > 1) {
$money1 = $goods[0]['member_goods_price'] * $goods[0]['goods_num'];
} else {
$od = M('order')->where('order_id', $v['order_id'])->find();
$money1 = $od['order_amount'] + $od['user_money'];
}
} else {
$goodsarr = explode(',', $v['goods_id_list']);
$goods = M('order_goods')->alias('a')->join('goods b', 'a.goods_id=b.goods_id', 'left')->where('order_id', $v['order_id'])->where("a.goods_id", "in", $goodsarr)->field('b.*,a.member_goods_price,a.goods_num')->select();
$od = M('order')->where('order_id', $v['order_id'])->find();
$money1 = $od['order_amount'] + $od['user_money'];
$goodnum1 = count($og);
}
if (!empty($od)) {
if (!empty($od['integral'])) {
$list[$k]['Integral'] = $od['integral'];
}
}
$list[$k]['goods'] = $goods;
$list[$k]['money'] = number_format($money1, 2);
$list[$k]['gnum'] = $goodnum1;
}
$this->assign('list', $list);
$this->assign('page', $page->show());// 赋值分页输出
if (I('is_ajax')) {
return $this->fetch('ajax_return_goods_list', getMobileStoId());
exit;
}
$p = I("p/d", 1);
if ($count >= $p * 10) {
$this->assign('mshow', 1);
} else {
$this->assign('mshow', 0);
}
return $this->fetch('', getMobileStoId());
}
/**
* 退货详情
*/
public function return_goods_info()
{
upload_ylp_log('退货详情');
$id = I('id/d', 0);
$oid = I('order_id/d', 0);
$gid = I('goods_id/d', 0);
if ($id) {
$return_goods = M('return_goods')->where("id", $id)->find();
}
if ($oid) {
$return_goods = M('return_goods')->where("order_id", $oid)->where('goods_id', $gid)->find();
}
if ($return_goods['imgs']) {
$str = rtrim($return_goods['imgs'], ",");
$return_goods['imgs'] = explode(',', $str);
}
//$goods = M('goods')->where("goods_id",$return_goods['goods_id'])->find();
if (empty($return_goods['goods_id_list'])) {
$goods = M('goods')->where("goods_id", $return_goods['goods_id'])->select();
} else {
$goodsarr = explode(',', $return_goods['goods_id_list']);
$goods = M('goods')->where("goods_id", "in", $goodsarr)->select();
}
$ord = M("order")->where("order_id", $return_goods['order_id'])->find();
$orgoods = M("order_goods")->where("order_id", $return_goods['order_id'])->select();
if ($return_goods['addtime']) {
$return_goods['addtime'] = date('Y-m-d H:i:s', $return_goods['addtime']);
}
if ($return_goods['handle_time']) {
$return_goods['handle_time'] = date('Y-m-d H:i:s', $return_goods['handle_time']);
}
if ($return_goods['ok_time']) {
$return_goods['ok_time'] = date('Y-m-d H:i:s', $return_goods['ok_time']);
}
$this->assign('goods', $goods);
$this->assign('ord', $ord);
$this->assign('return_goods', $return_goods);
return $this->fetch('', getMobileStoId());
}
public function recharge()
{
$order_id = I('order_id/d');
$paymentList = M('Plugin')->where("`type`='payment' and code!='cod' and status = 1 and scene in(0,1)")->select();
//微信浏览器
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
$paymentList = M('Plugin')->where("`type`='payment' and status = 1 and code='weixin'")->select();
}
$paymentList = convert_arr_key($paymentList, 'code');
foreach ($paymentList as $key => $val) {
$val['config_value'] = unserialize($val['config_value']);
if ($val['config_value']['is_bank'] == 2) {
$bankCodeList[$val['code']] = unserialize($val['bank_code']);
}
}
$bank_img = include APP_PATH . 'home/bank.php'; // 银行对应图片
$payment = M('Plugin')->where("`type`='payment' and status = 1")->select();
$this->assign('paymentList', $paymentList);
$this->assign('bank_img', $bank_img);
$this->assign('bankCodeList', $bankCodeList);
if ($order_id > 0) {
$order = M('recharge')->where("order_id", $order_id)->find();
$this->assign('order', $order);
}
return $this->fetch('', getMobileStoId());
}
/**
* 申请提现记录
*/
public function withdrawals()
{
upload_ylp_log('申请提现记录');
header("Content-type:text/html;charset=utf-8");
$distribut_min = tpCache('basic.distribut_min', getMobileStoId()); // 最少提现额度
$needmon = tpCache('basic.distribut_need', getMobileStoId()); // 满多少才能提现
if (IS_POST) {
$data['user_id'] = $this->user_id;
$data['money'] = I('money');
$data['bank_name'] = I('bank_name');
$data['account_bank'] = I('account_bank');
$data['account_name'] = I('account_name');
$data['store_id'] = I('stoid');
$data['order_sn'] = "tx" . date("YmdHis") . rand(1000, 9999);
$data['create_time'] = time();
$data['bank_type'] = I('bank_type');
if ($data['money'] < $distribut_min) {
$this->error('每次最少提现额度' . $distribut_min);
exit;
}
if ($data['money'] > $this->user['user_money']) {
$this->error("你最多可提现{$this->user['user_money']}账户余额.");
exit;
}
$withdrawal = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
if ($this->user['user_money'] < ($withdrawal + $data['money'])) {
$this->error('您有提现申请待处理,本次提现余额不足');
}
if (M('withdrawals')->add($data)) {
$this->success("已提交申请");
exit;
} else {
$this->error('提交失败,联系客服!');
exit;
}
}
$switch_list = tpCache('basic.switch_list', getMobileStoId()); // 是否有银行卡选项
$wx = M('wx_user')->where('store_id', getMobileStoId())
->field('check_json')
->find();
if ($wx['check_json']) {
$dd = json_decode($wx['check_json'], true);
$isck = $dd['code'];
$switch = tpCache('basic.is_tx_wx', getMobileStoId());
if ($switch == 1 && $isck == 1) {
$this->assign('isck', 1);
}
}
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$lc_mon = $this->user['frozen_money'];
$rmon = $this->user['user_money'] - $locking_money - $lc_mon;
//查找最新一条提现记录
$topres = M('withdrawals')->where(array('store_id' => getMobileStoId(), 'user_id' => $this->user_id))
->order('create_time desc')->find();
if (I('is_ajax')) {
return $this->fetch('ajax_withdrawals_list', getMobileStoId());
exit;
}
$this->assign('topres', $topres);//最新提现记录
$this->assign('distribut_min', $distribut_min);//最低额度
$this->assign('needmon', $needmon); //满多少可以提现
$this->assign('rmon', $rmon); //满多少可以提现
$this->assign('switch_list', json_decode($switch_list, true)); //是否有银行卡选项
$this->assign('liudong_money', number_format($rmon, 2)); //流动资金
//$this->assign('user_money', $this->user['user_money']); //用户余额
return $this->fetch('', getMobileStoId());
}
/**
* 申请记录列表
*/
public function withdrawals_list()
{
upload_ylp_log('申请记录列表');
$withdrawals_where['user_id'] = $this->user_id;
$count = M('withdrawals')->where($withdrawals_where)->count();
$pagesize = C('PAGESIZE');
$page = new Page($count, $pagesize);
$list = M('withdrawals')->where($withdrawals_where)->order("id desc")->limit("{$page->firstRow},{$page->listRows}")->select();
$this->assign('page', $page->show());// 赋值分页输出
$this->assign('list', $list); // 下线
if (I('is_ajax')) {
return $this->fetch('ajax_withdrawals_list', getMobileStoId());
exit;
}
return $this->fetch('', getMobileStoId());
}
/**
* 删除已取消的订单
*/
public function order_del()
{
upload_ylp_log('删除已取消订单');
$user_id = $this->user_id;
$order_id = I('get.ordid');
$order = M('order')->where(array('order_id' => $order_id, 'user_id' => $user_id))->find();
if (empty($order)) {
return $this->error('订单不存在');
exit;
}
$data = ['isdel' => 1];
$res = M('order')->where("order_id=$order_id")->save($data);
if ($res) {
return json(['code' => 1]);
} else {
return json(['code' => -1]);
}
}
/**
* 我的关注
* $author lxl
* $time 2017/1
*/
public function myfocus()
{
return $this->fetch('', getMobileStoId());
}
/**
* 待收货列表
* $author lxl
* $time 2017/1
*/
public function wait_receive()
{
upload_ylp_log('待收货列表');
$where = ' user_id=' . $this->user_id;
//条件搜索
if (I('type') == 'WAITRECEIVE') {
$where .= C(strtoupper(I('type')));
}
$count = M('order')->where($where)->count();
$pagesize = C('PAGESIZE');
$Page = new Page($count, $pagesize);
$show = $Page->show();
$order_str = "order_id DESC";
$order_list = M('order')->order($order_str)->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
//获取订单商品
$model = new UsersLogic();
foreach ($order_list as $k => $v) {
$order_list[$k] = set_btn_order_status($v); // 添加属性 包括按钮显示属性 和 订单状态显示属性
//$order_list[$k]['total_fee'] = $v['goods_amount'] + $v['shipping_fee'] - $v['integral_money'] -$v['bonus'] - $v['discount']; //订单总额
$data = $model->get_order_goods($v['order_id']);
$order_list[$k]['goods_list'] = $data['result'];
}
//统计订单商品数量
foreach ($order_list as $key => $value) {
$count_goods_num = '';
foreach ($value['goods_list'] as $kk => $vv) {
$count_goods_num += $vv['goods_num'];
}
$order_list[$key]['count_goods_num'] = $count_goods_num;
//订单物流单号
$invoice_no = M('DeliveryDoc')->where("order_id", $value['order_id'])->getField('invoice_no', true);
$order_list[$key][invoice_no] = implode(' , ', $invoice_no);
}
$this->assign('page', $show);
$this->assign('order_list', $order_list);
if ($_GET['is_ajax']) {
return $this->fetch('ajax_wait_receive', getMobileStoId());
exit;
}
return $this->fetch('', getMobileStoId());
}
/**
* 用户消息通知
* @author dyr
* @time 2016/09/01
*/
public function message_notice()
{
return $this->fetch('user/message_notice', getMobileStoId());
}
/**
* ajax用户消息通知请求
* @author dyr
* @time 2016/09/01
*/
public function ajax_message_notice()
{
$type = I('type', 0);
$user_logic = new UsersLogic();
$message_model = new Message();
if ($type == 1) {
//系统消息
$user_sys_message = $message_model->getUserMessageNotice();
$user_logic->setSysMessageForRead();
} else if ($type == 2) {
//活动消息:后续开发
$user_sys_message = array();
} else {
//全部消息:后续完善
$user_sys_message = $message_model->getUserMessageNotice();
}
$this->assign('messages', $user_sys_message);
return $this->fetch('user/ajax_message_notice', getMobileStoId());
}
/**
* 设置消息通知
*/
public function set_notice()
{
//暂无数据
return $this->fetch('', getMobileStoId());
}
/**
* 退款中 新增 20170318
*/
public function return_loading()
{
return $this->fetch('', getMobileStoId());
}
/**
* 填写物流信息 新增 20170318
*/
public function fill_exp()
{
return $this->fetch('', getMobileStoId());
}
/**
* 总余额 新增 20170320
*/
public function money()
{
$where1 = ' user_id=' . $this->user_id;
$current_money = M('users')->where($where1)->field('user_money,frozen_money,erpvipid')->find();
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
//流动资金
$liudong_money = $current_money['user_money'] - $locking_money - $current_money['frozen_money'];
$yucun_money = 0; //预存款金额
$rs0 = M('rebate_log')->where(array('user_id' => $this->user_id, 'status' => 2))->sum('money');
if ($rs0) {
$rs0 = $rs0;
} else {
$rs0 = 0.00;
}
$this->assign('Unavailable', number_format($rs0, 2));
$this->assign('allmoney', number_format($rs0 + $liudong_money, 2));
$user = session('user');
//有账套
$yucun_money = 0;
if ($this->pm_erpid) {
$yucun_money = $this->getyucun();
}
$amount_money = $liudong_money + $yucun_money;
$this->assign('liudong_money', number_format($liudong_money, 2));
$this->assign('yucun_money', $yucun_money == '' ? 0 : $yucun_money);
$this->assign('amount_money', $amount_money);
return $this->fetch('', getMobileStoId());
}
/**
* 预存款 20170822
*/
public function money_1()
{
$where1 = ' user_id=' . $this->user_id;
$current_money = M('users')->where($where1)->field('user_money')->find();
$locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
$liudong_money = number_format($current_money['user_money'] - $locking_money, 2); //流动资金
$yucun_money = 0; //预存款金额
$user = session('user');
$users = D("users")->where("user_id", $user['user_id'])->find(); //$user['user_id']
if (empty($users["erpvipid"])) {
return json(["code" => "-1", "msg" => "会员信息错误"]);
}
$id = $users["erpvipid"];
// $where["VIPId"] = array('=', $user["erpvipid"]);//$user["erpvipid"]
//$where["EndDate"]=array('egt',date('Y-m-d H:i:s',time()));
// $where["EndDate"]=array('=', "ISNULL(EndDate,'')");
$where = " VIPID='" . $user["erpvipid"] . "' and (ISNULL([VIP_AdvanceItemForm].EndDate,'')='' or [VIP_AdvanceItemForm].EndDate>='" . date('Y-m-d H:i:s', time()) . "')";
$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find();
$aa = getApiData("wxd.vip.advancelist", $tk['api_token'], null, $where);
$qlist = json_decode($aa, true);
//var_dump($qlist['data']);
if (!empty($qlist['data'])) {
foreach ($qlist['data'] as $k => $item) {
$item['order'] = $k % 4 + 1;
$item['Balance'] = 0.00 + $item['Balance'];
$list1[] = $item;
}
}
//有账套
if ($this->pm_erpid) {
$yucun_money = $this->getyucun();
}
$yucun_money = 0.00 + $yucun_money;
$amount_money = $liudong_money + $yucun_money;
$this->assign('yucun_money', $yucun_money == '' ? 0 : $yucun_money);
$this->assign('liudong_money', $liudong_money);
$this->assign('amount_money', $amount_money);
$this->assign('list', $list1);
return $this->fetch('', getMobileStoId());
}
/**
* 获取线下会员预存款(余额)
*/
public function getyucun()
{
$user = $this->user;
$user['api_token'] = tpCache('shop_info.api_token', $user['store_id']);
$where['VIPId'] = array('=', $user["erpvipid"]);//$user["erpvipid"]
$offinfo = getApiData("wxd.vip.balance", $user['api_token'], null, $where);
$offinfo = json_decode($offinfo, true);
upload_ylp_log('获取线下会员预存款(余额)');
if ($offinfo["data"] != null) {
$getvipsum = $offinfo["data"][0]["VIPSum"];
} else {
$getvipsum = 0;
}
return $getvipsum;
}
/**
* 预存款活动项
*/
public function yucunlist()
{
$store = I('stoid'); //商家ID
$accdb = tpCache('shop_info.ERPId', $store);
$data['VIPId'] = urlencode($this->user['erpvipid']);
$qlist = getApiData_java_p("api/erp/vip/addmoneyact/page", $accdb, $data, 1, 1000);
$qlist = json_decode($qlist, true);
$isnull = 0;
if (empty($qlist['data']["pageData"])) {
$isnull = 1;
}
upload_ylp_log('预存款活动项');
if ($qlist) {
if ($isnull) {
return json(["code" => "-1", "msg" => "未找到数据"]);
} else {
$res_data = $qlist['data']["pageData"];
$newdata = array();
$getnum = 0;
foreach ($res_data as $k => $v) {
$getshow = 1;
if ($v['sQty']) {
$getbuy_num = $v['sQty'];
} else {
$getbuy_num = $v['Qty'];
}
if ($getbuy_num > 0) {
$user_buy_count = M('recharge')->where(array('store_id' => $store, 'user_id' => $this->user_id, 'yucun_id' => $v['Id'], 'pay_status' => 1))->count();
if ($user_buy_count >= $getbuy_num) {
$getshow = 0;
}
}
//是否显示项目
if ($getshow) {
$newdata[$getnum]['Id'] = $v['Id'];
$newdata[$getnum]['StorageId'] = $v['StorageId'];
$newdata[$getnum]['AdvanceItemId'] = $v['AdvanceItemId'];
$newdata[$getnum]['ItemName'] = $v['ItemName'];
$newdata[$getnum]['BeginSum'] = $v['BeginSum'];
$newdata[$getnum]['Qty'] = $v['Qty'];
$newdata[$getnum]['EndSum'] = $v['EndSum'];
$newdata[$getnum]['NewSum'] = $v['NewSum'];
$newdata[$getnum]['PPPresentSum'] = $v['PPPresentSum'];
$newdata[$getnum]['begindate'] = $v['begindate'];
$newdata[$getnum]['enddate'] = $v['enddate'];
$getnum = $getnum + 1;
}
}
return json(["code" => "0", "msg" => "ok", "data" => $newdata]);
}
} else {
return json(["code" => "-1", "msg" => "获取接口数据错误"]);
}
}
/**
* 会员预存款详情
*/
public function vipyucunlist()
{
$user = session('user');
//$users = D("users")->where("user_id", "2641")->find();//$user['user_id']
$store = I('stoid'); //商家ID
$where["VIPId"] = array('=', $user["erpvipid"]);//$user["erpvipid"]
$tk = M("store")->where("store_id", $store)->field("api_token")->find();
$rs = getApiData("wxd.vip.advancelist", $tk['api_token'], null, $where);
$qlist = json_decode($rs, true);
$isnull = 0;
if (empty($qlist['data'])) {
$isnull = 1;
}
upload_ylp_log('会员预存款详情');
if ($rs) {
if ($isnull) {
return json(["code" => "-1", "msg" => "未找到数据"]);
} else {
return json(["code" => "0", "msg" => "ok", "data" => $qlist['data']]);
}
} else {
return json(["code" => "-1", "msg" => "获取接口数据错误"]);
}
}
/**
* 流动资金记录
*/
public function liudongrecord()
{
upload_ylp_log('流动资金记录');
try {
$stime = I("stime"); //开始时间
$etime = I("etime"); //结束时间
if (empty($etime)) {
$etime = date('Y-m-d', time());
$etime .= " 23:59:59";
} else {
$etime .= " 23:59:59";
}
$where = "";
$where1 = "";
if ($stime) {
$where .= " and create_time >= UNIX_TIMESTAMP('" . $stime . "')";
$where1 .= " and confirm >= UNIX_TIMESTAMP('" . $stime . "')";
}
if ($etime) {
$where .= " and create_time <= UNIX_TIMESTAMP('" . $etime . "')";
$where1 .= " and confirm <= UNIX_TIMESTAMP('" . $etime . "')";
}
$user = session('user');
$store = I('stoid'); //商家ID
$p = I('p');
$pcount = 10;
$count = Db::field('num')
->table('wxd_withdrawals')
->union("SELECT count(1) as num FROM wxd_rebate_log where status=3 and user_id=" . $user["user_id"] . " and store_id = " . $store . $where1)
->where("status<>2 and user_id = " . $user["user_id"] . " and store_id = " . $store . " " . $where)
->count();
$count = $count;
$first = $p * $pcount;
$sql1 = M('withdrawals')->where("status<>2 and user_id = " . $user["user_id"] . " and store_id = " . $store . $where)
->field('user_id,create_time AS time,money,order_sn,remark,store_id, type+1 as type,\'提现\' AS `intro`')
->buildSql();
$sql2 = M('rebate_log')->where("status=3 and user_id = " . $user["user_id"] . " and store_id = " . $store . $where)
->field('user_id,confirm AS time,money,order_sn,remark,store_id,0 AS type,\'分成\' AS intro')
->buildSql();
$sql = $sql1 . 'UNION' . $sql2 . ' ORDER BY time DESC LIMIT ' . $first . ',' . $pcount;//最终SQL语句
$recordlist = DB::query($sql);
if (empty($recordlist)) {
$jsonlist['state'] = "0";
$jsonlist['msg'] = '无数据';
} else {
$jsonlist['state'] = "1";
$jsonlist['msg'] = '成功';
}
$jsonlist['item'] = $recordlist;
return json($jsonlist);
} catch (HttpResponseException $exception) {
mlog($exception->getResponse(), "liudong");
return json(['state' => '-1']);
}
}
/**
* 不可用资金记录
*/
public function unablerecord()
{
upload_ylp_log('不可用资金记录');
$stime = I("stime"); //开始时间
$etime = I("etime"); //结束时间
$where = "";
if ($stime) {
$where .= " and create_time >=" . strtotime($stime);
}
if ($etime) {
$where .= " and create_time <= " . strtotime($etime);
}
$user = session('user');
$store = I('stoid'); //商家ID
$p = I('p');
$pcount = 10;
$first = $p * $pcount;
$wh = "user_id=" . $this->user_id . " and store_id=" . $store . " and status=2" . $where;
$count = M('rebate_log')->where($wh)->count();
/*--不可用金额--*/
$recordlist = M('rebate_log')->where($wh)->limit($first, $pcount)->select();
if (empty($recordlist)) {
$jsonlist['state'] = "0";
$jsonlist['msg'] = '无数据';
} else {
$jsonlist['state'] = "1";
$jsonlist['msg'] = '成功';
}
$jsonlist['item'] = $recordlist;
return json($jsonlist);
}
/**
* 预存款 新增 20170320
*/
public function pre_deposit()
{
return $this->fetch('', getMobileStoId());
}
/**
* 提现项目 新增 20170321
*/
public function withdrawals_project()
{
return $this->fetch('', getMobileStoId());
}
/**
* 提现记录 新增 20170321
*/
public function cash_record()
{
return $this->fetch();
}
/**
* 提现记录 20170506
*/
public function cashrecord()
{
try {
$stime = I("stime"); //开始时间
$etime = I("etime"); //结束时间
if (empty($etime)) {
$etime = date('Y-m-d', time());
}
$user = session('user');
$store = I('stoid'); //商家ID
$p = I('p');
$pcount = 5;
$count = DB::query("select count(1)as num from wxd_withdrawals WHERE type=0 and user_id = " . $user["user_id"] . " and store_id = " . $store . " and create_time >= UNIX_TIMESTAMP('" . $stime . "') and create_time <= UNIX_TIMESTAMP('" . $etime . " 23:59:59')");
$count = $count[0]["num"];
$page = $count / $pcount;
//if($count%$pcount>0)$page++;
$first = $p * $pcount;
$sql = "SELECT * FROM wxd_withdrawals WHERE type=0 and user_id = " . $user["user_id"] . " and store_id = $store and create_time >= UNIX_TIMESTAMP('" . $stime . "') and create_time <= UNIX_TIMESTAMP('" . $etime . " 23:59:59') ORDER BY create_time DESC LIMIT " . $first . "," . $pcount;
$recordlist = DB::query($sql);
if (empty($recordlist)) {
$jsonlist['state'] = "0";
$jsonlist['msg'] = '无数据';
} else {
$jsonlist['state'] = "1";
$jsonlist['msg'] = '成功';
}
$jsonlist['item'] = $recordlist;
$jsonlist['page'] = $page;
} catch (HttpResponseException $exception) {
//$data = $exception->getResponse();
mlog($exception->getResponse(), "cash");
}
upload_ylp_log('提现记录');
return json($jsonlist);
}
/**
* 根据卡号判断银行 20170508
*/
public function getbankname()
{
$length = strlen(input('get.bankno'));
try {
if (empty($length)) {
return json(array("code" => -1));
} else {
$bankno = I("bankno");
$newbankno = "";
for ($i = 0; $i < strlen($bankno); $i += 1) {
if ($bankno[$i] != ' ') $newbankno .= $bankno[$i];
}
if (strlen($newbankno) < 6) {
return "{\"code\":\"-1\"}";;
} //位数不够
$sql = "select * from wxd_bank_card where card_bin='" . substr($newbankno, 0, 6) . "' and card_digits='" . strlen($newbankno) . "'";
$res = Db::query($sql);
//mlog(implode(',',$res[0]),"bank");
if (empty($res[0])) {
return json(array("code" => 0)); //查找不到
} else {
mlog(implode(',', $res[0]), "bank");
return json(array("code" => 1, "bankname" => $res[0]["bank_name"]));
}
}
} catch (HttpResponseException $exception) {
mlog("报错:" . $exception->getResponse(), "bank");
return json(array("code" => -2));
}
}
//获取门店分类
public function ajax_get_category()
{
$stoid = I('stoid', 0);
$list = array();
//$res = D('storage_category')->where("store_id", $stoid)->select();
$res = Db::query("select a.*,IFNULL(b.num,0) as num from wxd_storage_category a left join (select count(1) as num,category_id from wxd_pick_up where isstop=0 and store_id=" . $stoid . " group by category_id) b on a.cat_id=b.category_id where a.store_id=" . $stoid . " and num>0");
foreach ($res as $val) {
$val['cat_id'] = $val['cat_id'];
$val['cat_name'] = urldecode($val['cat_name']);
$list[] = $val;
}
return json(array("code" => 1, "data" => $list));
}
//获取门店
public function ajax_get_pick()
{
$stoid = I('stoid', 0);
$category_id = I('category_id', 0);
$list = array();
$res = M('pick_up')->where(array("store_id" => $stoid, "category_id" => $category_id, "isstop" => 0))
->field('pickup_id,pickup_name')->select();
foreach ($res as $val) {
$val['pickup_id'] = $val['pickup_id'];
$val['pickup_name'] = urldecode($val['pickup_name']);
$list[] = $val;
}
return json(array("code" => 1, "data" => $list));
}
/*--访问接口获取会员信息 测试--*/
public function SelectUser()
{
//$user = session('user');
//$user = M("users")->alias("a")->join("store b", "a.store_id=b.stoir_id", "left")
//->where('a.user_id', $user['user_id'])->field('a.*,b.api_token')->find();
$user = $this->user;
$user['api_token'] = tpCache('shop_info.api_token', $user['store_id']);
if (empty($users["erpvipid"])) {
return json(["code" => "-1", "msg" => "会员信息错误"]);
}
$id = $users["erpvipid"];
$id = "{" . $id . "}";
$where['Id'] = array('=', $id);
/*-----
$store = I('stoid');
$tk = M("store")->where("store_id", $store)->field("api_token")->find();
$list = array("access_token" => "wxd.vip.vipinfo.list.get");
$array = array(
'token' => $tk['api_token'],
'data' => "",
'map' => $where,
'order' => "",
);
$json = json_encode($array);
$url = GetSignUrl($list);
if (empty($url)) {
return json(["code" => "-1", "msg" => "生成签名错误"]);
}
$rs = http_post_json($url, $json);
$qlist = json_decode(urldecode($rs[0]), true);---*/
$qlist = getApiData("wxd.vip.vipinfo.list.get", $user['api_token'], null, $where);
}
/**
* 优惠券列表
*/
public function coupon()
{
$store = I('stoid'); //商家ID
return $this->fetch('', $store);
}
public function coupons_sear()
{
$store = I('stoid'); //商家ID
$page = I('p/d', 1); //页数
$length = I('length/d', 10); //长度
$type = I('type/d', 0); //1已经使用,2已过期,3未使用
$start = I('start');
$end = I('end');
$user = $this->user;
$isnull = 0;//是否有记录
$return_data = array();
if ($this->pm_erpid) {
$accdb = tpCache("shop_info.ERPId", $store);
$where['VIPId'] = urlencode($user['erpvipid']);
$time = date('Y-m-d', time());
//所有
switch ($type) {
case 1://已经使用
$where['IsUse'] = 1;
break;
case 2://已过期
$where['IsUse'] = 2;
break;
default://未使用
$where['IsUse'] = 0;
break;
}
if (!empty($start)) {
$where['BeginDate'] = $start;
}
if (!empty($end)) {
$where['EndDate'] = $start;
}
$list = getApiData_java_p("/api/erp/vip/cash/page", $accdb, $where, $page, $length);
$qlist = json_decode($list, true);
if (empty($list) || empty($qlist['data']['pageData'])) {
$isnull = 1;
} else {
foreach ($qlist['data']['pageData'] as $k => $v) {
$qlist['data'][$k]['Sum'] = number_format($v['Sum'], 2);
if ($v['ValidDate'] != "") {
$qlist['data'][$k]['ValidDate'] = date('Y-m-d', strtotime($v['ValidDate']));
} else {
$qlist['data'][$k]['ValidDate'] = "不限";
}
if ($v['BeginDate'] != "")
$qlist['data'][$k]['BillDate'] = date('Y-m-d', strtotime($v['BeginDate']));
else
$qlist['data'][$k]['BillDate'] = "";
}
$return_data = $qlist['data']['pageData'];
}
} else {
$time = time();
$where = " uid=" . $user['user_id'];
switch ($type) {
case 1://已经使用
$where .= " and is_user=1";
break;
case 2://已过期
$where .= " and is_user=0 and (validtime is not null and validtime<>'' and validtime<='" . $time . "')";
break;
default://未使用
$where .= " and is_user=0 and (validtime is null or validtime='' or validtime>'" . $time . "')";
break;
}
if (!empty($start)) {
$where .= " and send_time>='" . strtotime($start) . "'";
}
if (!empty($end)) {
$end = strtotime($end . " 23:59:59");
$where .= " and send_time<='" . $end . "'";
}
$count = M('coupon_list')->where(array('store_id' => $store))->where($where)->count("id");
$Page = $pager = new Page($page, $length);// 实例化分页类 传入总记录数和每页显示的记录数
$qlist = M('coupon_list')->where(array('store_id' => $store))->where($where)
->limit($Page->firstRow . ',' . $Page->listRows)
->select();
if (empty($qlist)) {
$isnull = 1;
} else {
foreach ($qlist as $K => $v) {
$new_v['Remark'] = urldecode($v['remark']);
$new_v['Sum'] = number_format($v['sum'], 2);
if ($v['validtime']) {
$new_v['ValidDate'] = date('Y-m-d', $v['validtime']);
$t = $v['validtime'];
} else {
$new_v['ValidDate'] = "不限";
$t = "";
}
if ($v['begintime']) {
$new_v['BeginDate'] = date('Y-m-d', $v['begintime']);
} else {
$new_v['BeginDate'] = "";
}
$new_v['BillDate'] = date('Y-m-d', $v['send_time']);
$new_v['CashRepNo'] = $v['code'];
$return_data[] = $new_v;
}
}
}
$isshow = 0;
if ($qlist['count'] > $length * $page) {
$isshow = 1;
}
$this->assign("mshow", $isshow);
if (I('isajax')) {
if ($qlist) {
if ($isnull) {
return json(["code" => "-1", "msg" => "未找到数据"]);
} else {
return json(["code" => "0", "msg" => "ok", "data" => $return_data, 'isshow' => $isshow]);
}
} else {
return json(["code" => "-1", "msg" => "获取接口数据错误"]);
}
exit;
}
$this->assign("isnull", $isnull);
$this->assign("user_id", $this->user_id);
$this->assign("quanlist", $return_data);
return $this->fetch('', $store);
}
/**
* 确定订单的使用优惠券
* @author lxl
* @time 2017
*/
public function checkcoupon()
{
$cartLogic = new \app\home\logic\CartLogic();
// 找出这个用户的优惠券 没过期的 并且 订单金额达到 condition 优惠券指定标准的
$result = $cartLogic->cartList($this->user, $this->session_id, 1, 1); // 获取购物车商品
if (I('type') == '') {
$where = " c2.uid = {$this->user_id} and " . time() . " < c1.use_end_time and c1.condition <= {$result['total_price']['total_fee']} ";
}
if (I('type') == '1') {
$where = " c2.uid = {$this->user_id} and c1.use_end_time < " . time() . " or {$result['total_price']['total_fee']} < c1.condition ";
}
$coupon_list = DB::name('coupon')
->alias('c1')
->field('c1.name,c1.money,c1.condition,c1.use_end_time, c2.*')
->join('coupon_list c2', 'c2.cid = c1.id and c1.type in(0,1,2,3) and order_id = 0', 'LEFT')
->where($where)
->select();
$this->assign('coupon_list', $coupon_list); // 优惠券列表
return $this->fetch('', getMobileStoId());
}
/*--优惠券兑换列表--*/
public function exchange_coupons()
{
$erip = $this->pm_erpid;
if (empty($erip)) {
$quanlist = tpCache("shopping.quan_rate", getMobileStoId());
if ($quanlist) {
$quanlist = json_decode($quanlist, true);
foreach ($quanlist as $k => $v) {
$quanlist[$k]['Integral'] = intval($v['integral']);
$quanlist[$k]['ToSum'] = number_format(empty($v['sum']) ? 0 : $v['sum'], 2);
$quanlist[$k]['title'] = $quanlist[$k]['Integral'] . '积分兑换' . $quanlist[$k]['ToSum'] . '元微券';
}
$this->assign('buylist', $quanlist); // 优惠券列表
}
} else {
/*--获取规则--*/
//$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find();
//$rs = getApiData("wxd.vip.intertosum", $tk['api_token']);
$data['StorageId']=1;
$data['pageSize']=100;
$rs = getApiData_java_p("/api/erp/vip/integral/tosum/page",$this->pm_erpid,$data);
if ($rs) {
$d = json_decode($rs, true);
if($d && $d['code']===0 && $d['data']) $d['data']=$d['data']['pageData'];
if ($d['data']) {
foreach ($d['data'] as $k => $v) {
$v['Integral'] = intval($v['Integral']);
$d['data'][$k]['ToSum'] = number_format(empty($v['ToSum']) ? 0 : $v['ToSum'], 2);
$d['data'][$k]['title'] = $v['Integral'] . '积分兑换' . $d['data'][$k]['ToSum'] . '元微券';
}
$this->assign('buylist', $d['data']); // 优惠券列表
}
}
}
return $this->fetch();
}
/*--兑换券--*/
public function exchangecoup()
{
$money = I("money/f");
$integ = I("integ/d");
/*--查找用户--*/
//$user = M("users")->where('user_id', $this->user_id)->find();
/*--规则检验--*/
//$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find();
$user = $this->user;
$istrue = 0;
if (empty($this->pm_erpid)) {
$quanlist = tpCache("shopping.quan_rate", getMobileStoId());
if ($quanlist) {
$quanlist = json_decode($quanlist, true);
foreach ($quanlist as $k => $v) {
if ($money == $v['sum'] && $integ == $v['integral']) {
$istrue = 1;
break;
}
}
}
} else {
$user['api_token'] = tpCache('shop_info.api_token', $user['store_id']);
//$rs = getApiData("wxd.vip.intertosum", $user['api_token']);
$data['StorageId']=1;
$data['pageSize']=100;
$rs = getApiData_java_p("/api/erp/vip/integral/tosum/page",$this->pm_erpid,$data);
if ($rs) {
$d = json_decode($rs, true);
if($d && $d['code']===0 && $d['data']) $d['data']=$d['data']['pageData'];
foreach ($d['data'] as $k => $v) {
if ($money == $v['ToSum'] && $integ == $v['Integral']) {
$istrue = 1;
break;
}
}
}
}
if ($istrue == 0) {
$back = ["code" => -1, "msg" => '不存在该兑换项目'];
return json($back);
}
/*判断券是否充足*/
if (empty($this->pm_erpid)) {
$u_inte = $this->user['pay_points'];
if ($integ > $u_inte) {
$back = ["code" => -1, "msg" => '您的积分不足'];
return json($back);
}
} else {
//$uwhere['Id'] = array('=', $user['erpvipid']);
//$rs = getApiData("wxd.vip.vipinfo.list.get", $user['api_token'], null, $uwhere);
if(!$user['erpvipid']){
$back = ["code" => -1, "msg" => '未找到会员信息'];
return json($back);
}
$d=get_erpvipinfo($user['erpvipid'],$this->pm_erpid);
if ($d) {
$u = $d;
if ($integ > $u['Integral']) {
$back = ["code" => -1, "msg" => '您的积分不足'];
return json($back);
}
} else {
$back = ["code" => -1, "msg" => '未找到会员信息'];
return json($back);
}
}
$orderno = "1000" . date("ymdHis") . get_total_millisecond();
if (empty($this->pm_erpid)) {
//优惠券
//插入线上优惠券领取表
$coupon_list['cid'] = 0;
$coupon_list['type'] = 2;
$coupon_list['uid'] = $user['user_id'];
$coupon_list['send_time'] = time();
$coupon_list['code'] = $orderno;
$coupon_list['store_id'] = getMobileStoId();
$coupon_list['begintime'] = time();
$coupon_list['validtime'] = strtotime("+1 year", time());
$coupon_list['sum'] = $money;
$coupon_list['buysum'] = 0;
$coupon_list['remark'] = "积分兑换券";
$add_couponinfo = add_coupon($coupon_list, $user, $user['store_id']);
//积分对换券
accountLog($user["user_id"], 0, -$integ, "积分兑换券", 0, $user['store_id'], $user["pay_points"]);
$dd['code'] = 1;
$dd['msg'] = '代金券生成成功';
return json($dd);
} else {
$onlyorderno = '1000' . date('Ymd') . rand(1000, 9999) . date('siHL');
$data = array(['FromId' => $onlyorderno, 'CashRepNo' => $orderno,
'Sum' => $money, 'Integral' => -$integ, 'vipRemark' => $integ . '积分兑换' . $money . '元微券(无限制)',
'Remark' => $integ . '积分兑换' . $money . '元微券',
'Id' => $user['erpvipid']],);
$dd = getApiData("wxd.vip.intertocash", $user['api_token'], $data);
$dd = json_decode($dd, true);
if ($dd) {
if ($dd['code'] === 0 && $dd['msg'] == '代金券生成成功') {
$colorlist = urlencode("#FF0000|#173177|#173177|#173177|#173177|#173177|#FF0000|#ca003a");
$pd['typeid'] = "1006";
$pd['backurl'] = curHostURL() . '/index.php/Mobile/User/coupon/stoid/' . getMobileStoId();
$pd['colorlist'] = $colorlist;
$pd['title'] = "您好,恭喜您成功领取" . $money . "元优惠券";
$pd['key1'] = $this->user['vipname'];
$pd['key2'] = $money . "元优惠券";
$pd['key3'] = date("Y-m-d");
$pd['remark'] = "点击详情查看优惠券详情信息";
$Event = \think\Loader::controller('home/Api');
$Event->web_poswxcode($pd, getMobileStoId(), $this->user);
}
return json($dd);
} else {
return json(["code" => -1, "msg" => "兑换失败"]);
}
}
}
/*--积分明细--*/
public function detailed_sear()
{
$type = I('type/d');//收入支出
$start = I('start');//开始时间
$end = I('end');//结束时间
$user = $this->user;
$this->assign('stoid', getMobileStoId());
if ($this->pm_erpid) {
//收入支出
if ($type != '') {
if ($type == 1) {
$where["FInregral"] = 1;
} else {
$where["FInregral"] = 0;
}
}
if ($start && $end) {
$end = $end;
$where["BeginDate"] = $start;
$where["EndDate"] = $end;
} else {
if ($start) {
$where["BeginDate"] = $start;
}
if ($end) {
$where["EndDate"] = $end;
}
}
if ($user['erpvipid']) {
$where['VIPId'] = urlencode($user['erpvipid']);
$d = getApiData_java_p("/api/erp/vip/integral/list/page", $this->pm_erpid, $where, 1, 10);;
$d = json_decode($d, true);
if ($d) {
if ($d['data'] && $d['data']['pageData']) {
$list = array_slice($d['data']['pageData'], 0, 10);
foreach ($list as $ko => $vo) {
$list[$ko]['BillDate'] = date('Y-m-d H:i:s', strtotime($vo['BillDate']));
}
$this->assign("intlist", $list);
}
}
}
} else {
if (!empty($type)) {
if ($type == 1) {
$where["pay_points"] = array('gt', 0);
} else {
$where["pay_points"] = array('lt', 0);
}
}
if ($start && $end) {
$end = $end . " 23:59:59";
$where["change_time"] = [['egt', strtotime($start)], ['elt', strtotime($end)]];
} else {
if ($start) {
$where["change_time"] = ['egt', strtotime($start)];
}
if ($end) {
$end = $end . " 23:59:59";
$where["change_time"] = array('elt', strtotime($end));
}
}
//记录
$intlist = M('account_log')->where(array('store_id' => $user['store_id'], 'user_id' => $this->user_id))->where($where)->limit(0, 50)->order('change_time desc')->select();
if ($intlist) {
foreach ($intlist as $kl => $vl) {
$intlist[$kl]['BillDate'] = date('Y-m-d H:i:s', $vl['change_time']);
$intlist[$kl]['Remark'] = $vl['desc'];
$intlist[$kl]['InOutInt'] = $vl['pay_points'];
}
$this->assign("intlist", $intlist);
}
//
}
upload_ylp_log('积分明细');
return $this->fetch();
}
public function ajax_detailed_sear()
{
$type = I('type/d');//收入支出
$start = I('start');//开始时间
$end = I('end');//结束时间
$getp = I('p/d', 1);//页数
$user = $this->user;
$this->assign('stoid', getMobileStoId());
if ($this->pm_erpid) {
//收入支出
if ($type != '') {
if ($type == 1) {
$where["FInregral"] = 1;
} else {
$where["FInregral"] = 0;
}
}
if ($start && $end) {
$end = $end . " 23:59:59";
$where["BeginDate"] = $start;
$where["EndDate"] = $end;
} else {
if ($start) {
$where["BeginDate"] = $start;
}
if ($end) {
$where["EndDate"] = $end;
}
}
if ($user['erpvipid']) {
$where['VIPId'] = urlencode($user['erpvipid']);
$d = getApiData_java_p("/api/erp/vip/integral/list/page", $this->pm_erpid, $where, $getp, 10);;
$d = json_decode($d, true);
if ($d) {
if ($d['data'] && $d['data']['pageData']) {
$list = array_slice($d['data']['pageData'], 0, 10);
foreach ($list as $ko => $vo) {
$list[$ko]['BillDate'] = date('Y-m-d H:i:s', strtotime($vo['BillDate']));
}
$this->assign("intlist", $list);
}
}
}
} else {
if (!empty($type)) {
if ($type == 1) {
$where["pay_points"] = array('gt', 0);
} else {
$where["pay_points"] = array('lt', 0);
}
}
if ($start && $end) {
$end = $end . " 23:59:59";
$where["change_time"] = [['egt', strtotime($start)], ['elt', strtotime($end)]];
} else {
if ($start) {
$where["change_time"] = ['egt', strtotime($start)];
}
if ($end) {
$end = $end . " 23:59:59";
$where["change_time"] = array('elt', strtotime($end));
}
}
//记录
$intlist = M('account_log')->where(array('store_id' => $user['store_id'], 'user_id' => $this->user_id))->where($where)->limit(0, 50)->order('change_time desc')->select();
if ($intlist) {
foreach ($intlist as $kl => $vl) {
$intlist[$kl]['BillDate'] = date('Y-m-d H:i:s', $vl['change_time']);
$intlist[$kl]['Remark'] = $vl['desc'];
$intlist[$kl]['InOutInt'] = $vl['pay_points'];
}
$this->assign("intlist", $intlist);
}
//
}
return $this->fetch('', getMobileStoId());
}
/**账户积分*/
public function points()
{
$page = I('page/d', 1);
$length = I('length/d', 100);
$user = $this->user;
if ($this->pm_erpid)//账套
{
if ($user['erpvipid']) {
$where['VIPId'] = urlencode($user['erpvipid']);
$d = getApiData_java_p("/api/erp/vip/integral/list/page", $this->pm_erpid, $where, $page, $length);;
$d = json_decode($d, true);
if ($d) {
if ($d['data'] && $d['data']['pageData']) {
if ($d['data']['summary'] && $d['data']['summary']['InIntegral']) {
$getIntegral = $d['data']['summary']['InIntegral'];
if ($d['data']['summary']['OutIntegral']) {
$getIntegral = $getIntegral - $d['data']['summary']['OutIntegral'];
}
$vipinfo['Integral'] = $getIntegral;
$this->assign("vipinfo", $vipinfo);
}
$pdd = array_slice($d['data']['pageData'], 0, 5);
foreach ($pdd as $kl => $vl) {
$pdd[$kl]['BillDate'] = date('Y-m-d H:i:s', strtotime($vl['BillDate']));
}
$this->assign("intlist", $pdd);
}
}
}
/*--充值购买列表--*/
$rs = getApiData_java_p("/api/erp/vip/integral/tosum/list", $this->pm_erpid, null, $page, $length);
if ($rs) {
$d = json_decode($rs, true);
if ($d) {
if ($d['data']) {
foreach ($d['data'] as $k => $v) {
$d['data'][$k]['Integral'] = number_format(empty($v['Integral']) ? 0 : $v['Integral'], 0);
$d['data'][$k]['ToSum'] = number_format(empty($v['ToSum']) ? 0 : $v['ToSum'], 2);
$d['data'][$k]['title'] = '充值' . $d['data'][$k]['Integral'] . '积分';
}
$this->assign('buylist', $d['data']); // 优惠
}
}
}
$this->assign("clist", $d);
} else {
$news_user = M("users")->where('user_id', $this->user_id)->field('pay_points')->find();
$news_userinfo['Integral'] = $news_user['pay_points'];
$this->assign("vipinfo", $news_userinfo);
//记录
$intlist = M('account_log')->where(array('store_id' => $user['store_id'], 'user_id' => $this->user_id))->limit(0, 10)->order('change_time desc')->select();
if ($intlist) {
foreach ($intlist as $kl => $vl) {
$intlist[$kl]['BillDate'] = date('Y-m-d H:i:s', $vl['change_time']);
$intlist[$kl]['Remark'] = $vl['desc'];
if ($vl['pay_points'] > 0) {
$intlist[$kl]['InOutInt'] = $vl['pay_points'];
} else {
$intlist[$kl]['OutIntegral'] = $vl['pay_points'];
}
}
$this->assign("intlist", $intlist);
}
/*--充值购买列表--*/
$point_rate = json_decode(tpCache('shopping.point_rate', getMobileStoId()), true);
$getIntegral = 0;
$getToSum = 0;
if ($point_rate['money']) {
$getToSum = $point_rate['money'];
}
if ($point_rate['integral']) {
$getIntegral = $point_rate['integral'];
}
if ($getIntegral && $getToSum) {
$buylist[0]['ToSum'] = $getToSum;
$buylist[0]['Integral'] = $getIntegral;
$buylist[0]['title'] = '充值' . $getIntegral . '积分';
$this->assign('buylist', $buylist);
}
}
return $this->fetch('', getMobileStoId());
}
//注册,邀请赠送优惠券,测试
public function zs_coupon($userid, $stoid)
{
//注册赠送优惠券
$coupon = M("coupon")->where("store_id", $stoid)->where("type", 2)->find();
$userinfo = M("users")->where("user_id", 2662)->find();
$tk = M("store")->where("store_id", $stoid)->field("api_token")->find();
if ($coupon["send_end_time"] > time()) {
$CashRepNo = date('Ymd') . rand(1000, 9999) . date('siH');
$data = array(
'CashRepNo' => $CashRepNo,//券号
'VIPId' => $userinfo["erpvipid"],//会员id
'Sum' => $coupon["money"],//金额
'Operator' => '微信商城',//来源
'ValidDate' => date('Y-m-d H:i:s', $coupon["use_end_time"]),//截止期限
'BuySum' => $coupon["condition"],//满多少才能使用
);
if ($coupon['useobjecttype']) {
$data['UseObjectType'] = $coupon['useobjecttype'];
$data['UseObjectID'] = $coupon['useobjectid'];
$data['UseObjectNo'] = $coupon['useobjectno'];
$data['UseObjectName'] = $coupon['useobjectname'];
}
$aa = getApiData("wxderp.cashreplace.add", $tk['api_token'], array($data));
$add_rs = [$aa, 1];
if (!$add_rs[0]) {
return array('status' => -1, 'msg' => '服务器繁忙, 请联系管理员!');
}
$add_qlist = json_decode(urldecode($add_rs[0]), true);
// //如果插入不成功,报错
// if($add_qlist['code'] != 1 ){
// return array('status'=>-1,'msg'=>'绑定失败!');
// }
}
//邀请赠送优惠券
$p_coupon = M("coupon")->where("store_id", $stoid)->where("type", 3)->find();
$userinfo = M("users")->where("user_id", 2662)->find();
if ($userinfo["first_leader"] != 0 && $coupon["send_end_time"] > time()) {
$p_userinfo = M("users")->where("user_id", $userinfo["first_leader"])->find();
$p_CashRepNo = date('Ymd') . rand(1000, 9999) . date('siH');
//$tk = M("store")->where("store_id", $stoid)->field("api_token")->find();
$data = array(
'CashRepNo' => $p_CashRepNo,//券号
'VIPId' => $p_userinfo["erpvipid"],//会员id
'Sum' => $p_coupon["money"],//金额
'Operator' => '微信商城',//来源
'ValidDate' => date('Y-m-d H:i:s', $p_coupon["use_end_time"]),//截止期限
'BuySum' => $p_coupon["condition"],//满多少才能使用
);
if ($coupon['useobjecttype']) {
$data['UseObjectType'] = $p_coupon['useobjecttype'];
$data['UseObjectID'] = $p_coupon['useobjectid'];
$data['UseObjectNo'] = $p_coupon['useobjectno'];
$data['UseObjectName'] = $p_coupon['useobjectname'];
}
/*----
$list = array("access_token" => "wxderp.cashreplace.add");
$array = array(
'token' => $tk['api_token'],
'data' => array($data),
'map' => '',
'order' => "",
);
$json = json_encode($array);
$url = GetSignUrl($list);
if (empty($url)) {
return array('status'=>-1,'msg'=>'生成签名错误!');
}
$add_rs = http_post_json($url, $json);
if (!$add_rs[0]) {
return array('status'=>-1,'msg'=>'服务器繁忙, 请联系管理员!');
}
$add_qlist = json_decode(urldecode($add_rs[0]), true);---*/
$add_qlist = getApiData("wxderp.cashreplace.add", $tk['api_token'], array($data));
// //如果插入不成功,报错
// if($add_qlist['code'] != 1 ){
// return array('status'=>-1,'msg'=>'绑定失败!');
// }
}
}
/*--多图片上传--退款--*/
public function my_up_load()
{
$id = I('id');
$xmlstr = file_get_contents('php://input');
$jpg = $xmlstr;//得到post过来的二进制原始数据
if (empty($jpg)) {
echo '-1';
exit();
}
$type = null;
/*---
if (strpos($jpg, 'png') !== false || strpos($jpg, 'PNG') !== false) {
$type = '.png';
}
if (strpos($jpg, 'JPEG') !== false || strpos($jpg, 'JPG') !== false || strpos($jpg, 'jpeg') !== false
|| strpos($jpg, 'jpg') !== false || strpos($jpg, 'JFIF') !== false || strpos($jpg, 'jfif') !== false
) {
$type = '.jpg';
}
if (strpos($jpg, 'gif') !== false || strpos($jpg, 'GIF') !== false) {
$type = '.gif';
}---*/
$type = getFileType($xmlstr);
$now = time();
$filename = $now . rand(1000000, 9999999) . '.' . $type;
$datapath = '/public/upload/return_goods/' . $this->user_id . '/' . date('Y', $now) . '/' . date('m-d', $now);
$save_url = ROOT_PATH . $datapath;
if (!file_exists($save_url)) {
mkdir($save_url, 0777, true);
}
$path = $save_url . '/' . $filename;
$datasave = $datapath . '/' . $filename;
//保存到存储云
vendor('qcloudcos.myqcloudcos');
$resfolder = Myqcloudcos::statFolder('wxd', $datapath);
if ($resfolder && $resfolder['code'] != 0)//不存在创建
{
Myqcloudcos::createFolder('wxd', $datapath);
}
$file = fopen($path, "w");//打开文件准备写入
fwrite($file, $xmlstr);//写入
fclose($file);//关闭
/*--剪切图片--*/
m_cut_img($filename, $save_url . '/', 600);
$rs = M('return_goods')->where('id', $id)->find();
$img = $rs['imgs'];
$img .= $datasave . ',';
$data = ['imgs' => $img];
//腾讯云
$res = Myqcloudcos::upload('wxd', $path, $datasave);
if ($res && $res['code'] == 0)//成功
{
mdelFile($path);
}
mlog($img, 'myupload');
$rs = M('return_goods')->where('id', $id)->save($data);
echo '0';
exit();
}
/*--多图片上传--评价--*/
public function comment_up_load()
{
$id = I('id');
$xmlstr = file_get_contents('php://input');
$jpg = $xmlstr;//得到post过来的二进制原始数据
if (empty($jpg)) {
echo '-1';
exit();
}
$type = null;
/*--
if (strpos($jpg, 'png') !== false || strpos($jpg, 'PNG') !== false) {
$type = '.png';
}
if (strpos($jpg, 'JPEG') !== false || strpos($jpg, 'JPG') !== false || strpos($jpg, 'jpeg') !== false
|| strpos($jpg, 'jpg') !== false || strpos($jpg, 'JFIF') !== false || strpos($jpg, 'jfif') !== false
) {
$type = '.jpg';
}
if (strpos($jpg, 'gif') !== false || strpos($jpg, 'GIF') !== false) {
$type = '.gif';
}---*/
$type = getFileType($xmlstr);
$now = time();
$filename = $now . rand(1000000, 9999999) . '.' . $type;
$datapath = '/public/upload/comment/' . $this->user_id . '/' . date('Y', $now) . '/' . date('m-d', $now);
$save_url = ROOT_PATH . $datapath;
if (!file_exists($save_url)) {
mkdir($save_url, 0777, true);
}
$path = $save_url . '/' . $filename;
$datasave = $datapath . '/' . $filename;
//保存到存储云
vendor('qcloudcos.myqcloudcos');
$resfolder = Myqcloudcos::statFolder('wxd', $datapath);
if ($resfolder && $resfolder['code'] != 0)//不存在创建
{
Myqcloudcos::createFolder('wxd', $datapath);
}
$file = fopen($path, "w");//打开文件准备写入
fwrite($file, $xmlstr);//写入
fclose($file);//关闭
/*--剪切图片--*/
m_cut_img($filename, $save_url . '/', 600);
//腾讯云
$res = Myqcloudcos::upload('wxd', $path, $datasave);
if ($res && $res['code'] == 0)//成功
{
mdelFile($path);
}
$rs = M('comment')->where('comment_id', $id)->find();
$img = unserialize($rs['img']);
$img[] = $datasave;
$data = ['img' => serialize($img)];
mlog($img, 'comment');
$rs = M('comment')->where('comment_id', $id)->save($data);
echo '0';
exit();
}
///判断会员是否是分销商
public function is_distribut()
{
$stoid = getMobileStoId();
$user_id = $this->user_id;
if ($user_id == 0) {
return json(array('status' => -1));
}
$distribut = tpCache('distribut', $stoid);
if (!$distribut) {
return json(array('status' => -2));//未启用分销商
}
if ($distribut && $distribut['switch'] == 1) {
//注册会员不足判断
$rs = $this->user;
if (($this->pm_erpid && empty($rs['erpvipid'])) || (empty($this->pm_erpid) && empty($rs['mobile']))) {
return json(array('status' => -1));
}
if ($rs['is_distribut'] == 1) {
return array('status' => 1);
} else {
$ty = M('store_distribut')->where('store_id', $stoid)->field('distribut_num')->find();
$count1 = M("users")->where('store_id', $stoid)->where('is_distribut', 1)->count();
//是否有购买
$is_out = M("store_module_endtime")
->where('store_id', getMobileStoId())
->where('type', 2)->find();
if ($is_out) {
if (empty($ty['distribut_num'])) {
return json(array('status' => -3, 'msg' => '商家分销功能已过期'));
}
if ($ty['distribut_num'] <= $count1) {
return json(array('status' => -3, 'msg' => '当前版本的分销会员已满'));
}
} else {
//看体验人数是否到了
$yy = M('distri_price')->where('type', 0)->where('money', 0)->find();
$allnum = $yy['user_num'];
if ($allnum <= $count1) {
return json(array('status' => -3, 'msg' => '当前版本的分销会员已满'));
}
}
switch ($distribut['condition']) {
case 0:
if ($this->user['is_distribut'] != 1
&& !empty($this->user['mobile'])
) {
M('users')->where('store_id', $stoid)->where('user_id', $user_id)
->save(array('is_distribut' => 1, 'be_distribut_time' => time(), 'be_dis_condition' => "直接成为分销商"));
//M('store_distribut')->where('store_id', $stoid)->setDec('distribut_num');
}
return json(array('status' => 1));//绑定成为分销商
case 1:
$data = array(
'condition_money' => $distribut['condition_money'],
'condition_explain' => $distribut['condition_explain'],
);
return json(array('status' => 0, 'data' => $data));
case 2:
$gnd = M('goods')->where('goods_id', $distribut['condition_goods_id'])->field('goods_name')->find();
$goods_name = $gnd['goods_name'];
$data = array(
'condition_goods_name' => $goods_name,
'condition_goods_id' => $distribut['condition_goods_id'],
'condition_explain' => $distribut['condition_explain'],
);
return json(array('status' => 2, 'data' => $data));
case 3:
$gnd = M('goods')->where('goods_id', $distribut['condition_goods_id'])->field('goods_name')->find();
$goods_name = $gnd['goods_name'];
$data = array(
'condition_money' => $distribut['condition_money'],
'condition_goods_name' => $goods_name,
'condition_goods_id' => $distribut['condition_goods_id'],
'condition_explain' => $distribut['condition_explain'],
);
return json(array('status' => 3, 'data' => $data));
}
}
} else {
return json(array('status' => -2));//未启用分销商
}
}
public function getwuliu()
{
$bh = I('bh');
$com = I('com');
if (empty($bh) || empty($com)) {
return json(['code' => -1, 'msg' => '传递参数有误']);
}
$shippinfo = M('shipping')->where(array('shipping_code' => $com))->find();
if (empty($shippinfo)) {
return json(['code' => -1, 'msg' => '找不到物流代码失败']);
}
$EBusinessID = "1350455";
$AppKey = "33d719fd-b827-4ca7-bbcb-fe08102361f8";
$ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
$requestData = "{'OrderCode':'','ShipperCode':'" . $shippinfo['new_shipping_code'] . "','LogisticCode':'" . $bh . "'}";
$datas = array(
'EBusinessID' => $EBusinessID,
'RequestType' => '1002',
'RequestData' => urlencode($requestData),
'DataType' => '2',
);
$datas['DataSign'] = $this->encrypt($requestData, $AppKey);
$result = httpRequest($ReqURL, "POST", $datas);
$data = json_decode($result, true);
if ($data['Success'] != "true") {
return json(['code' => -1, 'msg' => $data['Reason']]);
} else {
return json(['code' => 0, 'msg' => 'ok', 'state' => $data['State'], 'data' => $data['Traces']]);
}
}
/**
* 电商Sign签名生成
* @param data 内容
* @param appkey Appkey
* @return DataSign签名
*/
function encrypt($data, $appkey)
{
return urlencode(base64_encode(md5($data . $appkey)));
}
/*--订单确认--*/
public function ordercheck()
{
$sn = I('ordsn');
$order = M('order')->where('order_sn', $sn)->find();
if ($order['parent_sn'] != $sn) {
$rs = M('order')->where('order_sn', $sn)->save(['parent_sn' => $sn]);
if ($rs) {
return json(['code' => 1]);
} else {
return json(['code' => -1]);
}
} else {
return json(['code' => 1]);
}
}
//服务卡-订购
public function shopping_card()
{
//$user_info = M('users')->alias('a')
// ->join('store b', 'a.store_id=b.store_id', 'left')
//->field('a.*,b.api_token')
//->where("a.user_id", $this->user_id)->find();
$user_info = M('users')->where("user_id", $this->user_id)->find();
$user_info['api_token'] = tpCache("shop_info.api_token", getMobileStoId());
$category_x_list = '';
$category_b_list = '';
$category__list = '';
$shop_list = '';
$server_cardlist = '';
if ($user_info) {
$alllist = getApiData('wxd.pos.prcsmexec.list', $user_info['api_token'], null);
mlog($alllist, "shopping_card/" . getMobileStoId());
// $alllist='{"code":1,"msg":"\u670d\u52a1\u5361\u63a5\u53e3\u83b7\u53d6\u6210\u529f","count":"","data":[{"itemtype":"{\"SMItem\":[{\"xzno\":\"01\",\"xzname\":\"\u6d4b\u8bd5\u5361\"}],\"SMItemType\":[{\"xzno\":\"01\",\"xzname\":\"\u6b21\u5361\"}]}","itemlist":"{\"itemlist\":[{\"id\":\"4FF9E5E4-5ED3-4AEF-AB33-3EC47D91D62A\",\"price\":\"1.00\",\"qty\":\"10.00\",\"storageid\":\"\",\"enddate\":\"180\",\"servername\":\"\u6d4b\u8bd5\u7f8e\u7532\",\"xmno\":\"01\",\"xmname\":\"\u6d4b\u8bd5\u5361\",\"kno\":\"01\",\"kname\":\"\u6b21\u5361\",\"remark\":\"\"},{\"id\":\"71A10FAF-667A-4E6D-A553-2CC1DD729977\",\"price\":\"500.00\",\"qty\":\"55.00\",\"storageid\":\"E3DBBCD1-9649-49F1-8E66-03EC66A01EC9\",\"enddate\":\"9999\",\"servername\":\"\u901a\u5929\u5854\",\"xmno\":\"01\",\"xmname\":\"\u6d4b\u8bd5\u5361\",\"kno\":\"01\",\"kname\":\"\u6b21\u5361\",\"remark\":\"\"},{\"id\":\"9E717E7C-14B0-47B6-8750-B89228E1868E\",\"price\":\"1.00\",\"qty\":\"1.00\",\"storageid\":\"\",\"enddate\":\"1\",\"servername\":\"\u6d4b\u8bd5\u6d17\u8138\u5361\",\"xmno\":\"01\",\"xmname\":\"\u6d4b\u8bd5\u5361\",\"kno\":\"01\",\"kname\":\"\u6b21\u5361\",\"remark\":\"\"},{\"id\":\"ECC38232-1F24-45C6-8686-16B669055BFA\",\"price\":\"50.00\",\"qty\":\"4.00\",\"storageid\":\"\",\"enddate\":\"30\",\"servername\":\"555\",\"xmno\":\"01\",\"xmname\":\"\u6d4b\u8bd5\u5361\",\"kno\":\"01\",\"kname\":\"\u6b21\u5361\",\"remark\":\"\"}]}","stolist":"{\"stolist\":[{\"id\":\"{C5041C55-3B03-4CA2-8B4F-C03011C2748B}\",\"storagename\":\"\u4e3b\u4ed3\u5e9312\"},{\"id\":\"CE41D033-DEF6-4CB7-9D4E-AA6DDE634147\",\"storagename\":\"\u95e8\u5e973\"},{\"id\":\"86A33F6B-6073-40E4-8053-8F4420E18EFB\",\"storagename\":\"\u5c0f\u5c0f\u5929\u5730\"},{\"id\":\"7D1F064A-7E97-4A23-8E20-6B2B27D55968\",\"storagename\":\"\u95e8\u5e971\"},{\"id\":\"8CD88334-099E-4B1B-8A04-4A0C78BDBBD6\",\"storagename\":\"\u95e8\u5e97222\"},{\"id\":\"8D4F4442-6B11-4234-B123-CD44A19E801F\",\"storagename\":\"\u9ec4\"},{\"id\":\"E3DBBCD1-9649-49F1-8E66-03EC66A01EC9\",\"storagename\":\"\u5c0f\u90d1\u95e8\u5e97\"},{\"id\":\"D5E2C6A1-A97D-4DB0-94D0-11883E813B83\",\"storagename\":\"\u53a6\u95e8\u5e97\"},{\"id\":\"EBBFE6B6-D70D-4268-AE49-A04781636C38\",\"storagename\":\"\u798f\u5dde\u5e97\"},{\"id\":\"AC9B0E96-2588-4F78-A814-A419EF6D57E9\",\"storagename\":\"\u8386\u7530\u5e97\"},{\"id\":\"775AC444-7BC4-421A-9784-DC8829D6BF00\",\"storagename\":\"\u4e3d\u6e90\u65e5\u5316\"},{\"id\":\"CAA71F97-5D08-46C5-B719-D2ECB4203A9F\",\"storagename\":\"\u53d1\u5149\"}]}","uselist":"","buylist":""}]}';
$alllist = json_decode($alllist, true);
if (!empty($alllist)) {
if ($alllist['code'] == 1) {
$alllist = $alllist['data'][0];
$category_x_list = json_decode($alllist['itemtype'], true)['SMItem']; //类型
$category_b_list = json_decode($alllist['itemtype'], true)['SMItemType']; //类别
$server_cardlist = json_decode($alllist['itemlist'], true)['itemlist']; //服务卡项目
if (!empty($server_cardlist)) {
foreach ($server_cardlist as $k1 => $v1) {
$server_cardlist[$k1]['enddate'] = date('Y-m-d ', time() + $v1['enddate'] * 24 * 3600);
}
}
$shop_list = json_decode($alllist['stolist'], true)['stolist']; //门店
}
}
// $mapuser['XZType'] ='SMItem';
// $category_x = getApiData('wxd.pos.smalllist.list.get', $user_info['api_token'], null, $mapuser); //类型
// $category_x=json_decode($category_x,true);
// if($category_x && $category_x["code"] ==1 ){
// $category_x_list=$category_x['data'];
// }
//
// $mapuser['XZType'] ='SMItemType';
// $category_b = getApiData('wxd.pos.smalllist.list.get', $user_info['api_token'], null, $mapuser); //类别
// $category_b=json_decode($category_b,true);
// if($category_b && $category_b["code"] ==1 ){
// $category_b_list=$category_b['data'];
// }
//
// $category_c = getApiData('wxd.base.storages.list.get', $user_info['api_token'], null); //门店
// $category_c=json_decode($category_c,true);
// if($category_c && $category_c["code"] ==1 ){
// $shop_list=$category_c['data'];
// }
//
// unset($mapuser);
// $cardlist = getApiData('wxd.pos.smitemanage.list.get', $user_info['api_token'], null); //服务卡项目
// $cardlist=json_decode($cardlist,true);
// if($cardlist && $cardlist["code"] ==1 ){
// $server_cardlist=$cardlist['data'];
// if(!empty($server_cardlist))
// {
// foreach ($server_cardlist as $k1=>$v1){
// $server_cardlist[$k1]['EndDate']=date('Y-m-d ',time()+$v1['EndDate']*24*3600);
// }
// }
//
// }
}
//$category_x = getApiData('wxd.pos.smalllist.list.get', $user_info['api_token'], null);// 类别:smalllist 购卡记录:smbuyitem 服务卡项目:smitemanage
$this->assign("clist_x", $category_x_list);
$this->assign("clist_b", $category_b_list);
$this->assign("clist_c", $shop_list);
$this->assign('cardlist', $server_cardlist);
$this->assign("clist_x1", json_encode($category_x_list));
$this->assign("clist_b1", json_encode($category_b_list));
$this->assign('cardlist1', json_encode($server_cardlist));
return $this->fetch('', getAdmStoId());
}
//线下订单
public function offline_order()
{
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name')
->where("a.user_id", $this->user_id)->find();//调取api_token
$stime = I('stime');//起始时间
$etime = I('etime');//结束时间
$ajax = I('isajax');//ajax传值
$pagenum = I('morepage');//页数
if ($ajax == 'isajax') {
$user_id = $this->user_id;//会员号码
$where['VIPId'] = $user_info['erpvipid'];//会员id
if ($stime && empty($etime)) {//只有开始时间
$where['PosDay'] = array('egt', $stime);
}
if ($etime && empty($stime)) {//只有结束时间
$where['PosDay'] = array('elt', $etime);
}
if ($stime && $etime) {//2个时间
$where['PosDay'] = array('between', [$stime, $etime]);
}
mlog(json_encode($where), "offline_order/" . $user_info['store_id']);
$offline = getApiData('wxd.mshop.pos.list.get', $user_info['api_token'], null, $where, $pagenum, 10, '');
$offline = json_decode($offline, true);
$ordnum = ceil($offline['count'] / 10);
if (!empty($offline['data'])) {
foreach ($offline['data'] as $key => $value) {
$offline['data'][$key]['Sum'] = number_format($offline['data'][$key]['Sum'], 2);
foreach ($offline['data'][$key]['data_list'] as $v => $value) {
$offline['data'][$key]['data_list'][$v]['Price'] = number_format($offline['data'][$key]['data_list'][$v]['Price'], 2);
$offline['data'][$key]['data_list'][$v]['Sum'] = number_format($offline['data'][$key]['data_list'][$v]['Sum'], 2);
}
}
}
if ($offline['code'] == 1 && $offline['count'] == null || $offline['data'] == null) {
//无数据
return json(["code" => -1, "msg" => "没有线下订单", "ordnum" => $ordnum, "data" => $offline]);
}
if ($offline['code'] == 1 && $offline['count'] && $offline['count'] <= 10 && $offline['count'] > 0 && $pagenum == 1) {
//有数据只有一页
return json(["code" => 1, "msg" => "存在线下订单", "ordnum" => $ordnum, "data" => $offline]);
}
if ($offline['code'] == 1 && $offline['count'] && $offline['count'] > 10 && $pagenum >= 1) {
//有数据多页
return json(["code" => 2, "msg" => "加载更多", "ordnum" => $ordnum, "data" => $offline]);
}
}
return $this->fetch();
}
//服务卡-已购
public function shopping_hascard()
{
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token')
->where("a.user_id", $this->user_id)->find();
$category_x_list = '';
$category__list = '';
$shop_list = '';
$server_cardlist = '';
$vip_uselist = '';
if ($user_info) {
$mapuser['vipid'] = $user_info['erpvipid'];
$alllist = json_decode(getApiData('wxd.pos.prcsmexec.list', $user_info['api_token'], null, $mapuser), true);
//var_dump($alllist);
if (!empty($alllist)) {
if ($alllist['code'] == 1) {
$alllist = $alllist['data'][0];
$category_x_list = json_decode($alllist['itemtype'], true)['SMItem']; //类型
$category_b_list = json_decode($alllist['itemtype'], true)['SMItemType']; //类别
$server_cardlist = json_decode($alllist['buylist'], true); //会员服务卡项目
if (!empty($server_cardlist)) {
foreach ($server_cardlist as $k => $item) {
$t = 0;
if ($server_cardlist[$k]['enddate'] != '' && strtotime(date('y-m-d')) > strtotime($server_cardlist[$k]['enddate'])) {
$t = 1;
}
$server_cardlist[$k]['isgq'] = $t;
}
}
$shop_list = json_decode($alllist['stolist'], true)['stolist']; //门店
$vip_uselist = json_decode($alllist['uselist'], true); //消费记录
}
}
// var_dump($category_x_list);
// var_dump($category_b_list);
// var_dump($server_cardlist);
// var_dump($shop_list);
// var_dump($vip_uselist);
// $mapuser['XZType'] ='SMItem';
// $category_x = getApiData('wxd.pos.smalllist.list.get', $user_info['api_token'], null, $mapuser); //类型
// $category_x=json_decode($category_x,true);
// if($category_x && $category_x["code"] ==1 ){
// $category_x_list=$category_x['data'];
// }
//
// $mapuser['XZType'] ='SMItemType';
// $category_b = getApiData('wxd.pos.smalllist.list.get', $user_info['api_token'], null, $mapuser); //类别
// $category_b=json_decode($category_b,true);
// if($category_b && $category_b["code"] ==1 ){
// $category_b_list=$category_b['data'];
// }
//
// $category_c = getApiData('wxd.base.storages.list.get', $user_info['api_token'], null); //门店
// $category_c=json_decode($category_c,true);
// if($category_c && $category_c["code"] ==1 ){
// $shop_list=$category_c['data'];
// }
//
// unset($mapuser);
// $mapuser['VIPid']=$user_info['erpvipid'];
// $cardlist = getApiData('wxd.pos.smbuyitem.list.get', $user_info['api_token'], null, $mapuser); //购卡项目
// $cardlist=json_decode($cardlist,true);
// if($cardlist && $cardlist["code"] ==1 ){
// $server_cardlist=$cardlist['data'];
//
// if(!empty($server_cardlist))
// {
// foreach ($server_cardlist as $k=>$item)
// {
// $t=0;
// if($server_cardlist[$k]['EndDate']!='' && strtotime(date('y-m-d'))>strtotime($server_cardlist[$k]['EndDate']))
// {
// $t=1;
// }
// $server_cardlist[$k]['isgq']=$t;
// }
// }
//
//
// }
//
// $uselist = getApiData('wxd.pos.smuseitem.list.get', $user_info['api_token'], null); //服务卡消费记录
// $uselist=json_decode($uselist,true);
// if($uselist && $uselist["code"] ==1 ){
// $vip_uselist=$uselist['data'];
//
// }
}
//$category_x = getApiData('wxd.pos.smalllist.list.get', $user_info['api_token'], null);// 类别:smalllist 购卡记录:smbuyitem 服务卡项目:smitemanage
$this->assign("clist_x", $category_x_list);
$this->assign("clist_b", $category_b_list);
$this->assign("clist_c", $shop_list);
$this->assign('cardlist', $server_cardlist);
$this->assign("clist_x1", json_encode($category_x_list));
$this->assign("clist_b1", json_encode($category_b_list));
$this->assign('cardlist1', json_encode($server_cardlist));
$this->assign('vipuselist', empty($vip_uselist) ? '' : json_encode($vip_uselist));
return $this->fetch('', getAdmStoId());
}
public function voiceVerify()
{
$param = I('post.');
// $param = [
// "stoid" => '1',
// "verifyCode" => '1234',
// "playTimes"=> "2", //播放次数
// "to"=> '15559135165', //手机号
// "displayNum"=> "4000879077",
// "welcomePrompt"=>"huanying.wav",
//// "maxCallTime"=>"60",
//// "respUrl"=>'', //语音验证码状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知
// "lang"=>"zh", //语言
// ];
$verifyCode = $param['verifyCode']; //验证码内容,为数字和英文字母,不区分大小写,长度4-8位
$playTimes = $param['playTimes'];//播放次数,1-3次
$to = $param['to']; //接收号码
$displayNum = $param['displayNum'];//示的主叫号码
$respUrl = $param['respUrl']; //语音验证码状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知
$lang = $param['lang'];//语言类型。取值en(英文)、zh(中文),默认值zh。
$userData = $param['userData'];//第三方私有数据
// 初始化REST SDK
// Vendor('VoiceVerifySDK.CCPRestSDK');
include_once(ROOT_PATH . "/vendor/VoiceVerifySDK/CCPRestSDK.php");
$rest = new \REST(v_serverIP, v_serverPort, v_softVersion);
$rest->setAccount(v_accountSid, v_accountToken);
$rest->setAppId(v_appId);
//调用语音验证码接口
$result = $rest->voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl, $lang, $userData);
if ($result == NULL) {
return json(['status' => -1, 'msg' => '请求语音信息错误!']);
}
if ($result->statusCode != 0) {
return json(['status' => -1, 'msg' => $result->statusMsg]);
} else {
return json(['status' => 1, 'msg' => '发送成功,稍后您将接到电话语音验证码!']);
// $voiceVerify = $result->VoiceVerify;
// 'callSid'=>$voiceVerify->callSid,
// 'dateCreated'=>$voiceVerify->dateCreated,
}
}
//--购买等级卡界面--
public function vipcard()
{
$stoid = getMobileStoId();
$rank_switch = tpCache('shopping.rank_switch', $stoid);//等级开关
if (empty($rank_switch)) {
$this->error('商家还未开启plus功能', U('User/index', array('stoid' => $stoid)));
}
$userinfo = M('users')->where(array('store_id' => $stoid, 'user_id' => $this->user_id, 'mobile' => array('neq', '')))->find();
$accdb = tpCache('shop_info.ERPId', $stoid);
//--- 判断是导购还是会员分享过来的 ---
//--等级卡那边分享过来的--
$first_leader = I("plus_leader");
//--邀请人--
if ($first_leader) {
$fir_user = M("users")->where('user_id', $first_leader)->where("store_id", $stoid)->find();
if (empty($fir_user)) {
$this->error('未找到分享会员', U('User/index', array('stoid' => $stoid)));
}
if (empty($fir_user['card_field'])) {
$this->error('未找到分享的plus会员', U('User/index', array('stoid' => $stoid)));
}
$rand_end = empty($fir_user['card_expiredate']) ? 0 : strtotime($fir_user['card_expiredate']);
if ($rand_end < time()) {
$this->error('分享的plus会员已经过期', U('User/index', array('stoid' => $stoid)));
}
$data['VIPId'] = urlencode($fir_user['erpvipid']);
$c_user = getApiData_java_p("/api/erp/vip/mem/list", $accdb, $data);
$c_user = json_decode($c_user, true);
if ($c_user && $c_user['code'] === 0 && $c_user['data']) {
$rs = M("users_plus")->where("user_id", $this->user_id)->find();
if ($rs) {
M("users_plus")->where("user_id", $this->user_id)->save(['plus_user_id' => $first_leader, 'edittime' => time()]);
} else {
M("users_plus")->save(['user_id' => $this->user_id, 'plus_user_id' => $first_leader, 'addtime' => time(), 'store_id' => $stoid]);
}
$plus_qrcode = M("plus_qrcode")->where("UserId", $first_leader)->find();
if ($plus_qrcode) {
$this->assign("is_daogou", 1);
$this->assign("def_code", $plus_qrcode['StaffMobile']);
$this->assign("def_staff1", $plus_qrcode['StaffNo']);
} else {
$this->assign("is_fengxiang", 1);
$plus_qrcode = $c_user['data'][0];
$this->assign("def_code", $fir_user['mobile']);
$this->assign("def_staff1", $plus_qrcode['StaffNo']);
}
} else {
$this->error('未找到分享的等级卡会员', U('User/index', array('stoid' => $stoid)));
}
} else {
//如果在users_plus有值的话,就取users_plus上会员的资料
$users_plus = M("users_plus")->where("user_id", $this->user_id)->find();
if ($users_plus) {
$fir_user = M("users")->where('user_id', $users_plus['plus_user_id'])->where("store_id", $stoid)->find();
$is_out = 0;
if (empty($fir_user)) {
$is_out = 1;
}
if (empty($fir_user['card_field'])) {
$is_out = 1;
}
$rand_end = empty($fir_user['card_expiredate']) ? 0 : strtotime($fir_user['card_expiredate']);
if ($rand_end < time()) {
$is_out = 1;
}
//--邀请的会员的等级卡没有过期--
if (!$is_out) {
$data['VIPId'] = urlencode($fir_user['erpvipid']);
$c_user = getApiData_java_p("/api/erp/vip/mem/list", $accdb, $data);
$c_user = json_decode($c_user, true);
$first_leader = $users_plus['plus_user_id'];
if ($c_user && $c_user['code'] === 0 && $c_user['data']) {
$j_rs = M("users_plus")->where("user_id", $this->user_id)->find();
if ($j_rs) {
M("users_plus")->where("user_id", $this->user_id)->save(['plus_user_id' => $first_leader, 'edittime' => time()]);
} else {
M("users_plus")->save(['user_id' => $this->user_id, 'plus_user_id' => $first_leader, 'addtime' => time()]);
}
$plus_qrcode = M("plus_qrcode")->where("UserId", $first_leader)->find();
if ($plus_qrcode) {
$this->assign("is_daogou", 1);
$this->assign("def_code", $plus_qrcode['StaffMobile']);
$this->assign("def_staff1", $plus_qrcode['StaffNo']);
} else {
$this->assign("is_fengxiang", 1);
$plus_qrcode = $c_user['data'][0];
$this->assign("def_code", $fir_user['mobile']);
$this->assign("def_staff1", $plus_qrcode['StaffNo']);
}
}
}
}
}
$tk = M("store_config")->where("store_id", $stoid)
->field("dj_num,switch_list")->find();
$getdj_num = $tk['dj_num'];
$getswitch_list = $tk['switch_list'];
$getcardrules = tpCache('basic.cardrules', $stoid);
//判断是否人数到
$iscard = 0;
if (empty($getdj_num)) {
$iscard = 0;
}
if ($getdj_num > 0) {
$count = 0;
//调用ERP接口取有效等级会员
//$store_m = M('store_module_endtime')->where('store_id', 1)->where('type', 3)->find();
//$datap['EndDate'] = date("Y-m-d", $store_m['end_time']);
$rs_count = getApiData_java("/api/erp/vip/mem/card/count", $accdb, null, 1, 1);
if ($rs_count) {
$rs_count = json_decode($rs_count, true);
if ($rs_count['code'] == 0) {
$count = $rs_count['data']['SumTotal'];
if ($count < $getdj_num) {
$iscard = 1;
}
}
}
}
if ($iscard) {
$dj_p = M('dj_price')->where('money=0')->find();
//当人数不是使用人数时
if ($getdj_num != $dj_p['user_num']) {
$u = M('store_module_endtime')
->where('store_id', $stoid)
->where('is_sy', 0)
->where('type', 3)->find();
if ($u) {
if ($u['end_time'] < time()) {
$iscard = 0;
}
}
}
}
$this->assign('iscard', $iscard);
$rank_switch = json_decode($getswitch_list, true);
$isyaoqingma = $rank_switch['isyaoqingma'];
$is_staffno = $rank_switch['is_staffno'];
$this->assign('isyaoqingma', $isyaoqingma);
$this->assign('is_salesman', $is_staffno);
$recharge_type = 3;
if ($userinfo['card_field']) $recharge_type = 4;
$this->assign('recharge_type', $recharge_type);
$getval = I('getval');
if ($getval == 1) //验证邀请码
{
$codemobile = I('code');//邀请人手机号码
$userinfo = M('users')->where(array('store_id' => $stoid, 'user_id' => $this->user_id, 'mobile' => array('neq', '')))->find();
if (empty($userinfo)) {
return json(['msg' => -8]);
}
if ($userinfo['mobile'] == $codemobile) {
return json(['msg' => -8]);
}
$data['InviteCode'] = $codemobile;
$data['VIPId'] = $userinfo['erpvipid'];
$rt = getApiData_java_p("/api/erp/vip/mem/referee/code/check", $accdb, $data, 1, 100, null, "POST");
$rt = json_decode($rt, true);
if ($rt['code'] == 0) {
return $rt['data'][0];
}
return json(['msg' => 2]);
}
if ($getval == 2)//生成购买订单跳转到付款页面
{
$param = I('param.');
$data['code'] = $param['code'];
$data['staff'] = $param['staff'];
$data['cardid'] = $param['cardid'];
$data['fee'] = $param['fee'];
$data['no'] = 'vlc' . date("YmdHis") . rand(1000, 9999);//等级卡购买/续费单号
$data['billdate'] = time();
$data['user_id'] = $this->user_id;
$data['store_id'] = $stoid;
$order_id = M('level_orderform')->add($data);
}
//等级卡列表
$rs = getApiData_java_p("/api/erp/vip/mem/bership/list", $accdb, null, 1, 10, null, "GET");
//要进行加密计算
$arrlist = json_decode($rs, true)['data'];
$free_price = null;
if ($arrlist) {
foreach ($arrlist as $k => $v) {
//$fileds_key= md5($param["cardid"].$param['fee'].$param["ex_days"].getErpKey());
$fee = number_format($v['CardFee'], 2, ".", "");
$fileds_key = md5($v['CardId'] . $fee . $v['ExpiryDate'] . getErpKey());
$arrlist[$k]['keys'] = $fileds_key;
$free_price[] = ['index' => $k, 'fee' => $fee];
if (empty($v['CardImg'])) $arrlist[$k]['CardImg'] = QCLOUD_IMGURL . "/miniapp/images/plus/bg" . ($k + 1) . ".jpg?v=1";
if (empty($v['CardColor'])) $arrlist[$k]['CardColor'] = "#ecba95";
}
//---价格的排序---
$last_names = array_column($free_price, 'fee');
array_multisort($last_names, SORT_DESC, $free_price);
//--固定的是优惠多少钱---
$arr = [3031, 2089, 1219];
$map = null;
$max_free_index = $free_price[0]['index'];
$this->max_card = $arrlist[$max_free_index];
foreach ($free_price as $k => $v) {
$map[$v['index']] = $arr[$k]; //把价格填入map中
}
//--最把会优惠多少钱的数据填充到数组中去--
foreach ($arrlist as $k => $v) {
$arrlist[$k]['free'] = $map[$k];
}
}
$this->assign('userinfo', $userinfo);
$this->assign('list', $arrlist);
$this->assign('cardrules', $getcardrules);
return $this->fetch('', $stoid);
}
//--判断是否等级卡--
public function checkvipcard()
{
$codemobile = I('mobile');
$staffno = I('staffno');
$userinfo = M('users')->where(array('store_id' => getMobileStoId(), 'user_id' => $this->user_id, 'mobile' => array('neq', '')))->find();
if (empty($userinfo)) {
return json(['msg' => -8]);
}
if ($userinfo['mobile'] == $codemobile) {
return json(['msg' => -8]);
}
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
//如果只有营业员,就调用营业员判断的方法
if ($staffno) {
$data['KeyWord'] = urlencode($staffno);
$rt = getApiData_java_p("/api/erp/msg/staff/page", $accdb, $data, 1, 100, null);
if (empty($rt)) {
return json(['msg' => '网络异常,请点击重试']);
}
$rt = json_decode($rt, true);
if ($rt['code'] != 0) {
return json(['msg' => $rt['msg']]);
}
if (empty($rt['data']) || empty($rt['data']['pageData'])) {
return json(['msg' => '营业员不存在,请重新输入']);
}
$item = $rt['data']['pageData'][0];
//--如果营业员是自己的话,则不能购买--
if ($userinfo['mobile'] == $item['Tel']) {
return json(['msg' => -8]);
}
}
if ($codemobile) {
$data1['InviteCode'] = $codemobile;
$data1['VIPId'] = urlencode($userinfo['erpvipid']);
$rt = getApiData_java_p("/api/erp/vip/mem/referee/code/check", $accdb, $data1, 1, 100, null, "POST");
if (empty($rt)) {
return json(['msg' => '网络异常,请点击重试']);
}
$rt = json_decode($rt, true);
if ($rt['code'] != 0) {
return json(['msg' => '邀请人不存在,请重新输入']);
}
return $rt['data'][0];
}
return json(['msg' => '']);
}
//绑定选择门店
public
function get_the_Store()
{
try {
$stoid = I('stoid');
mlog("1", "get_the_Store/" . $stoid);
$lx = I('lx');
$ly = I('ly');
$uid = session('user')['user_id'];
if ($lx != 0 || $ly != 0) {
session('ulx', $lx);
session('uly', $ly);
}
$mindate = [];
/*--剔除不显示门店分类底下的门店--*/
$res0 = M("storage_category")->where('store_id', $stoid)->where('is_show', 0)->field("cat_id")->select();
$count0 = M("storage_category")->where('store_id', $stoid)->count();
$res0 = get_arr_column($res0, 'cat_id');
$wh = "1=1";
if (!empty($res0))
$wh = "category_id not in(" . implode(',', $res0) . ")";
// $result0=M("pick_up")->where('store_id',$stoid)->where('isstop<>1')->where($wh)->select();
$result0 = M("pick_up")->where('store_id', $stoid)->where('isstop<>1')->where($wh)->select();
$count = count($result0);
if ($count == 0) {
return json(['code' => -2, 'msg' => '未找到门店', 'is_bline' => 0]);
}
/*--当数量小于5--*/
if ($count <= 5 || $count0 <= 0) {
foreach ($result0 as $kk => $vv) {
$x1 = $vv['lon'];
$y1 = $vv['lat'];
$distance = sqrt(($x1 - $lx) * ($x1 - $lx) + ($y1 - $ly) * ($y1 - $ly));
$result0[$kk]['distance'] = round($distance, 2); //和定位点的距离
$dos[$kk] = $result0[$kk]['distance'];
}
if ($lx != 0 || $ly != 0) {
array_multisort($dos, SORT_ASC, $result0);
unset($dos);
}
return json(['code' => 1, 'msg' => 'ok', 'mini' => $result0, 'type' => 1]);
} else {
/*----选择门店-----*/
$res1 = M("storage_category")->where('store_id', $stoid)->where('is_show', 1)
->order('sort asc')->cache("storage_category_" . $stoid, TPSHOP_CACHE_TIME)->select();
foreach ($res1 as $k1 => $v1) {
$result = [];
foreach ($result0 as $k => $v) {
if ($v1['cat_id'] == $v['category_id']) {
$result[] = $v;
}
}
if (empty($result)) {
unset($res1[$k1]);
} else {
foreach ($result as $kk => $vv) {
$x1 = $vv['lon'];
$y1 = $vv['lat'];
$distance = sqrt(($x1 - $lx) * ($x1 - $lx) + ($y1 - $ly) * ($y1 - $ly));
$result[$kk]['distance'] = round($distance, 2); //和定位点的距离
$dos[$kk] = $result[$kk]['distance'];
}
if ($lx != 0 || $ly != 0) {
array_multisort($dos, SORT_ASC, $result);
unset($dos);
/*--取出最小值--*/
if (empty($mindata)) {
$mindata = $result[0];
} else {
$ele = $result[0];
if ($mindata['distance'] > $ele['distance']) {
$mindata = $ele;
}
}
}
$res1[$k1]['list'] = $result;
}
}
return json(['code' => 1, 'msg' => 'ok', 'store' => $res1, 'min' => $mindata, 'type' => 0]);
}
} catch (\Exception $e) {
insert_errlog($stoid, "会员绑定", "获取门店列表", "异常出错返回:" . $e->getMessage());
return json(['code' => -2, 'msg' => $e->getMessage()]);
}
}
/*
* 订单列表
*/
public
function order_list_pt()
{
$where = ' user_id=' . $this->user_id;
$where .= ' and is_zsorder>1 and pt_status>0 and store_id=' . getMobileStoId();
$type = I('type/d', 0);
switch ($type) {
case 0:
break;
case 1:
$where .= " and pt_status=1";
break;
case 2:
$where .= " and (pt_status=2 or pt_status=4 or pt_status=5)";
break;
case 3:
$where .= " and pt_status=3";
break;
}
$count = M('order')->where($where)->where('isdel=0')->count();
$Page = new Page($count, 10);
$order_list = M('order')->order('order_id DESC')->where($where)
->where('isdel=0')->limit($Page->firstRow . ',' . $Page->listRows)->select();
//dump($order_list); exit;
//获取订单商品
$model = new UsersLogic();
foreach ($order_list as $k => $v) {
$data = $model->get_order_goods1($v['order_id']);
$teamlist = M("teamlist")->where('id', $v['pt_prom_id'])->find();
$teamgroup = M("teamgroup")->where('listno', $v['pt_listno'])->where('store_id', getMobileStoId())->find();
$order_list[$k]['goods_list'] = $data['result'];
$order_list[$k]['teamlist'] = $teamlist;
$order_list[$k]['teamgroup'] = $teamgroup;
$order_list[$k]['j_num'] = 0;
$j_num = M("order")
->where('store_id', getMobileStoId())
->where('pt_status=1')
->where('pt_listno', $v['pt_listno'])->count();
if ($j_num) $order_list[$k]['j_num'] = $j_num;
$qh = $v['pt_listno'];
//已拼团人数
$ptedlist = M('order')
->field('is_pt_tz,pt_pay_time,user_id,add_time')
->where('store_id', getMobileStoId())
->where('pt_listno', $qh)->where('pay_time>0')->order('is_pt_tz desc')->select();
if ($ptedlist) {
$order_list[$k]["buyed_num"] = count($ptedlist);
}
if ($teamlist['kttype'] == 3) {
$max_num = 0;
$jt_data = json_decode($teamlist['ct_rylist'], true);
foreach ($jt_data as $kl => $vl) {
if ($vl['rynum'] >= $max_num) $max_num = $vl['rynum'];
}
$order_list[$k]['max_num'] = $max_num;
}
if ($v['pt_status'] == 2 || $v['pt_status'] == 4 || $v['pt_status'] == 5) {
$order_list[$k]['m_num'] = $teamlist['ct_num'];
if ($teamlist['kttype'] == 3) {
$teamgroup = M("teamgroup")->where('listno', $v['pt_listno'])->where('store_id', getMobileStoId())->find();
$order_list[$k]['m_num'] = $teamgroup['jt_ct_num'];
}
}
}
//统计订单商品数量
foreach ($order_list as $key => $value) {
$count_goods_num = '';
foreach ($value['goods_list'] as $kk => $vv) {
$count_goods_num += $vv['goods_num'];
if ($vv['prom_type'] == 3 || $vv['prom_type'] == 5) {
$order_list[$key]['is_prom'] = 1;
}
}
$order_list[$key]['count_goods_num'] = $count_goods_num;
}
$this->assign('lists', $order_list);
$this->assign('active', 'order_list');
$this->assign('active_status', I('get.type'));
if ($_GET['is_ajax']) {
return $this->fetch('ajax_order_list_pt', getMobileStoId());
exit;
}
$p = I("p/d", 1);
if ($count <= $p * 10) {
$this->assign('mshow', 0);
} else {
$this->assign('mshow', 1);
}
upload_ylp_log('订单列表');
return $this->fetch('', getMobileStoId());
}
//等级卡功能是否使用
public function is_djk()
{
$getstoid = getMobileStoId();
$tk = M("store_config")->where("store_id", $getstoid)->field("dj_num")->find();
$is_xuqi = I("is_xuqi");
$is_huiyuan_guoqi = 0;
if ($is_xuqi) {
$user = $this->user;
if (strtotime($user['card_expiredate']) < time()) {
$is_huiyuan_guoqi = 1;
}
}
$getdj_num = $tk['dj_num'];
//判断是否人数到
$iscard = 0;
if (empty($getdj_num)) {
return json(['code' => -1, 'msg' => 'PLUS功能未购买,请联系商家处理!']);
}
$erp = tpCache("shop_info.ERPId", $getstoid);
$dj_p = M('dj_price')->where('money=0')->find();
//当人数不是体验时使用人数时
if ($tk['dj_num'] != $dj_p['user_num']) {
$u = M('store_module_endtime')->where('store_id', $getstoid)->where('is_sy', 0)->where('type', 3)->find();
if ($u) {
if ($u['end_time'] < time()) {
return json(['code' => -1, 'msg' => 'PLUS功能已到期,请联系商家处理!']);
}
}
} else {
$u = M('store_module_endtime')->where('store_id', $getstoid)->where('is_sy', 1)->where('type', 3)->find();//试用的
}
//$datap['EndDate'] = date("Y-m-d", $u['end_time']);
$rs = getApiData_java_p("/api/erp/vip/mem/card/count", $erp, null);
if (empty($rs)) {
return json(['code' => -1, 'msg' => '网络繁忙数据获取失败,请点击重试【00】']);
}
$rs = json_decode($rs, true);
if ($rs['code'] != 0) {
return json(['code' => -1, 'msg' => '网络繁忙数据获取失败,请点击重试【01】']);
}
$count = $rs['data']['SumTotal'];
//--是不是续费--
if ($is_xuqi) {
//--是不是该会员过期了--
if ($is_huiyuan_guoqi && $count >= $getdj_num) {
return json(['code' => -1, 'msg' => 'PLUS会员数量已达上限,请联系商家升级PLUS功能']);
}
} else {
if ($count >= $getdj_num) {
return json(['code' => -1, 'msg' => 'PLUS会员数量已达上限,请联系商家升级PLUS功能']);
}
}
return json(['code' => 1, '成功!']);
}
//更换手机
public
function modimobile()
{
upload_ylp_log('更换手机');
$getstoid = getMobileStoId();
$user_info = M('users')->alias('a')
->where(array('store_id' => $getstoid, 'user_id' => $this->user_id))->find();
if ($user_info) {
$user_openid = $this->user['openid'];
$this->assign("user_openid", $user_openid);
$user_openidkey = md5($user_openid . "&" . getErpKey());
$this->assign("user_openid", $user_openid);
$this->assign("user_openidkey", $user_openidkey);
$storeconfig = M('store_config')->where('store_id', getMobileStoId())->field('reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
$reg_sms_enable = tpCache('sms.regis_sms_enable', getMobileStoId());
$reg_smtp_enable = tpCache('sms.regis_smtp_enable', getMobileStoId());
$sms_time_out = tpCache('sms.sms_time_out', getMobileStoId()) > 0 ? tpCache('sms.sms_time_out', getMobileStoId()) : 120;
$this->assign('sms_time_out', $sms_time_out); // 手机短信超时时间
$sms_send_type = json_decode($storeconfig['sms_send_type'], true);
$this->assign('s_type', $sms_send_type['type'] ? $sms_send_type['type'] : 0);
$this->assign('s_time_out', $sms_send_type['time_out'] ? $sms_send_type['time_out'] : 60);
$this->assign('is_verifycode', $sms_send_type['is_verifycode'] ? $sms_send_type['is_verifycode'] : 0);
/*---
//有账套
if ($this->pm_erpid) {
$user_info['api_token'] = tpCache('shop_info.api_token', getMobileStoId());
$mapuser['Id'] = $user_info['erpvipid'];
$user_rs = getApiData('wxd.vip.vipinfo.list.get', $user_info['api_token'], null, $mapuser);
$user_rs = json_decode($user_rs, true);
//调用接口错误,提示错误信息
if ($user_rs && $user_rs["code"] == 1 && $user_rs['data']) {
$new_user_info = $user_rs['data'][0];
if ($new_user_info) {
$updateuser['erpvipno'] = $new_user_info['VIPNo'];
}
$updateuser['mobile'] = $new_user_info['MobileTel'];
}
}--*/
}
$is_ajax = I('is_ajax/d', 0);
if ($is_ajax) {
$code = I('mobile_code');
$username = I('username');
$session_id = session_id();
$logic = new UsersLogic();
// $check_code = $logic->check_validate_code($code, $username, $session_id);
// if ($check_code['status'] != 1) {
// return array('status' => -1, 'msg' => $check_code['msg']);
// exit;
// }
M('sms_log')->where(array('store_id' => $getstoid, 'mobile' => $username, 'status' => 1))->delete();
$usercode = md5($username . getErpKey());
return array('status' => 1, 'msg' => 'ok', 'usercode' => $usercode);
}
$this->assign('user_info', $user_info);
return $this->fetch('', getMobileStoId());
}
//更换手机2
public
function modimobile2()
{
upload_ylp_log('更换手机');
$getstoid = getMobileStoId();
$usercode = I('usercode');
if (empty($usercode)) {
$this->error('操作失败1', U('User/modimobile', array('stoid' => $getstoid)));
exit();
}
$user_info = M('users')->alias('a')
->where(array('store_id' => $getstoid, 'user_id' => $this->user_id))->find();
if ($user_info) {
$mobile = $user_info['mobile'];
$getusercode = md5($mobile . getErpKey());
if ($getusercode != $usercode) {
$this->error('操作失败2', U('User/modimobile2', array('stoid' => $getstoid)));
exit();
}
$user_openid = $this->user['openid'];
$this->assign("user_openid", $user_openid);
$user_openidkey = md5($user_openid . "&" . getErpKey());
$this->assign("user_openid", $user_openid);
$this->assign("user_openidkey", $user_openidkey);
$storeconfig = M('store_config')->where('store_id', getMobileStoId())->field('reg_type,reg_info,reg_default,sms_send_type,switch_list')->find();
$reg_sms_enable = tpCache('sms.regis_sms_enable', getMobileStoId());
$reg_smtp_enable = tpCache('sms.regis_smtp_enable', getMobileStoId());
$sms_time_out = tpCache('sms.sms_time_out', getMobileStoId()) > 0 ? tpCache('sms.sms_time_out', getMobileStoId()) : 120;
$this->assign('sms_time_out', $sms_time_out); // 手机短信超时时间
$sms_send_type = json_decode($storeconfig['sms_send_type'], true);
$this->assign('s_type', $sms_send_type['type'] ? $sms_send_type['type'] : 0);
$this->assign('s_time_out', $sms_send_type['time_out'] ? $sms_send_type['time_out'] : 60);
$this->assign('is_verifycode', $sms_send_type['is_verifycode'] ? $sms_send_type['is_verifycode'] : 0);
}
$is_ajax = I('is_ajax/d', 0);
if ($is_ajax) {
$code = I('mobile_code');
$username = I('username');
$session_id = session_id();
$logic = new UsersLogic();
if ($getstoid != 1) {
$check_code = $logic->check_validate_code($code, $username, $session_id);
if ($check_code['status'] != 1) {
return json(array('status' => -1, 'msg' => $check_code['msg']));
exit;
}
M('sms_log')->where(array('store_id' => $getstoid, 'mobile' => $username, 'status' => 1))->delete();
}
//查询当前手机是否存在
$oldres = M('users')->where(array('store_id' => $getstoid, 'mobile' => $username))->find();
if ($oldres) {
return json(array('status' => -1, 'msg' => '当前手机已存在,请更换其他手机'));
exit;
}
//有账套
if ($this->pm_erpid) {
//$user_info['api_token'] = tpCache('shop_info.api_token', getMobileStoId());
//$mapuser['MobileTel'] = $username;
//$user_rs = getApiData('wxd.vip.vipinfo.list.get', $user_info['api_token'], null, $mapuser);
//$user_rs = json_decode($user_rs, true);
$mapuser['MobileTel'] =$username;
$user_rs = getApiData_java_p("/api/erp/vip/info/page", $this->pm_erpid, $mapuser, 1, 10, null, "GET");
$user_rs = json_decode($user_rs, true);
//调用接口错误,提示错误信息
if ($user_rs && $user_rs["code"] === 0 && $user_rs['data'] && $user_rs['total']>0 ) {
return json(array('status' => -1, 'msg' => '当前手机已存在,请更换其他手机'));
exit;
}
$erp_userres = json_decode($user_rs['data'], true);
$updata_erpuser['MobileTel'] = $username;
if ($erp_userres['MobileTel'] == $erp_userres['VIPNo']) {
$updata_erpuser['VIPNo'] = $username;
}
if ($erp_userres['MobileTel'] == $erp_userres['VIPName']) {
$updata_erpuser['VIPName'] = $username;
}
$updata_erpuser['Id'] = $user_info['erpvipid'];
//更新线下
$user_rs = getApiData('wxd.vip.vipinfo.edit', $user_info['api_token'], array($updata_erpuser));
}
//成立的话,更换
$newmobile['mobile'] = $username;
if ($user_info['mobile'] == $user_info['erpvipno']) {
$newmobile['erpvipno'] = $username;
}
if ($user_info['mobile'] == $user_info['vipname']) {
$newmobile['vipname'] = $username;
}
$update_m = M('users')->where(array('store_id' => $getstoid, 'user_id' => $this->user_id))->save($newmobile);
if (empty($update_m)) {
return json(array('status' => -1, 'msg' => '更新失败,请重试'));
}
return json(array('status' => 1, 'msg' => 'ok'));
}
$this->assign('user_info', $user_info);
$this->assign('usercode', $usercode);
return $this->fetch('', getMobileStoId());
}
//验证手机号是否存在
public
function yzmobile()
{
$getstoid = I('stoid');
$getmobile = I('username');
$res = M('users')->where(array('store_id' => $getstoid, 'mobile' => $getmobile))->find();
if ($res){
return json(array('code' => -1, 'msg' => '手机号码已存在,请更换其他手机'));
}
//$user_info['api_token'] = tpCache('shop_info.api_token', getMobileStoId());
//$mapuser['MobileTel'] = $getmobile;
//$user_rs = getApiData('wxd.vip.vipinfo.list.get', $user_info['api_token'], null, $mapuser);
$mapuser['MobileTel'] =$getmobile;
$user_rs = getApiData_java_p("/api/erp/vip/info/page", $this->pm_erpid, $mapuser, 1, 10, null, "GET");
$user_rs = json_decode($user_rs, true);
if ( ($user_rs['code'] === 0 && $user_rs['data'] && $user_rs['total']>0 )) {
return json(array('code' => -1, 'msg' => '手机号码已存在,请更换其他手机'));
}
return json(array('code' => 0, 'msg' => 'ok'));
}
//会员权益
public
function vipqy()
{
$geterpvipid = $this->user["erpvipid"];
$this->assign('geterpvipid', $geterpvipid);
$mapuser['VIPId'] = $geterpvipid;
$xmnum = 0;
$user_info['api_token'] = tpCache('shop_info.api_token', getMobileStoId());
$privilegelist = getApiData('wxd.vip.privilege.get', $user_info['api_token'], null, $mapuser);
if ($privilegelist) {
$privilegelist = json_decode($privilegelist, true);
if ($privilegelist['code'] == 1) {
$list = $privilegelist["data"];
$xmnum = count($list);
}
$this->assign('list', $list);
}
//代金券
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
$data['VIPId'] = urlencode($this->user['erpvipid']);
$rs = getApiData_java("api/erp/vip/shop/privilege/cash/list", $accdb, $data, 1, 1000);
if ($rs) {
$rs = json_decode($rs, true);
if ($rs['code'] == 0) {
if ($rs['data']) {
foreach ($rs['data'] as $kl => $vl) {
if ($vl['EndDate']) $rs['data'][$kl]['EndDate'] = date("Y-m-d", strtotime($vl['EndDate']));
}
}
$this->assign('qlist', $rs['data']);
}
}
$this->assign('xmnum', $xmnum);
$getvipqy_remark = tpCache('shopping.vipqy_remark', getMobileStoId());
$replaceold = array("\r\n", "\n", "\r");
$replace = '
';
$getvipqy_remark = str_replace($replaceold, $replace, $getvipqy_remark);
$this->assign('vipqy_remark', $getvipqy_remark);
return $this->fetch('', getMobileStoId());
}
public
function vipqy_sumbit()
{
// $url="http://open.xinda100.com/api/erp/vip/privilege/cash/insert";
// $method="POST";
// $postfile["token"]="5533cc000791d49740d6456b2bf48eca0c142f870f30ea84ef93cf4c5560e59cc1e61f8078f3f50a7ea4ecdd1393d393c09dd2d2c2d27f2bc2e5b5a4249194d8c07a7dfd02ee68f8423436fae3a2ed8a01644c15f7dcd50750d55dd1206aa2282aeafc70ff6a700057a203170f44e65e93e562340400c3f10e11a516d0635af8831bbc852f911c044a94741ebdcc660adadcf15c1ce76aecba769da2af0f65f2c58a217dafed94f2db49a9037da9f47a9de83f5a184d878dfb75da94d49a9a1671238a0e5140695583fabdc94f73c17870cfb85d000e1b3030ccc4d5261708998e3b0cc8fd50a4e7a9492d972ff0170eaf8ced81a4b1a591bd21ffb210705da2";
// $postfile["VIPId"]="8697c54c-2751-4017-8cd4-f2e4b5c8d692";
// $postfile["PrivilegeId"]="99CBB2F7-093D-43E6-9285-61A47BB12ADE";
// $postfile["page"]=1;
// $postfile["pageSize"]=1000;
// $res=httpRequest($url,$method,$postfile);
// var_dump($res);die;
//代金券领取
$getid = I('sid');
if (empty($getid)) {
return json(array('code' => -1, 'msg' => '参数有误'));
}
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
$data['VIPId'] = urlencode($this->user['erpvipid']);
$data['PrivilegeId'] = $getid;
$rs = getApiData_java_p("/api/erp/vip/privilege/cash/insert", $accdb, $data, 1, 1000, null, "POST");
//return json($rs);
return json_decode(stripslashes($rs), true);
}
//---开始计算尾款,并展示----
//'pt_tail_money'=>$price*$num+$vp['shipping_price']-$vp['order_amount']-$vp['user_money']
public
function show_wk_div()
{
$ord = I("ordsn");
$listno = I("listno");
$prom_id = I('pid');
$is_ajax = I('is_ajax');
$olist1 = M('teamgroup')->where('listno', $listno)->where('team_id', $prom_id)
->where('team_type', 3)->where('state', 2)->find();
if (empty($olist1)) return json(['code' => -1, 'msg' => '未找到团']);
//如果不的提交的话
if ($is_ajax) {
/*---获取地区---*/
$region_list = get_region_list();
$addlist = M('user_address')->where(['user_id' => $this->user_id])->select();
foreach ($addlist as $kk => $vv) {
$vv['provicename'] = $region_list[$vv['province']]['name'];
$vv['cityname'] = $region_list[$vv['city']]['name'];
$vv['districtname'] = $region_list[$vv['district']]['name'];
$vv['twonname'] = $region_list[$vv['twon']]['name'];
//$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find();
$addrstr = $vv['provicename'] . "-" . $vv['cityname'];
if (!empty($vv['district']))
$addrstr .= "-" . $vv['districtname'];
if (!empty($vv['twon']))
$addrstr = $addrstr . "-" . $vv['twonname'];
$vv['addrstr'] = $addrstr;
$addlist[$kk] = $vv;
}
$this->assign("addlist", $addlist);
$address_id = I('address_id/d');
if ($address_id) {
foreach ($addlist as $kk => $vv) {
if ($vv['address_id'] == $address_id) {
$address = $vv;
}
}
} else {
foreach ($addlist as $kk => $vv) {
if ($vv['is_default'] == 1) {
$address = $vv;
}
}
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
if (empty($address)) {
//header("Location: ".U('Mobile/User/add_address',array('stoid'=>getMobileStoId(),'source'=>'cart2')));
$this->assign('setadd', 1);
} else {
$this->assign('address', $address);
$this->assign('setadd', 0);
}
}
return "";
}
/**
* 添加微信收货信息
*/
public
function addwx_address()
{
$data = I('post.');
if (empty($data)) {
return json(array('code' => -1, 'msg' => '操作失败'));
}
$userName = $data['userName'];
$postalCode = $data['postalCode'];
$provinceName = $data['provinceName'];
$cityName = $data['cityName'];
$countryName = $data['countryName'];
$detailInfo = $data['detailInfo'];
$telNumber = $data['telNumber'];
$moreAddress = $provinceName . "-" . $cityName . "-" . $countryName . "-" . $detailInfo;
$provinceId = 0;
$cityId = 0;
$countryId = 0;
$res_province = M('region')->where(array('name' => $provinceName, 'level' => 1))->find();
if ($res_province) {
$provinceId = $res_province['id'];
}
$res_city = M('region')->where(array('name' => $cityName, 'parent_id' => $provinceId))->find();
if ($res_city) {
$cityId = $res_city['id'];
}
$res_district = M('region')->where(array('name' => $countryName, 'parent_id' => $cityId))->find();
if ($res_district) {
$districtId = $res_district['id'];
}
//判断是否已经添加过了
$resinfo = M('user_address')->where(array('user_id' => $this->user_id, 'consignee' => $userName, 'province' => $provinceId, 'district' => $districtId, 'address' => $detailInfo, 'mobile' => $telNumber))->find();
if ($resinfo) {
return json(array('code' => 0, 'msg' => '操作成功,已存在'));
}
$postdata['store_id'] = getMobileStoId();
$postdata['user_id'] = $this->user_id;
$postdata['consignee'] = $userName;
$postdata['province'] = $provinceId;
$postdata['city'] = $cityId;
$postdata['district'] = $districtId;
$postdata['address'] = $detailInfo;
$postdata['more_address'] = $moreAddress;
$postdata['zipcode'] = $postalCode;
$postdata['mobile'] = $telNumber;
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, $postdata);
if ($data['status'] != 1) {
return json(array('code' => -1, 'msg' => $data['msg']));
}
return json(array('code' => 0, 'msg' => '操作成功'));
}
//判断开卡,还是续费,续费1 开卡0
public
function check_is_card()
{
$user = M("users")->where("store_id", getMobileStoId())->where("user_id", $this->user_id)->find();
if ($user['card_field']) {
return json(["code" => 1]);
}
return json(["code" => 0]);
}
public
function coupon_list()
{
$stoid = getMobileStoId();
$user_id = $this->user['user_id'];
$FormId = I('FormId');
$GradeId = I('gradeId');
$Img = I('img');
$data = '?storeId=' . $stoid . '&userId=' . $user_id . '&FormId=' . $FormId . '&GradeId=' . $GradeId;
$quan_list = httpRequest(Mini_Host() . "/api/weshop/users/grade/wechat/cash/page" . $data, 'get');
$quan_list = json_decode($quan_list, true);
$this->assign('quan_list', $quan_list['data']['pageData']);
$this->assign('Img', $Img);
return $this->fetch('', getMobileStoId());
}
public
function fuwu()
{
return $this->fetch('', getMobileStoId());
}
public
function gorw_up()
{
return $this->fetch('', getMobileStoId());
}
public
function gorw_up_details()
{
$stoid = I("stoid");
$need_money = I("need_money");
$cz_url = Mini_Host() . "/api/weshop/users/grade/aftervipinfo/get?storeId=" . $stoid . "&userId=" . $this->user_id;
$cz_data = httpRequest($cz_url);
$cz_data = json_decode($cz_data, true);
if ($cz_data['code'] == 0) {
$this->assign('cz_data', $cz_data['data']);
}
if (empty($need_money)) {
$url = Mini_Host() . "/api/weshop/users/grade/vipgradeinfo/page?storeId=" . $stoid;
$rs = httpRequest($url);
$rs = json_decode($rs, true);
$backClass = $rs['data']['pageData'];
if ($backClass && $cz_data['data']) {
$need_money = 0;
foreach ($backClass as $k => $v) {
if ($cz_data['data']['GradeSum'] < $v) {
$need_money = $v['BuyGradeSum'];
break;
}
}
$this->assign("need_money", $need_money);
}
}
$end = strtotime("+1 week");
$this->assign("start", "2019-01-01");
$this->assign("end", "2019-12-01");
return $this->fetch('', getMobileStoId());
}
//买单个等级卡
public
function payvipcard()
{
$carid = I("carid");
$this->assign("cardid", $carid);
$tk = M("store_config")->where("store_id", getMobileStoId())
->field("dj_num,switch_list")->find();
$getdj_num = $tk['dj_num'];
$getswitch_list = $tk['switch_list'];
$rank_switch = json_decode($getswitch_list, true);
$isyaoqingma = $rank_switch['isyaoqingma'];
$is_staffno = $rank_switch['is_staffno'];
$this->assign('isyaoqingma', $isyaoqingma);
$this->assign('is_salesman', $is_staffno);
//判断是否人数到
$iscard = 0;
if (empty($getdj_num)) {
$iscard = 0;
}
if ($getdj_num > 0) {
$count = 0;
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
$store_m = M('store_module_endtime')->where('store_id', 1)->where('type', 3)->find();
//$datap['EndDate'] = date("Y-m-d", $store_m['end_time']);
//调用ERP接口取有效等级会员
$rs_count = getApiData_java("/api/erp/vip/mem/card/count", $accdb, null, 1, 1);
if ($rs_count) {
$rs_count = json_decode($rs_count, true);
if ($rs_count['code'] == 0) {
$count = $rs_count['data']['SumTotal'];
if ($count < $getdj_num) {
$iscard = 1;
}
}
}
}
if ($iscard) {
$dj_p = M('dj_price')->where('money=0')->find();
//当人数不是使用人数时
if ($getdj_num != $dj_p['user_num']) {
$u = M('store_module_endtime')
->where('store_id', getMobileStoId())->where('is_sy', 0)
->where('type', 3)->find();
if ($u) {
if ($u['end_time'] < time()) {
$iscard = 0;
}
}
}
}
$this->assign('iscard', $iscard);
if ($iscard) {
//等级卡列表
$rs = getApiData_java_p("/api/erp/vip/mem/bership/list", $accdb, null, 1, 10, null, "GET");
//要进行加密计算
$arrlist = json_decode($rs, true)['data'];
$free_price = null;
$item = null;
if ($arrlist) {
foreach ($arrlist as $k => $v) {
if ($v['CardId'] == $carid) {
$item = $v;
$fee = number_format($v['CardFee'], 2, ".", "");
$fileds_key = md5($v['CardId'] . $fee . $v['ExpiryDate'] . getErpKey());
$item['keys'] = $fileds_key;
$item['fee'] = $fee;
break;
}
}
}
$this->assign('item', $item);
}
return $this->fetch('', getMobileStoId());
}
}