getAdminId()); $res = M('admin')->alias('a')->join('store b', ' a.store_id=b.store_id', 'left') ->where($where)->field('b.isweb_reg,b.reg_mobile,b.ERPId,b.store_logo')->find(); $this->assign("stoinfo",$res); } $this->assign("islogin",$islogin); $cururl=curHostURL()."/home/index/index/stoid"; //置顶商家 $storeinfo=M('store')->alias('a')->join('wx_user b',' a.store_id=b.store_id','left') ->where(array('a.isindex'=>1))->field('a.store_id,a.store_name,b.headerpic,b.signature')->limit(0,10) ->select(); $this->assign("cururl",$cururl); $this->assign("storeinfo",$storeinfo); return $this->display(); } //商家注册 public function register() { $act=I('act'); $this->assign("act",$act); $xylist=M('store_industry')->order('ordid asc')->select(); $this->assign("xylist",$xylist); $bussinessmodel=M('store_bussinessmodel')->order('ordid asc')->select(); $this->assign("bussinessmodel",$bussinessmodel); return $this->fetch(); } //验证码 校验 public function first_reg() { $mobile = I('mobile'); $sms_captcha = I('sms_captcha'); if (empty($mobile) || empty($sms_captcha)) { return json(array('code'=>-1,'msg'=>'手机或验证不能为空!')); } if (!$this->is_mobile($mobile)) { return json(array('code'=>-1,'msg'=>'手机格式有误,请重新输入!')); } $res=M('reg_sms')->alias('a')->where(array('mobile'=>$mobile,'code'=>$sms_captcha,'type'=>1))->find(); if (empty($res)) { return json(array('code'=>-1,'msg'=>'验证码有误!')); } $row = M('reg_sms')->where(array('mobile' => $mobile, 'type' => 1, 'status' => 1))->delete(); return json(array('code'=>1,'msg'=>'验证成功!')); } //修改新密码验证码 校验 public function resetpass() { $mobile = I('mobile'); $sms_captcha = I('sms_captcha'); $password = I('password'); if (empty($mobile) || empty($sms_captcha) || empty($password)) { return json(array('code'=>-1,'msg'=>'手机或验证或密码不能为空!')); } if (!$this->is_mobile($mobile)) { return json(array('code'=>-1,'msg'=>'手机格式有误,请重新输入!')); } $res=M('reg_sms')->alias('a')->where(array('mobile'=>$mobile,'code'=>$sms_captcha,'type'=>2))->find(); if (empty($res)) { return json(array('code'=>-1,'msg'=>'验证码有误!')); } $storeinfo=M('store')->where(array('reg_mobile'=>$mobile))->find(); if (empty($storeinfo)) { return json(array('code'=>-1,'msg'=>'找不到该手机注册信息!')); } $savedata['pwd']=md5($password); $modiinfo=M('admin')->where(array('store_id'=>$storeinfo['store_id'],'ERPUser'=>$mobile))->save($savedata); if ($modiinfo) { $row = M('reg_sms')->where(array('mobile' => $mobile, 'type' => 2, 'status' => 1))->delete(); return json(array('code' => 1, 'msg' => '修改成功!')); }else { return json(array('code' => -1, 'msg' => '修改失败!')); } } //提交 完成 public function sumbit_reg() { $data=I('post.'); if (empty($data)) { return json(array('code'=>-1,'msg'=>'提交信息有误!')); } $stoinfo['store_name']=$data['store_company']; $stoinfo['store_company']=$data['store_company']; $stoinfo['reg_mobile']=$data['mobile']; $stoinfo['store_industry_id']=$data['store_industry_id']; $stoinfo['business_model_id']=$data['business_model_id']; $stoinfo['sms_mobile']=$data['mobile']; $stoinfo['store_tel']=$data['mobile']; $stoinfo['store_contact']=$data['store_contact']; $stoinfo['store_address']=$data['store_city'].$data['store_address']; $stoinfo['is_audit']=0; $stoinfo['BillDate']=time(); $stoinfo['BillIp']=getIP(); $sto_add=M('store')->add($stoinfo); if ($sto_add) { //添加admin角色 $role['store_id'] = $sto_add; $role['role_name'] = '超级管理员'; $role['act_list'] = 'all'; $role['role_desc'] = '管理全站'; $ro = D('role')->add($role); //新增的角色ID if ($ro) { // $admin['store_id'] = $sto_add; $admin['ERPUser'] = $data['mobile']; $admin['ERPName'] = $data['store_contact']; $admin['role_id'] = $ro; $admin['BillDate'] = time(); $admin['BillIp'] = getIP(); $admin['pwd'] = md5($data['password']); $admininfo = D('admin')->add($admin); return json(array('code'=>1,'msg'=>'提交成功!')); } else { return json(array('code'=>-1,'msg'=>'提交失败!')); } } else { return json(array('code'=>-1,'msg'=>'提交失败!')); } } //验证发送 public function reg_sms() { $mobile = I('mobile'); $type = I('type/d',1); if (empty($mobile)) { return json(array('code'=>-1,'msg'=>'手机或验证不能为空!')); } if (!$this->is_mobile($mobile)) { return json(array('code'=>-1,'msg'=>'手机格式有误,请重新输入!')); } if ($type==2) { $storeinfo=M('store')->where(array('reg_mobile'=>$mobile))->find(); if (empty($storeinfo)) { return json(array('code'=>-1,'msg'=>'找不到该手机注册信息!')); } } //判断是否存在验证码 $data = M('reg_sms')->where(array('mobile' => $mobile, 'type' => $type))->order('id DESC')->find(); //获取时间配置 $sms_time_out = 60; if ($data && (time() - $data['add_time']) < $sms_time_out) { $return_arr = array('status' => -1, 'msg' => $sms_time_out . '秒内不允许重复发送'); return json($return_arr); } else { //随机一个验证码 $code = rand(100000, 999999); $row = M('reg_sms')->add(array('mobile' => $mobile, 'code' => $code, 'add_time' => time(), 'type' => $type, 'status' => 0)); $getparam = "&smsTemplateCode=SMS_117245087¶meters=['" . $code . "']"; $poststr = "phone=" . $mobile . "&msgOrigin=WXD&smsFreeSignName=万信达软件" . $getparam; $resp = httpRequest("http://source-api.yolipai.com/external/sms/alidayu/send", "post", $poststr); $resp = json_decode($resp, true); if ($resp['code'] == 0) { //发送成功, 修改发送状态位成功 M('reg_sms')->where(array('mobile' => $mobile, 'code' => $code, 'type' => $type, 'status' => 0))->save(array('status' => 1)); return json(array('code'=>1,'msg'=>'发送成功,请注意查收')); } else { return json(array('code'=>-1,'msg'=>'发送失败'. $resp['msg'])); } } } //商家登陆 public function login() { return $this->fetch(); } //登陆POST public function sumbitlogin() { $mobile = I('mobile'); $password = I('password'); $autologin = I('autologin'); if (empty($mobile) || empty($password)) { return json(array('code'=>-1,'msg'=>'用户名或密码不能为空!')); } $password_md5=md5($password); $mobile_arry=explode("@",$mobile); if (count($mobile_arry)==2) { $login_user=$mobile_arry[0]; $login_mobile=$mobile_arry[1]; } else{ $login_user=$mobile; $login_mobile=$mobile; } $where=""; if ($this->is_mobile($login_mobile)) { $where=array('b.reg_mobile'=>$login_mobile,'a.ERPUser'=>$login_user,'a.pwd'=>$password_md5); } else{ $where=array('b.ERPId'=>$login_mobile,'a.ERPUser'=>$login_user,'a.pwd'=>$password_md5); } $res=M('admin')->alias('a')->join('store b',' a.store_id=b.store_id','left') ->where($where)->find(); if (empty($res)) { return json(array('code'=>-1,'msg'=>'用户名或密码有误!')); } if ($res['is_audit']!=1) { return json(array('code'=>-1,'msg'=>$res['fail_remak'])); } $fieldstr=""; if ($this->is_mobile($login_mobile)) { $fieldstr = "mobile=" . $res['reg_mobile'] . "&ERPUser=" . $res['ERPUser']; }else { $fieldstr = "ERPId=" . $res['ERPId'] . "&ERPUser=" . $res['ERPUser']; } $gofieldstr = $fieldstr; $fieldstr .= "&Key=" . getErpKey(); $fieldstr1 = strtolower($fieldstr); $key = md5($fieldstr1); $poststr = $gofieldstr . "&key=" . $key; $poststr = urlencode($poststr); return json(array('code'=>1,'link'=>$poststr,'msg'=>'登陆成功!')); } function is_mobile( $text ) { $search = '/^0?1[2|3|4|5|6|7|8|9][0-9]\d{8}$/'; if ( preg_match( $search, $text ) ) { return ( true ); } else { return ( false ); } } //找回密码 public function reset_password() { return $this->fetch(); } //ERP手店资料申请 public function apply_shop(){ $str=file_get_contents("php://input"); $str=str_replace('data=','',$str); $str=urldecode($str); // $str="ERPId=PPT&CORNAME=有礼派&CORFRNAME=问&CORFRTEL=1234567453&ERPUser=admin&ERPName=超级用户&Key=wxdkey123456"; if ($str) { Cookie::set("cur_erpinfo", $str); } if (cookie("cur_erpinfo")!="") { $str=cookie("cur_erpinfo"); } if($str!="") { $sReqData1 = explode('&', $str); $ary = array(); $arrlength = count($sReqData1); for ($i = 0; $i < $arrlength; $i++) { $ar = explode('=', $sReqData1[$i]); $k = $ar[0]; $v = $ar[1]; $ary[$k] = $v; } //$info=M('store')->alias('a') // ->join('wx_user b',' a.store_id=b.store_id') // ->where(array('a.ERPId'=>$ary['ERPId']))->find(); $info=M('store')->where(array('ERPId'=>$ary['ERPId']))->find(); if ($info) { $a = D('admin')->where(array('store_id'=>$info['store_id']))->where("ERPUser<>'admin'")->field('ERPUser')->select(); // echo json_encode($info); $info['CORFRNAME']=$info['store_name']; $info['CORNAME']=$info['store_contact']; $info['CORFRTEL']=$info['store_tel']; $getconvertimg=explode(",",$info['convertimg']); $getERPUser=""; foreach ($a as $v=>$value ) { if ($getERPUser=="") { $getERPUser=$value['ERPUser']; } else{ $getERPUser.=",".$value['ERPUser']; } } $info['ERPUser']=$getERPUser; $wxuser=M('wx_user')->where('store_id',$info['store_id'])->find(); $info['WX_appid_Pay']=$wxuser['appid']; $info['WX_secret_Pay']=$wxuser['appsecret']; $info['WX_MCHID']=$wxuser['mchid']; $info['WX_APIKey']=$wxuser['mchkey']; $this->assign('info', $info); $this->assign('convertimg', $getconvertimg); } else { try { $oldinfo = httpRequest(IMPORT_URL . "/API/CustInfo.ashx?method=shopinfo&ERPDBAccID=" . $ary['ERPId']); if ($oldinfo) { $oldinfo = json_decode($oldinfo, true); if ($oldinfo['code'] == 0) { $oldinfodata = $oldinfo['data']['item'][0]; $ary['WX_appid_Pay'] = $oldinfodata['WX_appid_Pay']; $ary['WX_secret_Pay'] = $oldinfodata['WX_secret_Pay']; $ary['WX_MCHID'] = $oldinfodata['WX_MCHID']; $ary['WX_APIKey'] = $oldinfodata['WX_APIKey']; } } } catch (Exception $ex) { } $this->assign('info', $ary); } } return $this->fetch(); } /** * 公告详情页 */ public function notice(){ return $this->fetch(); } // 二维码 public function qr_code(){ // 导入Vendor类库包 Library/Vendor/Zend/Server.class.php //http://www.tp-shop.cn/Home/Index/erweima/data/www.99soubao.com require_once 'vendor/phpqrcode/phpqrcode.php'; //import('Vendor.phpqrcode.phpqrcode'); $errorCorrectionLevel = "L"; // 纠错级别: error_reporting(E_ERROR); $url = urldecode(urldecode($_GET["data"])); ob_clean(); ob_end_clean(); \QRcode::png($url); } // 验证码 public function verify() { //验证码类型 $type = I('get.type') ? I('get.type') : ''; $fontSize = I('get.fontSize') ? I('get.fontSize') : '40'; $length = I('get.length') ? I('get.length') : '4'; $config = array( 'fontSize' => $fontSize, 'length' => $length, 'useCurve' => true, 'useNoise' => false, ); $Verify = new Verify($config); $Verify->entry($type); } public function apply_shop_Handle(){ try { $data = I('post.'); $wxverfiy = $data['wxverfiy']; $wxverfiy=str_replace(".txt","",$wxverfiy); $wxverfiy=trim($wxverfiy); $file = $wxverfiy . ".txt"; $wxverfiy1 = str_replace("MP_verify_", "", $wxverfiy); file_put_contents($file, $wxverfiy1, FILE_APPEND); $server_url=serverIP(); $url=explode(',',IP_ARRAY); $err=true; foreach ($url as $k => $v) { if ($v != $server_url) { $url = 'http://' . $v . '/index.php/home/index/receiveStreamFile/file/' . $file; $a = $this->sendStreamFile($url, $file); if (empty($a) || $a === false) { $err = false; } } } if(!$err){ $this->ajaxReturn(array('status' => -1, 'msg' => '申请失败!')); exit(); } $staff_num = ($data['staff_num']);//员工编号 unset($data['staff_num']);//过滤员工编号 $data['BillDate'] = time(); $data['BillIp'] = getIP(); $data['is_audit'] = 0;//申请的商家默认未审核 $data['ERPId']=strtolower($data['ERPId']); $erpres=httpRequest(WXDURL."?access_token=wxdoa.cust.all.list.get&accdb=".$data['ERPId'],'get'); $erpres=json_decode($erpres,true); if ($erpres && $erpres['code']==1) { $api_token=$erpres['data'][0]['token']; } $data['api_token'] = $api_token; $info_store=D('store')->where("ERPId", $data['ERPId'])->find(); if ($info_store) { // $this->error("此帐套已存在,请更换", U('manager/Admin/store_info')); $r = D('store')->where('store_id',$info_store['store_id'])->save($data); //默认给基本设置添加一条记录 $ifo['default_storage']=100; //默认库存 $ifo['warning_storage']=10; //预警库存 $ifo['distribut_need']=100; //需要多少提现 $ifo['distribut_min']=100; //最少提现多少钱 $ifo['categoryset']=',1,2,3,'; //分类默认都显示 $ifo['refund_type']=1; //退款默认原路返回 $ifo['is_sort_storage']=0; //门店GPS默认关闭 $ifo['switch_list']='{"jfcz_switch":1,"dhwz_switch":1}'; //默认显示积分,微券兑换 $ifo['sales_rules']=1; //默认线上库存 $ifo['inv_type']=0; $ifo['invitation_rate']='{"inv_jf":"0","inv_coupon":""}'; //邀请规则 $ifo['reg_type']=0; $ifo['reg_default']='{"reg_def_ty":"0","jf":"0","coupon":""}'; //注册规则 $uo=M('store_config')->where('store_id',$info_store['store_id'])->find(); if($uo) $wxuser=M('store_config')->where('Id',$uo['Id'])->save($ifo); else{ $ifo['store_id']=$info_store['store_id']; //注册规则 $wxuser=M('store_config')->save($ifo); } /*--默认商家分销人员--*/ $uo=M('store_distribut')->where('store_id',$info_store['store_id'])->find(); $yy=M('distri_price')->where('type',0)->where('money',0)->find(); if($uo){ $op['store_id']=$info_store['store_id']; //默认库存 $op['distribut_num']=$yy['user_num']; M('store_distribut')->save($op); }else{ $op['distribut_num']=$yy['user_num']; M('store_distribut')->where('store_id',$info_store['store_id'])->save($op); } /*--清理缓存数据--*/ $stoid=$info_store['store_id']; $arr = getCachaArr($stoid); foreach ($arr as $b) { Cache::rm($b); } delFile(TEMP_PATH . "/" . $stoid); //修改到微信表 $wx['wx_username'] = $data['wx_username']; $wx['wx_pwd'] = $data['wx_pwd']; $wx['appid'] = $data['appid']; $wx['appsecret'] = $data['appsecret']; $wx['mchid'] = $data['mchid']; $wx['mchkey'] = $data['mchkey']; $wx['token'] = $data['appid'].time(); $wx_l = D('wx_user')->where('store_id',$info_store['store_id'])->save($wx); if ($wx_l && $r) { $this->ajaxReturn(array('status' => 1, 'msg' => '提交成功!')); }else { $this->ajaxReturn(array('status' => -1, 'msg' => '提交失败!')); } } else { //添加商家 //$SupplyId = uuid(); $r = D('store')->add($data); //新增的商家ID ///后续操作 if ($r) { //添加商家的admin角色 $role['store_id'] = $r; $role['role_name'] = '超级管理员'; $role['act_list'] = 'all'; $role['role_desc'] = '管理全站'; $ro = D('role')->add($role); //新增的角色ID $role1['store_id'] = $r; $role1['role_name'] = '管理员'; $role1['act_list'] = '67,68,69,70,71,72,73,74,75,76,77,78,79,80,82,115,83,84,85,86,87,89,90,91,92,93,94,95,96,97,98,99,101,102,103,104,106,121,122,108,109,110,111,112,113,120,116,117,118,119,126,123,124,125'; $role1['role_desc'] = '管理员'; $ro1 = D('role')->add($role1); //新增的角色ID if ($ro) { $staff_num = $staff_num . ",admin"; //添加默认admin用户 $staff_num=str_replace(",",",",$staff_num); $array = explode(",", $staff_num); //添加商家用户 for ($i = 0; $i < count($array); $i++) { //添加用户 if ($array[$i] == "admin") { $admin['role_id'] = $ro; $admin['ERPName'] = '超级管理员'; } else { $admin['role_id'] = $ro1; $admin['ERPName'] = $array[$i]; } $admin['store_id'] = $r; $admin['ERPId'] = strtolower($data['ERPId']); $admin['ERPUser'] = $array[$i]; $admin['BillIp'] = getIP(); $admin['BillDate'] = time(); $a = D('admin')->add($admin); if (!$a) { $this->ajaxReturn(array('status' => -1, 'msg' => '申请失败!')); } } } //默认给基本设置添加一条记录 $ifo['default_storage']=100; //默认库存 $ifo['warning_storage']=10; //预警库存 $ifo['distribut_need']=100; //需要多少提现 $ifo['distribut_min']=100; //最少提现多少钱 $ifo['categoryset']=',1,2,3,'; //分类默认都显示 $ifo['refund_type']=1; //退款默认原路返回 $ifo['is_sort_storage']=0; //门店GPS默认关闭 $ifo['switch_list']='{"jfcz_switch":1,"dhwz_switch":1}'; //默认显示积分,微券兑换 $ifo['sales_rules']=1; //默认线上库存 $ifo['inv_type']=0; $ifo['invitation_rate']='{"inv_jf":"0","inv_coupon":""}'; //邀请规则 $ifo['reg_type']=0; $ifo['reg_default']='{"reg_def_ty":"0","jf":"0","coupon":""}'; //注册规则 $uo=M('store_config')->where('store_id',$r)->find(); if($uo) $wxuser=M('store_config')->where('Id',$uo['Id'])->save($ifo); else{ $ifo['store_id']=$r; //注册规则 $wxuser=M('store_config')->save($ifo); } /*--清理缓存数据--*/ $stoid=$r; $arr = getCachaArr($stoid); foreach ($arr as $b) { Cache::rm($b); } delFile(TEMP_PATH . "/" . $stoid); //添加到微信表 $wx['store_id'] = $r; $wx['wx_username'] = $data['wx_username']; $wx['wx_pwd'] = $data['wx_pwd']; $wx['appid'] = $data['appid']; $wx['appsecret'] = $data['appsecret']; $wx['mchid'] = $data['mchid']; $wx['mchkey'] = $data['mchkey']; $wx['token'] = $data['appid'].time(); $wx_l = D('wx_user')->add($wx); if ($wx_l) { $this->ajaxReturn(array('status' => 1, 'msg' => '申请成功!')); } } else { //添加失败 $this->ajaxReturn(array('status' => -1, 'msg' => '申请失败!')); } } } catch (Exception $ex) { mlog($ex,"apply_shop"); $this->ajaxReturn(array('status' => -1, 'msg' => '异常添加失败!')); } } /** php 发送流文件 * @param String $url 接收的路径 * @param String $file 要发送的文件 * @return boolean */ public function sendStreamFile($url, $file) { if (file_exists($file)) { $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'content-type:application/x-www-form-urlencoded', 'content' => file_get_contents($file) ) ); $context = stream_context_create($opts); $response = file_get_contents($url, false, $context); $ret = json_decode($response, true); return $ret; } else { return false; } } /** php 接收流文件 * @param String $file 接收后保存的文件名 * @return boolean */ public function receiveStreamFile() { $receiveFile = I('file'); $streamData = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; if (empty($streamData)) { $streamData = file_get_contents('php://input'); } if ($streamData != '') { $ret = file_put_contents($receiveFile, $streamData, true); } else { $ret = false; } return $ret; } }