where(array('ERPId' => $ACCDB, 'is_audit' => 1))->field('store_id,store_name')->find(); // if (empty($res_store)) { // $jsonres["STATE"] = -1; // $jsonres["MSG"] = "找不到相关账套!"; // return json_encode($jsonres); // } // // $getstore_id = $res_store['store_id']; // // $ts_sday = strtotime(date("Y-m-d", strtotime("1 day")) . " 00:00:00"); // $ts_eday = strtotime(date("Y-m-d", strtotime("2 day")) . " 00:00:00"); // $stypeid = "1014"; // $etypeid = "1013"; // // // $where = " start_time>=$ts_sday and start_time<=$ts_eday"; // $msurl = curHostURL() . "/Mobile/Goods/goodsInfo/";//秒杀网址 // // //秒杀一天后开始的 // $ms_res = M('flash_sale')->where(array('store_id' => $getstore_id, 'is_autowx' => 1, 'is_end' => array('<>', 1))) // ->where($where) // ->field("title,order_num,FROM_UNIXTIME(start_time) as hd_time," . $stypeid . " as typeid,CONCAT('$msurl','stoid/',store_id,'/id/',goods_id) as back_url") // ->select(); // // // //团购一天后开始的 // $tg_res = M('group_buy')->where(array('store_id' => $getstore_id, 'is_autowx' => 1, 'is_end' => 0)) // ->where($where) // ->field("title,buy_num,FROM_UNIXTIME(start_time) as hd_time," . $etypeid . " as typeid,CONCAT('$msurl','stoid/',store_id,'/id/',goods_id) as back_url") // ->select(); // // //搭配一天后开始的 // $dp_res = M('collocation')->where(array('store_id' => $getstore_id, 'is_autowx' => 1, 'is_end' => 0)) // ->where($where) // ->field("title,0 as order_num,FROM_UNIXTIME(start_time) as hd_time," . $stypeid . " as typeid,CONCAT('$msurl','stoid/',store_id,'/id/',main_goods_id) as back_url") // ->select(); // // // $where = " end_time>=$ts_sday and end_time<=$ts_eday"; // //秒杀一天后结束 // $ms_res1 = M('flash_sale')->where(array('store_id' => $getstore_id, 'is_autowx' => 1, 'is_end' => array('<>', 1))) // ->where($where) // ->field("title,order_num,FROM_UNIXTIME(end_time) as hd_time," . $etypeid . " as typeid,CONCAT('$msurl','stoid/',store_id,'/id/',goods_id) as back_url") // ->select(); // // // //团购一天后结束 // $tg_res1 = M('group_buy')->where(array('store_id' => $getstore_id, 'is_autowx' => 1, 'is_end' => 0)) // ->where($where) // ->field("title,0 as order_num,FROM_UNIXTIME(end_time) as hd_time," . $stypeid . " as typeid,CONCAT('$msurl','stoid/',store_id,'/id/',goods_id) as back_url") // ->select(); // // // // //搭配一天后结束 // $dp_res1 = M('collocation')->alias('a')->where(array('a.store_id' => $getstore_id, 'a.is_autowx' => 1, 'a.is_end' => 0)) // ->join("(select count(1) as order_num, prom_id from wxd_order_goods a left join wxd_order b on a.store_id=b.store_id and a.order_sn=b.order_sn where a.prom_type=5 and a.store_id=".$getstore_id." group by prom_id) b",' a.id=b.prom_id','left') // ->where($where) // ->field("a.title,0 as order_num,FROM_UNIXTIME(a.end_time) as hd_time," . $etypeid . " as typeid,CONCAT('$msurl','stoid/',a.store_id,'/id/',a.main_goods_id) as back_url") // ->select(); // // if ($ms_res || $tg_res || $dp_res || $ms_res1 || $tg_res1|| $dp_res1 ) { // $newres = array_merge($ms_res, $tg_res, $dp_res, $ms_res1, $tg_res1, $dp_res1); // // $jsonres["STATE"] = 1; // $jsonres['store_name']=$res_store['store_name']; // $jsonres["list"] =$newres; // $jsonres["MSG"] = "ok"; // return json_encode($jsonres); // } // else // { $jsonres["STATE"] = -1; $jsonres["MSG"] = "找不到相关记录!"; return json_encode($jsonres); // } } //des public function getdes() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "123"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $key = "xinda100xinda100";//密钥 $text = $postStr;//需要加密的内容 // echo ($text) . "\n"; $crypttext = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv)); $jsonres["STATE"] = 1; $jsonres["destext"] = $crypttext; return json_encode($jsonres); // echo mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key,base64_decode($crypttext),MCRYPT_MODE_ECB,$iv);//解密后的内容 } //获取stoid public function getstoid() { // $str="accdb=ppt&number=213123123123&date=2018-01-27&key=efee893817e836a94c0858ba8a0729b9"; $getaccdb = strtolower(I('accdb')); $getnumber = strtolower(I('number')); $getdate = strtolower(I('date')); $getkey = strtolower(I('key')); if ($getaccdb && $getnumber && $getdate && $getkey) { $fieldstr = "accdb=" . $getaccdb . "&number=" . $getnumber . "&date=" . $getdate . "&key=" . getErpKey(); $fieldstr1 = "accdb=" . $getaccdb . "&number=" . $getnumber . "&date=" . $getdate . "&key=" . $getkey; //如果key不相等,报错 if ($getkey != md5($fieldstr)) { goUrl("/err_mobile.html?msg=非法参数"); return; } $res = M('store')->where("ERPId", $getaccdb)->field('store_id')->find(); if ($res) { goUrl("/mobile/sign/index/stoid/" . $res['store_id'] . "?" . $fieldstr1); } else { goUrl("/err_mobile.html?msg=找不到相关信息"); return; } } else { goUrl("/err_mobile.html?msg=参数为空"); return; } } //绑定跳转 public function staffbinding() { // $md5str="accdb=ppt&usercode=ylp0019&key=" . getErpKey(); // echo md5($md5str);die; //$str="accdb=ppt&usercode=ylp0019&key=a1e42219f7d651c8e8e09f331723df7e"; $getaccdb = strtolower(I('accdb')); $getusercode = strtolower(I('usercode')); $getkey = strtolower(I('key')); if ($getaccdb && $getusercode && $getkey) { $fieldstr = "accdb=" . $getaccdb . "&usercode=" . $getusercode . "&key=" . getErpKey(); $fieldstr1 = "accdb=" . $getaccdb . "&usercode=" . $getusercode . "&key=" . $getkey; //如果key不相等,报错 if ($getkey != md5($fieldstr)) { goUrl("/err_mobile.html?msg=非法参数"); return; } $res = M('store')->where("ERPId", $getaccdb)->field('store_id')->find(); if ($res) { goUrl("/mobile/sign/staffbinding/stoid/" . $res['store_id'] . "?" . $fieldstr1); } else { goUrl("/err_mobile.html?msg=找不到相关信息"); return; } } else { goUrl("/err_mobile.html?msg=参数为空"); return; } } //账套关注数 public function count_vipandsubscribe() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } //$postStr = "{\"accdb\":\"ppt\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $getstoid = 0; $res = M('store')->where('ERPId', $accdb)->field('store_id')->find(); if (empty($res)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "找不到对应账套!"; return json_encode($jsonres); } //关注 $sdate = strtotime(date('Y-m-d', time()) . " 00:00:00"); $edate = strtotime(date('Y-m-d', time()) . " 23:59:59"); $getstoid = $res['store_id']; $gzsql = "SELECT sum(case when a.issubscribe=1 then 1 else 0 end) gzsum,sum(case when a.issubscribe=0 then 1 else 0 end) cgzsum from (SELECT (case when issubscribe=0 then unsubscribe_date ELSE subscribe_date END)as real_date,issubscribe from wxd_wx_openlist where store_id=" . $getstoid . ") a where a.real_date>=" . $sdate . " and a.real_date<=" . $edate . ""; $gz_res = DB::query($gzsql);//今日关注 及今日取消 $gzcount = M('wx_openlist')->where('store_id=' . $getstoid . ' and issubscribe=1')->count();//总关注 $vipnum = M('users')->where('store_id=' . $getstoid . ' and erpvipid<>"" and reg_time>=' . $sdate . ' and reg_time<=' . $edate)->count();//今日绑定 $vipsum = M('users')->where('store_id=' . $getstoid . ' and erpvipid<>"" and mobile<>\'\' ')->count();//会员总绑定 $jsonres["STATE"] = 0; $jsonres["MSG"] = "ok"; $count["subscribenum"] = $gz_res[0]['gzsum']; $count["vipnum"] = $vipnum; $count["unsubscribenum"] = $gz_res[0]['cgzsum']; $count["subscribesum"] = $gzcount; $count["vipsum"] = $vipsum; $jsonres["count"] = $count; return json_encode($jsonres); } ///更新线上会员等级卡信息 public function updateviplevelintro() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "123"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } mlog($postStr, 'levelintro'); $postStr = json_decode($postStr, true); $dbaccid = $postStr['ACCID'];//账套 $erpvipid = $postStr['VIPID'];//线下vipid $res = M('store')->where('ERPId', $dbaccid)->field('store_id')->find(); $sql = ''; if ($res && $postStr['DATA']) { Db::startTrans(); try { foreach ($postStr['DATA'] as $k => $v) { $card_field = ''; switch ($v['CARD_FIELD']) { case 'Price1': $card_field = 'cardprice1'; break; case 'Price2': $card_field = 'cardprice2'; break; case 'Price3': $card_field = 'cardprice3'; break; default: break; } $sql = "update wxd_users set card_field='" . $card_field . "',card_expiredate='" . $v['CARD_EXPIREDATE'] . "' where erpvipid='" . $v['VIPID'] . "' and store_id=" . $res['store_id'] . ";"; mlog($sql, 'levelintro'); $result = M("users")->execute($sql); mlog('执行结果:' . $result, 'levelintro'); } Db::commit(); $jsonres["STATE"] = 1; $jsonres["MSG"] = "更新成功!"; } catch (\Exception $e) { // 回滚事务 Db::rollback(); $jsonres["STATE"] = -1; $jsonres["MSG"] = "更新失败!"; } } else { $jsonres["STATE"] = -1; $jsonres["MSG"] = "找不到相关账套信息!"; } return json_encode($jsonres); } public function opencardsetup() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "123"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } mlog('开通等级:' . $postStr, 'levelintro'); $postStr = json_decode($postStr, true); $dbaccid = $postStr['ACCID'];//账套 $res = M('store')->where('ERPId', $dbaccid)->field('store_id')->find(); $sql = ''; if ($res) { Db::startTrans(); try { $switch = M('store_config')->where('store_id', $res['store_id'])->field('switch_list')->find(); $switch = $switch['switch_list']; $switch_list = json_decode($switch, true);//获取开关列表 $switch_list['rank_switch'] = 2;//$param['rank_switch']; $data['switch_list'] = json_encode($switch_list); $result = D('store_config')->where('store_id', $res['store_id'])->save($data); Db::commit(); $jsonres["STATE"] = 1; $jsonres["MSG"] = "更新成功!"; } catch (\Exception $e) { // 回滚事务 Db::rollback(); $jsonres["STATE"] = -1; $jsonres["MSG"] = "更新失败!"; } } else { $jsonres["STATE"] = -1; $jsonres["MSG"] = "找不到相关账套信息!"; } return json_encode($jsonres); } //核销码核销 public function getcodepro() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr='{"CODE":"90072201811011653454400","ACCID":"ppt"}'; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $dbaccid = $postStr['ACCID'];//账套 $operator = $postStr['OPERATOR'];//操作员 $storagename = $postStr['STORAGENAME'];//线下门店 $code = $postStr['CODE'];//核销码 //测试 $res = M('store')->where('ERPId', $dbaccid)->field('store_id')->find(); $store_id = $res['store_id']; $tempcode = mb_substr($code, 0, 4); if ($res) { Db::startTrans(); try { if ($tempcode == 9007)//礼包核销 { $tempcode_next = mb_substr($code, 4, 1); if ($tempcode_next == 1 || $tempcode_next == 2) { $list = M('libao_listvip')->where("store_id=" . $store_id . " and freebh='" . $code . "' and goods_num>usenum")->field('id,lbvipid,goods_name,goods_sn,goods_num,usenum,user_id')->select(); if ($list[0]) { $getpaytype = 0; $libaoindex = M('libao_formvip')->where('id', $list[0]['lbvipid'])->find(); $getpaytype = $libaoindex['paytype'];//支付类型 if ($libaoindex['expdate'] > time()) { $libaoindex = M('libao_form')->where('id=' . $libaoindex['lbid'] . ' and store_id=' . $store_id)->find();//对应礼包活动 $user_id = $list[0]['user_id']; $res1 = M('users')->where(array('store_id' => $store_id, 'user_id' => $user_id))->find(); $jsonres['vipid'] = $res1['erpvipid']; if ($tempcode_next == 1)//(礼包单个) { $libaoindex['lbprice'] = 0; $list1 = M('libao_listvip')->where(array('freebh' => $code))->field('goods_sn,1 as goods_num')->select(); Db::execute("update wxd_libao_listvip set usenum=usenum+1,admdate=" . time() . " where freebh='" . $code . "'"); $data1['code'] = $code; $data1['user_id'] = $user_id; $data1['store_id'] = $store_id; $data1['billdate'] = time(); $data1['proid'] = $list[0]['id']; $data1['prodetails'] = json_encode($list); M('code_record')->add($data1); } else if ($tempcode_next == 2)//(礼包全部) { $list1 = M('libao_listvip')->where(array('freebh' => $code))->field('goods_sn,goods_num')->select(); Db::execute("update wxd_libao_listvip set usenum=goods_num,admdate=" . time() . " where freebh='" . $code . "'"); Db::execute('update wxd_libao_formvip set isget=1 where id=' . $list[0]['lbvipid']); $data1['code'] = $code; $data1['user_id'] = $user_id; $data1['store_id'] = $store_id; $data1['billdate'] = time(); $data1['proid'] = $list[0]['lbvipid']; $data1['prodetails'] = json_encode($list); $data1['storagename'] = $storagename; $data1['operator'] = $operator; M('code_record')->add($data1); } $jsonres["state"] = 1; $jsonres["msg"] = "获取成功!"; $jsonres["data"] = $list1; if ($getpaytype == 1)//积分兑换的话ERP那里显示为0 { $jsonres['sum'] = 0; } else { $jsonres['sum'] = $libaoindex['lbprice']; } $jsonres['actnumber'] = $libaoindex['id']; $jsonres['actname'] = $libaoindex['lbtitle']; } else { $jsonres["state"] = -1; $jsonres["msg"] = "兑换时间已过期"; } } else { unset($list); $list = M('code_record')->where(array('code' => $code))->find(); if ($list) { $getpaytype = 0; if ($tempcode_next == 1)//单个商品 { $libaoindex = M('libao_listvip')->where('id=' . $list['proid'])->find(); $libaoindex = M('libao_formvip')->where('id=' . $libaoindex['lbvipid'])->find(); $libaoindex = M('libao_form')->where('id=' . $libaoindex['lbid'])->find(); $libaoindex['lbprice'] = 0; } else if ($tempcode_next == 2)//整个礼包 { $libaoindex = M('libao_formvip')->where('id=' . $list['proid'])->find(); $getpaytype = $libaoindex['paytype']; $libaoindex = M('libao_form')->where('id=' . $libaoindex['lbid'])->find(); } $user_id = $list['user_id']; $res1 = M('users')->where(array('store_id' => $store_id, 'user_id' => $user_id))->find(); $jsonres['vipid'] = $res1['erpvipid']; $list1 = json_decode($list['prodetails'], true); foreach ($list1 as $k => $vo) { $list2[$k]['goods_sn'] = $vo['goods_sn']; if ($tempcode_next == 1) { $list2[$k]['goods_num'] = 1; } else { $list2[$k]['goods_num'] = $vo['goods_num']; } } $jsonres["state"] = 0; $jsonres["msg"] = "该核销码已核销"; $jsonres['data'] = $list2; if ($getpaytype == 1) { $jsonres['sum'] = 0; } else { $jsonres['sum'] = $libaoindex['lbprice']; } $jsonres['actnumber'] = $libaoindex['id']; $jsonres['actname'] = $libaoindex['lbtitle']; } else { $jsonres["state"] = -1; $jsonres["msg"] = "找不到该核销码"; } } } else { $jsonres["state"] = -1; $jsonres["msg"] = "请输入正确核销码"; } } else { $jsonres["state"] = -1; $jsonres["msg"] = "请输入正确核销码"; } Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); mlog($e . message, 'getcodepro'); $jsonres["state"] = -1; $jsonres["msg"] = "获取失败!"; } } else { $jsonres["state"] = -1; $jsonres["msg"] = "找不到相关账套信息!"; } $jsonres['acttag'] = $tempcode; mlog('返回值:' . json_encode($jsonres), 'getcodepro'); return json_encode($jsonres); } //根据账套和typeid获取 public function getwxtemplateinfo() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"accdb\":\"ppt\",\"typeid\":\"1014\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $typeid = $postStr['typeid']; $accdb = $postStr['accdb']; $wxtype_res = M('wx_sendlist')->alias('a') ->join('store b', 'a.store_id=b.store_id', 'left') ->where(array("b.ERPId" => $accdb, "a.typeid" => $typeid)) ->field('a.template_id,a.htmlurl,a.store_id,a.template_type') ->find(); if (empty($wxtype_res)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "该账套没有设置该模板!"; return json_encode($jsonres); } if (empty($wxtype_res['htmlurl'])) { $wxtype_res['htmlurl'] = curHostURL() . "/mobile/User/index/stoid/" . $wxtype_res['store_id']; } $jsonres["STATE"] = 1; $jsonres["MSG"] = "ok"; $jsonres["data"][0] = $wxtype_res; return json_encode($jsonres); } //根据商户ID public function get_wxtoken() { //判断是否过了缓存期 $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"accdb\":\"ppt\",\"isupdate\":'\"1\}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $isupdate = $postStr['isupdate']; $wechat = M('wx_user')->alias("a") ->join('store b', 'a.store_id=b.store_id', 'left') ->field('a.*') ->where(array('b.erpid' => $accdb))->find(); $jsonres["STATE"] = 1; $jsonres["MSG"] = "ok"; $jsonres["access_token"] = erp_get_access_token($wechat, $wechat['store_id'], $isupdate); return json_encode($jsonres); } //根据商户广告 public function get_accdbgg() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } //$postStr = "{\"accdb\":\"ppt\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } mlog("显屏" . $postStr, "get_accdbgg"); $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $storageid = $postStr['storageid']; $storeres = M('store')->where(array('erpid' => $accdb))->find(); if (empty($storeres)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "没有数据"; return json_encode($jsonres); } $stoid = $storeres['store_id']; $pickres = M('pick_up')->where(array('store_id' => $stoid, 'keyid' => $storageid))->find(); $where = "pid=601 and enabled = 1 and start_time <= " . time() . " and end_time >= " . time() . " and store_id=" . $stoid; $where1 = ""; if ($pickres) { $getpickupid = $pickres['pickup_id']; $where1 = "(intype=0 or (intype=2 and find_in_set(" . $getpickupid . ",pickup_listid)>0) or (intype=1 and find_in_set(" . $getpickupid . ",pickup_listid)<=0))"; } $adimg = M('ad') ->where($where) ->where($where1) ->order('orderby asc') ->select(); if (empty($adimg)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "没有数据"; return json_encode($jsonres); } $jsonres["STATE"] = 1; $jsonres["MSG"] = "ok"; if ($getpickupid) { $jsonres["url"] = curHostURL() . "/home/Erpgg/index/stoid/" . $stoid . "/pickupid/" . $getpickupid . ".html"; } else { $jsonres["url"] = curHostURL() . "/home/Erpgg/index/stoid/" . $stoid . ".html"; } return json_encode($jsonres); } //安卓64位图片上传 public function getupimg() { $reimgname = time() . microtime_float(); $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } mlog($postStr, "getupimg"); if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $imgurl = str_replace("str64=", "", urldecode($postStr)); $image_type = "jpg"; $resimg = $this->saveimg($imgurl, "temp", $image_type); $jsonres["STATE"] = 1; $jsonres["MSG"] = "OK"; $jsonres["imgurl"] = $resimg; return json_encode($jsonres); } function saveimg($contents, $subweb_id, $face_image_type, $date = null) { if ($date) { $date = $date; } else { $date = date('Y') . '/' . date('m-d'); } $uploadpath = './public/upload/mchat/' . $subweb_id . '/' . $date . '/'; $ypath = '/public/upload/mchat/' . $subweb_id . '/' . $date . '/'; $img = base64_decode($contents); if (!file_exists(ROOT_PATH . $uploadpath)) { mkdir($uploadpath, 0777, true); } $reimgname = str_replace('.', '', microtime_float()); $simg = $reimgname . '.' . $face_image_type . ''; $imgname = $uploadpath . $simg; $a = file_put_contents($imgname, $img);//返回的是字节数 //保存到存储云 vendor('qcloudcos.myqcloudcos'); $resfolder = Myqcloudcos::statFolder($this->ybpath, $ypath); if ($resfolder && $resfolder['code'] != 0)//不存在创建 { Myqcloudcos::createFolder($this->ybpath, $ypath); } $res = Myqcloudcos::upload($this->ybpath, ROOT_PATH . $uploadpath . $simg, $ypath . $simg); if ($res) { //删除本地 mdelFile(ROOT_PATH . $uploadpath . $simg); } return $reimgname; } //根据商户广告 public function getuserinfo() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"accdb\":\"ppt\",\"erpvipid\":\"8876f3cf-fb20-5173-a0c7-e6f663e6bc73\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $where = ""; $stoinfo = M('store')->where(array('erpid' => $accdb))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $userinfo = M('users')->alias("a") ->where(array('a.store_id' => $stoinfo['store_id'], 'a.erpvipid' => $postStr['erpvipid'])) ->field('a.mobile,a.nickname,a.head_pic') ->find(); if ($userinfo) { $jsonres["STATE"] = 1; $jsonres["MSG"] = "ok"; $jsonres["data"] = $userinfo; } else { $jsonres["STATE"] = -1; $jsonres["MSG"] = "没有数据"; } return json_encode($jsonres); } /** * 根据账套和线下商品ID进行更新商品 * */ public function updateGoodsInfo() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"accdb\":\"ppt\",\"erpwareid\":\"8876f3cf-fb20-5173-a0c7-e6f663e6bc73\",\"wareno\":\"11\",\"barcode\":\"22\",\"posprice\":\"33\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $geterpwareid = $postStr['erpwareid']; $getwareno = $postStr['wareno']; $getbarcode = $postStr['barcode']; $getposprice = $postStr['posprice']; if (empty($geterpwareid) || empty($getwareno) || empty($getbarcode) || empty($getposprice)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json_encode($jsonres); } $where = ""; $stoinfo = M('store')->where(array('erpid' => $accdb))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $goodsinfo = M('goods')->alias("a") ->where(array('a.store_id' => $stoinfo['store_id'], 'a.erpwareid' => $geterpwareid)) ->find(); if (empty($goodsinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "商品不存在!"; return json_encode($jsonres); } $postdata['goods_sn'] = $getwareno; $postdata['sku'] = $getbarcode; $postdata['market_price'] = $getposprice; $flagGoods = M('goods') ->where(array('store_id' => $stoinfo['store_id'], 'goods_id' => $goodsinfo['goods_id'])) ->save($postdata); $return_arr = array('STATE' => 1, 'msg' => '操作成功'); return json_encode($return_arr); } /** * 根据账套和线下会员ID进行更新会员 * */ public function updateUserInfo() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } //$postStr = "{\"accdb\":\"ppt\",\"erpvipidlist\":[\"473ad2bf-df8f-418e-a902-0658fc38090b\"]}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; mlog(json_encode($postStr), "updateUserInfo/" . $accdb); $erpvipidlist = $postStr['erpvipidlist']; if (empty($erpvipidlist) || empty($accdb)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json_encode($jsonres); } $where = ""; $stoinfo = M('store')->where(array('erpid' => $accdb))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } foreach ($erpvipidlist as $key => $value) { $postdata['erpvipid'] = ""; $postdata['erpvipno'] = ""; $flagUser = M('users') ->where(array('store_id' => $stoinfo['store_id'], 'erpvipid' => $value)) ->save($postdata); } $return_arr = array('STATE' => 1, 'msg' => '操作成功'); return json_encode($return_arr); } /** * 根据账套和门店ID更新 * */ public function updateStorageInfo() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } //$postStr = "{\"accdb\":\"PPT\",\"keyidlist\":[\"8395C675-CCAE-49A5-80A3-B7E2BEF274CC\"]}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; mlog(json_encode($postStr), "updateStorageInfo/" . $accdb); $keyidlist = $postStr['keyidlist']; if (empty($keyidlist) || empty($accdb)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json_encode($jsonres); } $where = ""; $stoinfo = M('store')->where(array('erpid' => $accdb))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } foreach ($keyidlist as $key => $value) { $postdata['isstop'] = 1; $flagUser = M('pick_up') ->where(array('store_id' => $stoinfo['store_id'], 'keyid' => $value)) ->save($postdata); } $return_arr = array('STATE' => 1, 'msg' => '操作成功'); return json_encode($return_arr); } /** * 根据账套和线下会员ID更新PLUS会员卡时间 * */ public function updateCardInfo() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"accdb\":\"ppt\",\"erpvipid\":\"473ad2bf-df8f-418e-a902-0658fc38090b\",\"card_expiredate\":\"2019-11-30\",\"card_field\":\"cardprice1\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; mlog(json_encode($postStr), "updateCardInfo/" . $accdb); $geterpvipid = $postStr['erpvipid']; $getcard_expiredate = $postStr['card_expiredate']; if (empty($geterpvipid) || empty($accdb) || empty($getcard_expiredate)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json_encode($jsonres); } $where = ""; $stoinfo = M('store')->where(array('erpid' => $accdb))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json_encode($jsonres); } $postdata['card_expiredate'] = $getcard_expiredate; if ($postStr['card_field']) { $postdata['card_field'] = $postStr['card_field']; } $flagUser = M('users') ->where(array('store_id' => $stoinfo['store_id'], 'erpvipid' => $geterpvipid)) ->save($postdata); if (empty($flagUser)) { $return_arr = array('STATE' => 0, 'msg' => '更新失败'); return json_encode($return_arr); } $return_arr = array('STATE' => 1, 'msg' => '操作成功'); return json_encode($return_arr); } /** * 根据账套和门店ID更新 * fromtype 1=POS销售 2=预约核销 3=项目核销 * */ public function yy_wxsend() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } //$postStr = "{\"accdb\":\"ppt\",\"erpvipid\":\"0eaa411dff463588a6b332443a97921d\",\"fromid\":\"1BADE9B7-1868-4FF2-A8BC-1D79FFC8748C\",\"projectname\":\"美甲\",\"billdate\":\"2019-12-03 16:42:08\",\"storagename\":\"小郑门店\",\"fromtype\":\"3\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $erpvipid = $postStr['erpvipid']; $fromtype = $postStr['fromtype']; $fromid = $postStr['fromid']; $projectname = $postStr['projectname']; $storagename = $postStr['storagename']; $billdate = $postStr['billdate']; if (empty($accdb) || empty($erpvipid) || empty($fromtype) || empty($fromid)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json($jsonres); } $stoinfo = M('store')->where(array('erpid' => $accdb, 'is_audit' => 1))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "该账套未开通手店!"; return json($jsonres); } $getstoid = $stoinfo['store_id']; $storewxinfo = M('wx_user')->where(array('store_id' => $getstoid, 'appid' => array('neq', '')))->find(); if (empty($stoinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "该账套授权公众号!"; return json($jsonres); } $userinfo = M('users')->where(array('store_id1' => $getstoid, 'erpvipid' => $erpvipid, 'openid' => array('neq', '')))->find(); if (empty($userinfo)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "该用户不是微信会员!"; return json($jsonres); } $typeid = "1027"; $wxsend = M('wx_sendlist')->alias('a') ->join('wx_sendtype b', 'a.typeid=b.typeid') ->where(array('a.store_id' => $userinfo['store_id'], 'a.typeid' => $typeid))->find(); if (empty($wxsend)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "商家未设置推送模板!"; return json($jsonres); } $colorlist = urlencode("#FF0000|#173177|#173177|#173177|#173177|#173177|#FF0000|#ca003a"); $remark = "感谢您的使用,评价有惊喜,点击即刻评价!"; $pd['title'] = "你的订单已成功核销"; $pd['key1'] = $projectname; $pd['key2'] = $billdate; $pd['key3'] = $storagename; $pd['remark'] = $remark; $mdataarr = explode(",", $wxsend["myfieldlist"]); $postdata = null; /*--双数组,确定推送内容--*/ $i = 0; foreach ($mdataarr as $ku => $vu) { $postdata[$i . ''] = $pd[$vu]; $i++; } $postdata['colorlist'] = $colorlist; $backurl = curHostURL() . "/index.php/Mobile/Yyservice/yy_evaluate/stoid/" . $getstoid . "/fromid/" . urlencode($fromid) . "/fromtype/" . $fromtype . ".html"; $jssdk = new \app\mobile\logic\Jssdk($storewxinfo['appid'], $storewxinfo['appsecret']); $r = $jssdk->WeiXin_MassageModelSend($userinfo['store_id'], $userinfo['openid'], $wxsend['typeid'], $backurl, $postdata); if ($r['wxcode'] != 0) { $return_arr = array('STATE' => -1, 'msg' => '发送失败' . $r['msg'], 'data' => '',); return json($return_arr); } $return_arr = array('STATE' => 1, 'msg' => '发送成功', 'data' => ''); return json($return_arr); } //更新账套是否启用会员权益 public function updateGradeSet() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"accdb\":\"ppt\",\"isBool\":1}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $accdb = strtolower($accdb); $isBool = $postStr['isBool']; if (empty($accdb)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json($jsonres); } if ($isBool) { $jsonvalue = "{\"isBool\":true}"; } else { $jsonvalue = "{\"isBool\":false}"; } setRedisKey("erp", "grade", ":init:" . $accdb, $jsonvalue, 1 * 24 * 60 * 60); $return_arr = array('STATE' => 1, 'msg' => '成功', 'data' => ''); return json($return_arr); } //会员绑定异常回调 public function vipErrorApi() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr = "{\"Id\":\"6a192a7a-c936-bf48-be6a-7898d40f914b\",\"VIPNo\":\"13469461558\",\"VIPName\":\"13469461558\",\"Sex\":\"\",\"State\":\"正式\",\"BirthDate\":\"\",\"GBirthDate\":\"\",\"MobileTel\":\"13469461558\",\"Address\":\"\",\"Islunar\":true,\"Tel\":\"\",\"IDCard\":\"\",\"Integral\":\"\",\"IsMonth\":false,\"IsDay\":false,\"PassValidate\":false,\"VIPPass\":\"\",\"StoragesId\":\"\",\"StorageNo\":\"\",\"StorageName\":\"\",\"IntroducerVIPID\":\"\",\"Remark\":\"\",\"property1\":\"ou608vxICjfs4F59-yxPI-uoHX5k\",\"property6\":\"1\",\"accdb\":\"ppt\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "参数有误!"; return json($jsonres); } $postStr = json_decode($postStr, true); $accdb = $postStr['accdb']; $accdb = strtolower($accdb); $erpvipid = $postStr['Id']; $openid = $postStr['property1']; $mobile = $postStr['MobileTel']; $first_leader = $postStr['first_leader'];//是否分享人 $fromuser_id = $postStr['fromuser_id'];//介绍人 if (empty($accdb) || empty($erpvipid) || empty($openid) || empty($mobile)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,参数不全!"; return json($jsonres); } $store = M('store')->where(array('ERPId' => $accdb))->find(); if (empty($store)) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,该账套未开通手店!"; return json($jsonres); } $stoid = $store['store_id']; $userinfo_1 = M('users')->where(array('store_id' => $stoid, 'erpvipid' => $erpvipid, 'mobile' => $mobile, 'erpvipno' => array('neq', '')))->find(); if ($userinfo_1) { $jsonres["STATE"] = -1; $jsonres["MSG"] = "操作失败,该手机已绑定成功!"; return json($jsonres); } $ceshi_user = M('users')->where(array('mobile' => $mobile, 'store_id' => $stoid))->find(); $is_olduserinfo = 0; //判断如果openid为空且手机有值的话,取旧的 if ($ceshi_user['mobile'] && empty($ceshi_user['openid'])) { $is_olduserinfo = 1; $user_info = $ceshi_user; } else { $user_info = M('users')->where(array('openid' => $openid, 'store_id' => $stoid))->find(); } $map['erpvipid'] = $postStr['Id']; $map['erpvipno'] = $postStr['VIPNo']; $map['vipname'] = $postStr['VIPName']; $map['openid'] = $postStr['property1']; switch ($postStr['Sex']) { case "男": $map['sex'] = 1; break; case "女": $map['sex'] = 2; break; default: $map['sex'] = 0; break; } if ($postStr['IDCard']) { $map['idcard'] = $postStr['IDCard']; } $map['birthday'] = strtotime($postStr['BirthDate']); $map['islunar'] = $postStr['Islunar'] == '1' ? 1 : 2; if ($postStr['Address']) { $map['address'] = $postStr['Address']; } $map['mobile'] = $postStr['MobileTel']; if ($postStr['EMail']) { $map['email'] = $postStr['EMail']; } $pick = M("pick_up")->where("keyid", $postStr['StoragesId'])->where("keyid<>''")->field("pickup_id")->find(); if ($pick) { $map['pickup_id'] = $pick['pickup_id']; } //判断PLUS是否有值 if ($postStr['GradeCardID'] && $postStr['ExpiryDate']) { $switch_list = tpCache('basic.switch_list', $stoid); if ($switch_list) { $switch_list=json_decode($switch_list,true); $rank_switch=$switch_list['rank_switch']; if ($rank_switch==2) { $Cardwhere['CardId']=$postStr['GradeCardID']; $rs_cardset = getApiData_java_p("/api/erp/vip/mem/bership/get", $accdb, $Cardwhere, 1, 10, null, "GET"); if ($rs_cardset) { $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="cardprice2"; break; case "Price3": $getcard_field="cardprice3"; break; } $map['card_expiredate'] = $postStr['ExpiryDate']; $map['card_field'] = $getcard_field; } } } } $map['reg_time'] = time();//绑定重新更新注册时间 $map['mobile_validated'] = 1; // 成为分销商条件 $distribut_condition = tpCache('distribut.condition', $stoid); $distribut_switch = tpCache('distribut.switch', $stoid); if ($distribut_switch === 1 && $distribut_condition === 0) // 本来要购买成为分销,后来商家改为直接注册就可以成为分销商进行更改 { //判断分销可以注册的人数 $distr_num = M('store_distribut')->where('store_id', $stoid)->field('distribut_num')->find(); $count1 = M("users")->where('store_id', $stoid)->where('is_distribut', 1)->count(); if ($distr_num['distribut_num'] > $count1) { $map['is_distribut'] = 1; $map['be_distribut_time'] = time(); $map['be_dis_condition'] = "直接购买成为分销商"; } else { $is_out = M("store_module_endtime")->where('store_id', $stoid)->where('type', 2)->find(); if (empty($is_out)) { $yy = M('distri_price')->where('type', 0)->where('money', 0)->find(); $allnum = $yy['user_num']; if ($allnum > $count1) { $map['is_distribut'] = 1; $map['be_distribut_time'] = time(); $map['be_dis_condition'] = "直接购买成为分销商"; } } } } //分享人 $first_info = null; if ($first_leader != "") { $first_info = M('users')->where(array('user_id' => $first_leader, 'store_id' => $stoid))->find(); if ($first_info) { $map['Inviter_id'] = $first_leader; } if ($first_info && $first_info['is_distribut'] == "1") { $map['first_leader'] = $first_leader; } else { //往上找会员是否的分销商, //如果是分销商则注册会员的 first_leader 就是此分销商 $first_info0 = M('users')->where(array('user_id' => $first_info['first_leader'], 'store_id' => $stoid))->find(); if ($first_info0 && $first_info0['is_distribut'] == "1") { $map['first_leader'] = $first_info0['user_id']; } } if ($map['first_leader']) { $first_leader = M('users')->where("user_id", $map['first_leader'])->field("first_leader,second_leader")->find(); $map['second_leader'] = $first_leader['first_leader']; // 第一级推荐人 $map['third_leader'] = $first_leader['second_leader']; // 第二级推荐人 //他上线分销的下线人数要加1 M('users')->where(array('user_id' => $map['first_leader']))->setInc('underling_number'); M('users')->where(array('user_id' => $map['second_leader']))->setInc('underling_number'); M('users')->where(array('user_id' => $map['third_leader']))->setInc('underling_number'); } else { $map['first_leader'] = 0; } //如果邀请人存在,要弄个token if ($first_info) { $first_info['api_token'] = tpCache('shop_info.api_token', $stoid); } } //--介绍人-- $intr_user = null; if ($fromuser_id) { $map['fromuser_id'] = $fromuser_id; } // if (empty($user_info)) { $map['store_id'] = $stoid; $falg = M('users')->save($map);//线上用户信息 } else { $falg = M('users')->where(array('store_id' => $stoid, 'user_id' => $user_info["user_id"]))->save($map);//线上用户信息 } if (empty($falg)) { $return_arr = array('STATE' => -1, 'msg' => '线上保存失败', 'data' => ''); return json($return_arr); } if ($is_olduserinfo) { M('users')->where(array('store_id' => $stoid, 'user_id' => array('neq', $user_info['user_id']), 'openid' => $openid, 'mobile' => array('eq', '')))->delete(); } $sto_erpid = $accdb; //如果是新会员才增 if (empty($is_olduserinfo)) { $r = M('usercount')->where('daynum', date("Y-m-d"))->where('store_id', $stoid)->find(); if ($r) { $dd['new_vipnum'] = $r['new_vipnum'] + 1; $dd['sum_vipnum'] = $r['sum_vipnum'] + 1; M('usercount')->where('id', $r['id'])->save($dd); } else { //最大数 $r0 = M('usercount')->where('store_id', $stoid)->Max('daynum'); $dd['daynum'] = date("Y-m-d"); $dd['store_id'] = $stoid; $dd['new_vipnum'] = 1; if ($r0) { $dd['sum_vipnum'] = $r0 + 1; } else { //统计的数量 $num = M('users')->where('store_id', $stoid)->where("mobile<>''") ->count(); $dd['sum_vipnum'] = $num; } M('usercount')->save($dd); } } $news_info = M("users")->where("user_id", $user_info['user_id'])->find(); $reg_type = tpCache('basic.reg_type', $stoid); $logic = new UsersLogic(); //默认的注册规则 if ($reg_type == 0) { /*--读取默认注册属性--*/ $reg_def = tpCache('basic.reg_default', $stoid); $reg_default = json_decode($reg_def, true); $reg_def_ty = $reg_default['reg_def_ty']; if ($reg_def_ty == 0) {//积分 //如果赠送的积分大于0 if ($reg_default['jf'] > 0) { /*--- $data = array( 'VIPId' => $news_info["erpvipid"],//会员id 'OrderNo' => date('YmdHis') . rand(1000, 9999),//单号 'Integral' => $reg_default['jf'],//积分 'Remark' => '注册送积分', ); $add_rs = getApiData_java_p("/api/erp/vip/integral/update", $sto_erpid, $data, 1, 10, null, "PUT");--*/ com_update_integral($sto_erpid,$news_info,$reg_default['jf'],'注册送积分',$module="vipErrorApi"); } } else if ($reg_def_ty == 2) {//成长值 //--如果赠送的成长值大于0-- if ($reg_default['reg_cz'] > 0 && $sto_erpid) { $logic->send_czz($news_info['erpvipid'], $reg_default['reg_cz'], $sto_erpid, "注册赠送成长值"); } } else { if ($reg_default['coupon'] != "") {//优惠券 $coupon = M("coupon")->where(array("id" => $reg_default['coupon'], 'send_start_time' => array('elt', time()), 'send_end_time' => array('egt', time())))->find(); if ($coupon) { $logic->reg_send_quan($coupon, $news_info, $sto_erpid, $stoid); } } } } //自定义 else { $reg_info = json_decode(tpCache('basic.reg_info', $stoid), true); $jf = 0; $czz = 0; if (!empty($reg_data['name']) && $reg_info['name_state'] == 1) { if ($reg_info['name_val_type']) { $czz += $reg_info['name']; } else { $jf += $reg_info['name']; } } if (!empty($reg_data['birthday']) && $reg_info['birthday_state'] == 1) { if ($reg_info['birthday_type']) { $czz = $reg_info['birthday']; } else { $jf += $reg_info['birthday']; } } if (!empty($reg_data['idcard']) && $reg_info['idcard_state'] == 1) { if ($reg_info['idcard_type']) { $czz += $reg_info['idcard']; } else { $jf += $reg_info['idcard']; } } if (!empty($reg_data['address']) && $reg_info['address_state'] == 1) { if ($reg_info['address_type']) { $czz += $reg_info['address']; } else { $jf += $reg_info['address']; } } if (!empty($reg_data['pickup_id']) && $reg_info['pick_state'] == 1) { if ($reg_info['pick_type']) { $czz += $reg_info['pick']; } else { $jf += $reg_info['pick']; } } if (!empty($reg_data['sex']) && $reg_info['sex_state'] == 1) { if ($reg_info['sex_state_type']) { $czz += $reg_info['sex']; } else { $jf += $reg_info['sex']; } } //存在会员 if (!empty($reg_data['fromuser_id']) && $reg_info['introducer_state'] == 1) { if ($reg_info['introducer_type']) { $czz += $reg_info['introducer']; } else { $jf += $reg_info['introducer']; } } if ($jf > 0 && $sto_erpid) { /*--- $data = array( 'VIPId' => $news_info["erpvipid"],//会员id 'OrderNo' => date('YmdHis') . rand(1000, 9999),//单号 'Integral' => $jf,//积分 'Remark' => '注册送积分', ); $add_rs = getApiData_java_p("/api/erp/vip/integral/update", $sto_erpid, $data, 1, 10, null, "PUT");--*/ com_update_integral($sto_erpid,$news_info,$jf,'注册送积分',$module="vipErrorApi"); } if ($czz > 0 && $sto_erpid) { $logic->send_czz($news_info['erpvipid'], $czz, $sto_erpid, "注册赠送成长值"); } //优惠券 if ($reg_info['reginfo_coupon'] != "") { $coupon = M("coupon")->where(array("store_id" => $stoid, "id" => $reg_info['reginfo_coupon'], 'send_start_time' => array('elt', time()), 'send_end_time' => array('egt', time())))->find(); if ($coupon) { $logic->reg_send_quan($coupon, $news_info, $sto_erpid, $stoid); } } } $is_distri_rate = tpCache('distribut.is_distri_rate', $stoid); //分销商奖励 $is_invitation_rate = tpCache('distribut.is_invitation_rate', $stoid); //是否参与邀请送积分或代金券 //邀请赠送积分 if (!empty($first_info) && !empty($first_info['mobile']) && !empty($first_info['erpvipid']) ) { //如果上级会员是绑定,说明是通过链接进来,给发链接的用户赠送积分、优惠券 /*---当上级不是分销商 或者 开启分销商奖励,参与邀请送积分或代金券---*/ if ($first_info['is_distribut'] == 0 || $is_distri_rate == 0 || ($is_invitation_rate == 1 && $is_distri_rate == 1)) { $inv_type = tpCache('basic.inv_type', $stoid); $inv_info = tpCache('basic.invitation_rate', $stoid); $invitation_rate = json_decode($inv_info, true); /*--当上级的会员是绑定了的--*/ if ($inv_type == 0) { //邀请送积分 if ($invitation_rate['inv_jf'] && $sto_erpid) { /*--- $data = array( 'VIPId' => $first_info["erpvipid"],//会员id 'OrderNo' => date('YmdHis') . rand(1000, 9999),//单号 'Integral' => $invitation_rate['inv_jf'],//积分 'Remark' => '邀请送积分', ); $add_rs = getApiData_java_p("/api/erp/vip/integral/update", $sto_erpid, $data, 1, 10, null, "PUT");--*/ com_update_integral($sto_erpid,$first_info,$invitation_rate['inv_jf'],'邀请送积分',$module="vipErrorApi"); } } //---邀请送成长值--- else if ($inv_type == 2) { if ($sto_erpid) $logic->send_czz($first_info['erpvipid'], $invitation_rate['inv_cz'], $sto_erpid, "邀请赠送成长值"); } else { if ($invitation_rate['inv_coupon'] != "") { $coupon = M("coupon")->where(array("store_id" => $stoid, "id" => $invitation_rate['inv_coupon'], 'send_start_time' => array('elt', time()), 'send_end_time' => array('egt', time())))->find(); if ($coupon) { $logic->reg_send_quan($coupon, $first_info, $sto_erpid, $stoid, 1); } } } } } $wx_user = M('wx_user')->where('store_id', $stoid)->find(); $jssdk = new \app\mobile\logic\Jssdk($wx_user['appid'], $wx_user['appsecret']); //会员绑定通知start (season 2018-08-03) $postdata[0] = "亲爱的" . $news_info['nickname'] . ",恭喜您成功绑定成为我们会员!"; $postdata[1] = $mobile; $postdata[2] = date('Y-m-d h:i:s', time()); $postdata[3] = "更多精彩进店参与,急速前进"; $r = $jssdk->WeiXin_MassageModelSend($stoid, $openid, "1007", "", $postdata); //会员绑定通知 end /*---当是分销商 且 开启分销商奖励---*/ if ($is_distri_rate == 1) { $ydd_str = tpCache('distribut.invitation_ratelist', $stoid); $ydd = json_decode($ydd_str, true); // 一级 分销商赚 的钱 if ($ydd['first_money'] > 0 && $first_info['is_distribut'] == 1) { // 微信推送消息 $tmp_user = $first_info; $rrs1 = $this->add_user_money($ydd['first_money'], $first_info['user_id']); if ($rrs1) { $odata['user_id'] = $first_info['user_id']; $odata['create_time'] = time(); $odata['money'] = $ydd['first_money']; $odata['remark'] = "线下一级注册"; $odata['store_id'] = $stoid; $odata['order_sn'] = "zc" . date("YmdHis") . rand(1000, 9999); $odata['status'] = 1; $odata['type'] = 4; M('withdrawals')->save($odata); if ($tmp_user['oauth'] == 'weixin') { $wx_content = "你的一级下线刚刚绑定,你获得 ¥" . $ydd['first_money'] . "奖励 !"; $first_res = $jssdk->push_msg($tmp_user['openid'], $wx_content); } } } // 二级 分销商赚 的钱 if ($news_info['second_leader'] > 0 && $ydd['second_money'] > 0) { $fuid2 = M('users')->where('store_id=' . $stoid . ' and user_id=' . $news_info['second_leader'])->find(); if ($fuid2 && $fuid2['is_distribut'] == 1) { $rrs2 = $this->add_user_money($ydd['second_money'], $fuid2['user_id']); if ($rrs2) { $odata['user_id'] = $fuid2['user_id']; $odata['create_time'] = time(); $odata['money'] = $ydd['second_money']; $odata['remark'] = "线下二级注册"; $odata['store_id'] = $stoid; $odata['order_sn'] = "zc" . date("YmdHis") . rand(1000, 9999); $odata['status'] = 1; $odata['type'] = 4; M('withdrawals')->save($odata); // 微信推送消息 $tmp_user = $fuid2; if ($tmp_user['oauth'] == 'weixin') { $wx_content = "你的二级下线刚刚绑定,你获得 ¥" . $ydd['second_money'] . "奖励 !"; $second_res = $jssdk->push_msg($tmp_user['openid'], $wx_content); mlog($news_info['mobile'] . "的二级[" . $tmp_user['mobile'] . "]推送返回:" . json_encode($second_res), 'smslog/' . $stoid); } } } } // 三级 分销商赚 的钱 if ($news_info['third_leader'] > 0 && $ydd['third_money'] > 0) { $fuid3 = M('users')->where('store_id=' . $stoid . ' and user_id=' . $news_info['third_leader'])->find(); if ($fuid3 && $fuid3['is_distribut'] == 1) { $rrs3 = $this->add_user_money($ydd['third_money'], $fuid3['user_id']); if ($rrs3) { $odata['user_id'] = $fuid3['user_id']; $odata['create_time'] = time(); $odata['money'] = $ydd['third_money']; $odata['remark'] = "线下三级注册"; $odata['store_id'] = $stoid; $odata['order_sn'] = "zc" . date("YmdHis") . rand(1000, 9999); $odata['status'] = 1; $odata['type'] = 4; M('withdrawals')->save($odata); // 微信推送消息 $tmp_user = $fuid3; if ($tmp_user['oauth'] == 'weixin') { $wx_content = "你的三级下线刚刚绑定,你获得 ¥" . $ydd['third_money'] . "奖励 !"; $third_res = $jssdk->push_msg($tmp_user['openid'], $wx_content); } } } } } $return_arr = array('STATE' => 1, 'msg' => '成功', 'data' => ''); return json($return_arr); } /*查询积分兑换错误未处理日志*/ public function getintegralfail() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr="{\"pagenum\":\"10\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["msg"] = "POST为空"; return json($jsonres); } $postjson = json_decode($postStr, true); $pagenum = $postjson['pagenum']; $pagenum = 100; if ($postjson['pagenum']) { $pagenum = $postjson['pagenum']; } $ACCDB = $postjson['accdb']; if ($ACCDB) { $where1['ERPId'] = $ACCDB; $where1['is_audit'] = 1; $store_res = M('store')->where($where1)->field('store_id')->find(); $getstoreid = $store_res['store_id']; $where['a.store_id'] = $store_res['store_id']; } $where['a.status']=0; $count = M('order_integral_fail')->alias("a")->where($where)->count(); $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数 $res = M('order_integral_fail')->alias("a") ->join('users b','a.store_id=b.store_id and a.user_id=b.user_id','left') ->join('store c','a.store_id=c.store_id','left') ->where($where) ->field('a.*,b.erpvipid,c.ERPId as accdb') ->limit($Page->firstRow . ',' . $Page->listRows) ->select(); if (empty($res)) { $jsonres["STATE"] = -2; $jsonres["MSG"] = "没有相关数据"; return json($jsonres); } $jsonres["STATE"] = 1; $jsonres["MSG"] = "ok"; $jsonres["list"] = $res; return json($jsonres); } /*处理积分兑换错误未处理日志*/ public function updateintegralfail() { $postStr = file_get_contents("php://input"); if (empty($postStr)) { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; } // $postStr="{\"store_id\":\"1\",\"user_id\":\"5682268\",\"order_sn\":\"ppt202001131020349592\",\"status\":\"1\"}"; if (empty($postStr)) { $jsonres["STATE"] = -1; $jsonres["msg"] = "POST为空"; return json($jsonres); } $postjson = json_decode($postStr, true); $getstoreid = $postjson['store_id']; $getuser_id = $postjson['user_id']; $getorder_sn = $postjson['order_sn']; $getstatus = $postjson['status'];//1=有扣积分已更新订单 2=无扣积分更新状态 if (empty($getstoreid) || empty($getuser_id) || empty($getorder_sn) || empty($getstatus)) { $jsonres["STATE"] = -1; $jsonres["msg"] = "参数不全"; return json($jsonres); } $where['store_id']=$getstoreid; $where['user_id']=$getuser_id; $where['order_sn']=$getorder_sn; $res = M('order_integral_fail')->alias("a")->where($where) ->find(); if (empty($res)) { $jsonres["STATE"] = -2; $jsonres["MSG"] = "没有相关数据"; return json($jsonres); } if ($getstatus==1) { //有扣积分的话更新订单状态 $orderinfo = M('order')->where(array('store_id' => $getstoreid, 'user_id' => $getuser_id, 'order_sn' => $getorder_sn, 'order_status' => 3, 'pay_status' => 0, 'integral' => array('neq', 0)))->find(); if ($orderinfo) { $updatedata['order_status'] = 1; $updatedata['pay_status'] = 1; M('order')->where(array('store_id' => $getstoreid, 'order_id' => $orderinfo['order_id']))->save($updatedata); M('order_action')->where(array('store_id' => $getstoreid, 'order_id' => $orderinfo['order_id'], 'action_note' => '购扣积分失败取消订单'))->delete(); } } $updata_fail['status']=$getstatus; $updata_fail['adm_time']=time(); M('order_integral_fail')->where(array('id'=>$res['id']))->save($updata_fail); $jsonres["STATE"] = 1; $jsonres["MSG"] = "ok"; return json($jsonres); } }