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']; } 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']; } } } //批量取消收藏 public function batchcancel_collect() { $sellist = I('sellist'); $getstoid = I('stoid'); if (empty($getstoid)) { return json(array('code' => -1, 'msg' => '参数有误!')); } $user_id = $this->user_id; if (empty($user_id)) { return json(array('code' => -1, 'msg' => '用户异常!')); } $where = 'collect_id in (' . $sellist . ')'; $delinfo = M('goods_collect')->where("store_id", $getstoid)->where($where)->where(array('user_id' => $user_id))->delete(); if (empty($delinfo)) { return json(['code' => -1, 'msg' => '删除成功!']); } return json(['code' => 0, 'msg' => '删除成功!']); } //修改默认物流 public function modi_def_exp_code() { $getshipping_code = I('shipping_code'); $getstoid = I('stoid'); if (empty($getstoid)) { return json(array('code' => -1, 'msg' => '参数有误!')); } if (empty($getshipping_code)) { return json(array('code' => -1, 'msg' => '请选择要设置的物流')); } $user_id = $this->user_id; if (empty($user_id)) { return json(array('code' => -1, 'msg' => '用户异常!')); } $shippinfo = M('store_shipping')->alias('a')->join('shipping b', 'a.shipping_id=b.shipping_id', 'left')->where(array('a.store_id' => $getstoid, 'b.shipping_code' => $getshipping_code, 'a.status' => 1))->find(); if (empty($shippinfo)) { return json(array('code' => -1, 'msg' => '设置失败,该记录不存在!')); } $updatadata['def_exp_code'] = $getshipping_code; $updateinfo = M('users')->where(array('store_id' => $getstoid, 'user_id' => $user_id))->save($updatadata); return json(array('code' => 0, 'msg' => '设置成功!')); } //新人礼广告 public function new_people() { $user_id = I('user_id/d', 0); $stoid = I('stoid/d', 0); if (empty($user_id) || empty($stoid)) { return json(array('code' => -1, 'msg' => '非法参数')); } $data["userId"] = $user_id; $data["storeId"] = $stoid; $newpeople = getApiData_mini("/api/weshop/marketing/newpeople/act/judge", $data, $stoid, 'GET', null, 1, 10); $newpeoples = json_decode($newpeople, true); if (empty($newpeoples)) { return json(array('code' => -1, 'msg' => '网络繁忙')); } if ($newpeoples ['code'] != 0) { return json(array('code' => -1, 'msg' => $newpeoples ['msg'])); } return json($newpeoples ); } /*新人弹窗*/ public function new_peolep_layui() { /* 判断新人礼包活动 海报弹窗接口判断*/ $user_id = I('user_id'); $stoid = I('stoid'); if (empty($user_id) || empty($stoid)) { return json(array('code' => -1, 'msg' => '非法参数')); } $data["userId"] = $user_id; $data["storeId"] = $stoid; $poster_newpeople = getApiData_mini("/api/weshop/marketing/newpeople/act/bound/judge", $data, $stoid, 'GET', null, 1, 10); if (empty($poster_newpeople)) { return json(array('code' => -1, 'msg' => '网络繁忙')); } return json_decode($poster_newpeople); } /* 生日营销图片显示*/ public function birthday_activities() { $user_id = I('user_id'); $id = I('stro_id'); $data["storeId"] = $id; $data['userId'] = $user_id; $birthday = getApiData_mini("/api/weshop/marketing/birthday/act/judge", $data, $id); $birthday_s = json_decode($birthday, true); if ($birthday_s['code'] != -1) { $data = $birthday_s['data']; $giftbagid = $data["giftbagid"]; $actId = $data['id']; $actImg=QCLOUD_IMGURL.$data['actImg']; return json(array('code' => 0, 'giftbagid' => $giftbagid, 'user_id' => $user_id, 'actId' => $actId, 'actType' => 4,'actImg'=>$actImg)); } else { return json(array('code' => -1,)); } } /* 节日营销*/ public function festival_activity (){ $user_id = I('user_id'); $id = I('stro_id'); if (empty($user_id) || empty($id)) { return json(array('code' => -1, 'msg' => '非法参数')); } $data["storeId"] = $id; $data['userId'] = $user_id; $birthday = getApiData_mini("/api/weshop/marketing/holiday/act/judge", $data, $id); $birthday_s = json_decode($birthday, true); if ($birthday_s['code'] != -1) { $data_festival = $birthday_s['data']; $giftbagid = $data_festival["gifBagId"]; $actId = $data_festival['id']; $actBoundImg=QCLOUD_IMGURL.$data_festival['actBoundImg']; $actImg=QCLOUD_IMGURL.$data_festival['actImg']; return json(array('code' => 0, 'giftbagid' => $giftbagid, 'user_id' => $user_id, 'actId' => $actId, 'actType' => 3,'actBoundImg'=>$actBoundImg,"actImg"=>$actImg)); } else { return json(array('code' => -1,)); } } //获取当个门店的线下库存 public function get_one_store() { $goods_id = I("goods_id"); $pick_id = I("pick_id"); $good = M("goods")->where("goods_id", $goods_id)->find(); //获取商品 $pick = M("pick_up")->where("pickup_id", $pick_id)->find(); //获取门店 $stoid = $good['store_id']; $wdata['WareIds'] = urlencode($good['erpwareid']); $wdata['StorageNos'] = urlencode($pick['pickup_no']); $accdb = tpCache("shop_info.ERPId", $stoid); mlog("获取线下库存:" . json_encode($wdata), "get_one_store/" . $stoid); $rs = getApiData_java_p("api/erp/sto/storages/page", $accdb, $wdata, 1, 1); mlog("获取线下库存:" . $rs, "get_one_store/" . $stoid); if ($rs) { $data = json_decode($rs, true); $dt = $data['data']; if (!empty($dt)) { if ($dt['pageData']) { //---线下库存判断预存是多少,组装map数组,快速查找--- $strq = 'select sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id=' . $goods_id . ' and store_id=' . $stoid . ' and pickup_id=' . $pick_id; $dd = Db::query($strq); $allnum = $dt['pageData'][0]['CanOutQty']; if ($dd) { $yc_num = $dd[0]['sum0']; $allnum = $allnum - $yc_num; } return json(["code" => 0, "data" => $allnum]); } } return json(["code" => -1, "msg" => '未找到门店']); } else { return json(["code" => -1, "msg" => '未找到门店']); } } //显示点击领取礼品 public function click_gift(){ $user_id = I('user_id'); $stoid = I('stoid'); $orderNumber=I('orderNumber'); //$data['orderNumber'] = $order_goods['order_id'];//商品订单号 $data['orderType'] =2;//评价类型 1=商城订单评价 2=美容师评价 $data['storeId'] = $stoid;//商家id $data['userId'] = $user_id;//用户id $data['orderNumber']=$orderNumber; $is_ceremony = getApiData_mini("/api/weshop/marketing/comment/act/judge", $data, getMobileStoId, 'GET'); $ceremony_data = json_decode($is_ceremony, true); $data_s=$ceremony_data ['data']; if($ceremony_data['code']==0){ return json(array('code' => 0,'gifbagid'=>$data_s['gifbagid'],'id'=>$data_s['id'])); }else{ return json(array('code' => -1)); } } public function storespage() { mlog("1","storespage/".$id); $pagenum = 10;//C('PAGESIZE'); //每页显示数 $p = I('p/d', 1); $id = getMobileStoId(); $lx = I('lx'); $ly = I('ly'); $where = ""; $getkey = I('key'); $storetype = I('storetype'); if ($getkey) { $where['pickup_name'] = array('like', '%' . htmlspecialchars($getkey) . '%'); } if ($storetype) { $where['category_id'] = $storetype; } $count = M('pick_up')->where($where)->count(); $Page = $pager = new Page($count,$pagenum); $list = M('pick_up') ->where("store_id=" . $id . " and isstop=0 ") ->where($where) ->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance') ->order('distance asc,pickup_id asc') ->limit($Page->firstRow.','.$Page->listRows)->select(); $list_str = M('pick_up') ->where("store_id=" . $id . " and isstop=0 ") ->where($where) ->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance') ->order('distance asc,pickup_id asc')->fetchSql(true) ->limit($Page->firstRow.','.$Page->listRows)->select(); mlog($list_str,"storespage/".$id); if (empty($list)) { $jsonlist['state'] = "0"; $jsonlist['msg'] = '找不到相数据'; return json($jsonlist); } foreach ($list as $k => $v) { $list[$k]['address'] = $v['fulladdress']; } $jsonlist['state'] = "1"; $jsonlist['msg'] = '成功'; $jsonlist['item'] = $list; return json($jsonlist); } //绑定选择门店 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 get_qy_user(){ $stoid=getMobileStoId(); $data['storeId']=$stoid; $data['userId']=$this->user_id; $qy_list=null;$qy_user=null;$backClass=null;$g_qy_list=null; $res=getApiData_mini("/api/weshop/users/grade/aftervipinfo/get",$data,$stoid); if(empty($res)) return json(['code'=>-1,'msg'=>'访问失败']); $u_data=json_decode($res,true); if($u_data && $u_data['code']===0){ $qy_user=$u_data['data']; //获取所有的券列表 $adata['storeId']=$stoid; $res=getApiData_mini("/api/weshop/users/grade/vipprivilegeinfo/page",$adata,$stoid); if(empty($res)) return json(['code'=>-1,'msg'=>'访问权益列表失败']); $qy_list=json_decode($res,true); if(empty($qy_list) && $qy_list['code']!=0 && !$qy_list['data'] & !$qy_list['data']['pageData']) return json(['code'=>-1,'msg'=>'访问权益列表失败']); $qy_list=$qy_list['data']['pageData']; //--获取卡类列表-- $res=getApiData_mini("/api/weshop/users/grade/vipgradeinfo/page",$adata,$stoid); if(empty($res)) json(['code'=>-1,'msg'=>'访问权益卡类失败']); $backClass=json_decode($res,true); if(empty($backClass) && $backClass['code']!=0 && !$backClass['data'] & !$backClass['data']['pageData']) return json(['code'=>-1,'msg'=>'访问权益列表失败']); $backClass=$backClass['data']['pageData']; //--获取会员已有的权益列表-- $adata['userId']=$this->user_id; $adata['GradeId']=$qy_user['GradeId']; $res=getApiData_mini("/api/weshop/users/grade/privilegeform/list/page",$adata,$stoid); if(empty($res)) json(['code'=>-1,'msg'=>'访问会员的权益失败']); $g_qy_list=json_decode($res,true); if(empty($g_qy_list) && $g_qy_list['code']!=0 && !$g_qy_list['data'] & !$g_qy_list['data']['pageData']) return json(['code'=>-1,'msg'=>'访问会员权益列表失败']); $g_qy_list=$g_qy_list['data']['pageData']; $data['qy_user']=$qy_user; $data['qy_list']=$qy_list; $data['backClass']=$backClass; $data['g_qy_list']=$g_qy_list; return json(['code=0','data'=>$data]); }else{ if(empty($res)) return json(['code'=>-1,'msg'=>'获取会员权益失败']); } } }