order login site wxapp

                        order
var
e = getApp(); import http from '../util/request.js'; // 创建页面实例对象 Page({ /** * 页面名称 */ name: "order", /** * 页面的初始数据 */ data: { backTopValue: false, nodata: false, list: [], allPages: 0, page: 1, loadMoreData: "下拉加载更多", state:0, id:0, score1:0, score2:0, content:'', }, /** * 生命周期函数--监听页面加载 */ onLoad () { if (!wx.getStorageSync("user")) { wx.redirectTo({ url: '../login/login', }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady () { }, /** * 生命周期函数--监听页面显示 */ onShow () { this.setData({ state: 0, page: 1, }); this.getData(); }, /** * 生命周期函数--监听页面隐藏 */ onHide () { }, /** * 生命周期函数--监听页面卸载 */ onUnload () { }, onPullDownRefresh() { var self = this; setTimeout(function () { if (self.data.page < self.data.allPages) { self.setData({ page: self.data.page + 1 }); self.getData(); } else { self.setData({ loadMoreData: "没有数据了" }); } }, 300); }, onReachBottom() { var self = this; setTimeout(function () { if (self.data.page < self.data.allPages) { self.setData({ page: self.data.page + 1 }); self.getData(); } else { self.setData({ loadMoreData: "没有数据了" }); } }, 300); }, //以下为自定义点击事件 onPageScroll: function (e) { var that = this; var scrollTop = e.scrollTop var backTopValue = scrollTop > 150 ? true : false that.setData({ backTopValue: backTopValue }) }, backTop: function () { wx.pageScrollTo({ scrollTop: 0 }) }, getData:function(){ var that = this; http.get('order', { uid: wx.getStorageSync("user").id, page: that.data.page, state: that.data.state,}).then(data => { if (that.data.page == 1) { var tempArray = []; } else { var tempArray = that.data.list; } that.setData({ list: tempArray.concat(data.list), allPages: data.totalPage }); if (data.list.length == 0) { if (that.data.page == 1) { that.setData({ nodata: true }); } else { that.setData({ loadMoreData: '没有数据了' }); } } else { that.setData({ nodata: false }); } }); }, bindstate:function(e){ this.setData({ state: e.currentTarget.dataset.s, page: 1, id:0, }); this.getData(); }, topiuser:function(e){ wx.redirectTo({ url: '../uinfo/uinfo?id=' + e.currentTarget.dataset.id, }) }, topproject:function(e){ wx.redirectTo({ url: '../pinfo/pinfo?id=' + e.currentTarget.dataset.pid, }) }, callphone:function(e){ var mobile = e.currentTarget.dataset.s; wx.makePhoneCall({ phoneNumber: mobile }) }, quxiao:function(e){ var id = e.currentTarget.dataset.id; var that = this; wx.showModal({ title: '友情提示', content: '您确定取消该订单吗?', fail:function(){}, success:function(e){ if (e.confirm == false) return false; http.get('qx',{id:id}).then(data => { that.setData({ page: 1, }); that.getData(); }); } }) }, payment:function(e){ var id = e.currentTarget.dataset.id; var price = e.currentTarget.dataset.price; var that = this; http.get('pay', { price: price}).then(param => { wx.requestPayment({ 'timeStamp': param.timeStamp, 'nonceStr': param.nonceStr, 'package': param.package, 'signType': 'MD5', 'paySign': param.paySign, 'success': function (res) { http.get('pay2', { 'price': price, id: id,uid:wx.getStorageSync('user').id }).then(data => { wx.showToast({ title: '恭喜您付款成功,客服会马上和您联系', duration: 2500, }); setTimeout(function () { that.setData({ page: 1 }); that.getData(); }, 2500); }); }, 'fail': function (fail) { wx.showToast({ icon: 'none', title: '付款失败', duration: 3500, }); } }); }); }, comment:function(e){ var that = this; var id = e.currentTarget.dataset.id; var key = e.currentTarget.dataset.key; that.setData({ id: id}); that.setData({ content: that.data.list[key].comment.content || "", score1: that.data.list[key].comment.score1 || 0, score2: that.data.list[key].comment.score2 || 0 }); }, sliderchange1:function(e){ this.setData({ score1: e.detail.value}); }, sliderchange2: function (e) { this.setData({ score2: e.detail.value }); }, content:function(e){ this.setData({ content: e.detail.value }); }, sendComment:function(e){ var t = this; if (t.data.score1 == 0) { wx.showToast({ title: '服务技能必须大于0分', icon: "none", duration: 2500 }); return false; } if (t.data.score2 == 0) { wx.showToast({ title: '服务态度必须大于0分', icon: "none", duration: 2500 }); return false; } if (t.data.content == '') { wx.showToast({ title: '请填写评论内容', icon: "none", duration: 2500 }); return false; } var send = { uid: wx.getStorageSync("user").id, oid: t.data.id, content: t.data.content, score1: t.data.score1, score2: t.data.score2, }; http.post('comment', send).then(data => { if (data == 1) { wx.showToast({ title: '感谢您的支持,我们会做的更好!', icon: "none", duration: 3000, }) setTimeout(function () { t.setData({ id: 0, content: '', score1: 0, score2:0 }); t.getData(); }, 3000); } }); }, disComment:function(e){ this.setData({ id:0,score1:0,score2:0,content:"" }); } })
                 login
var
e = getApp(); import http from '../util/request.js'; Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { e.util.getUserInfo({ scuesss: function (rs) { console.log(rs); } }); }, bindGetUserInfo: function (a) { http.post('setuser',{ code: wx.getStorageSync("code"), nickName: a.detail.userInfo.nickName, avatar: a.detail.userInfo.avatarUrl, gender: a.detail.userInfo.gender, }).then(data => { wx.setStorageSync('user', data ); if (wx.getStorageSync("back")){ wx.redirectTo({ url: wx.getStorageSync("back"), }) }else{ wx.switchTab({ url: '../order/order', }) } }); }, back:function(e){ wx.switchTab({ url: '../index/index', }) } })
                         index.js
//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
       aa:'aa',
       bb:'bb',
       cc:'cc',
       dd:'dd',
       ee:'ee',
       content:'',
       tel:''
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onShow:function(){
    wx.onUserCaptureScreen(function (res) {
      console.log('用户截屏了')
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  bindButtonTap: function () {
    var that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: 'back',
      success: function (res) {
        that.setData({
          src: res.tempFilePath,
          aa:res.tempFilePath,
          bb:res.size,
          cc:res.duration,
         dd:res.height,
          ee:res.width,
        })
      }
    })
  },

up:function(){
  wx.chooseImage({
    success: function (res) {
      var tempFilePaths = res.tempFilePaths
      wx.uploadFile({
        url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
        filePath: tempFilePaths[0],
        name: 'file',
        formData: {
          'user': 'test'
        },
        success: function (res) {
          var data = res.data
          //do something
        }
      })
    }
  })

},

addr:function(){
  wx.getLocation({
    type: 'gcj02', //返回可以用于wx.openLocation的经纬度
    success: function (res) {
      var latitude = res.latitude
      var longitude = res.longitude
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        scale: 28
      })
    }
  })
},
zdl:function(){
  wx.vibrateLong({})
},
zdd: function () {
  wx.getScreenBrightness({})
},
msg:function(){
  wx.showToast({
    title: '盼盼成功',
    icon: 'none',
    duration: 2500
  })

},
load:function(){
  wx.showModal({
    title: '提示',
    content: '这是一个模态弹窗',
    success: function (res) {
      if (res.confirm) {
        console.log('用户点击确定')
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},
donav:function(){
  wx.showActionSheet({
    itemList: ['A', 'B', 'C'],
    success: function (res) {
      console.log(res.tapIndex)
    },
    fail: function (res) {
      console.log(res.errMsg)
    }
  })
},
  pagetitle:function(){
    wx.setNavigationBarTitle({
      title: '当前页面盼盼'
    })

  },
  tabar:function(){
    wx.setTabBarBadge({
      index: 1,
      text: '盼'
    })

  },
  rtabar:function(){
    wx.removeTabBarBadge({
      index:1
    })

  },
  content:function(e){
    this.setData({
      content:e.detail.value
    })
  },
  tel:function(e){
    this.setData({
      tel: e.detail.value
    })
  },
 submit:function(){
  if(this.data.content==''){
    wx.showToast({
      title: '内容不能为空',
    })
  }else if(!(/^1[3|4|5|6|7|8][0-9]{9}$/.test(this.data.tel))){
    wx.showToast({
      title: '电话号码格式不对',
    })
  }else{
    //提交到后台
    var that = this
    wx.showLoading({
      title: '数据提交中',
    })
              app.util.request({
                url:'entry/wxapp/consult',
                data:{
                  m:'lv_suo',
                  content:that.data.content,
                  tel:that.data.tel,
                },
                cachetime:30,
                success:function(res){
                  if(res.data.data.status == 'success'){
                    wx.showToast({
                      title: '添加成功',
                    })
                    wx.reLaunch({
                      url:"../index/index"
                    })
                  }
                },
                fail:function(){
                  failGo('请检查连接地址')
                }

              })
  }
 } ,
/*
addons.lv_suo/wxapp.php

public function doPageConsult(){
    global $_GPC,$_W;
    $data = array(
        'content'=>$_GPC['content'],
        'tel'=>$_GPC['tel'],
        'addtime'=>time(),
        'uniacid'=>$_W['uniacid']
    );
    $result = pdo_insert('lv_suo_consult',$data);

    if(!empty($result)){
        $errno = 0;
        $message=$tltal;
        $data = array('status'=>'susccse');
        return $this->result($errno,$message,$data);
    }

}

*/
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})

 

                   site
<?php
/**
 * md_daojia模块微站定义
 *
 * 
 * @url 
 */
defined('IN_IA') or exit('Access Denied');

class Md_daojiaModuleSite extends WeModuleSite {
    
    private $tb_banner = 'daojia_focus';
    private $tb_category = 'daojia_cat';
    private $tb_user = 'daojia_user';
    private $tb_addr = 'daojia_addr';
    private $tb_project = 'daojia_project';
    private $tb_poseal = 'daojia_poseal';
    private $tb_setup = 'daojia_setup';
    private $tb_order = 'daojia_order';
    private $tb_comment = 'daojia_comment';
    
    public function doWebSetup() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            $row = $this->getSetUpRow();
            if (checksubmit()) {
                $set = $_GPC['set'];
                $set['uniacid'] = $_W['uniacid'];
                if($row['id'] == 0){
                    pdo_insert($this->tb_setup, $set);
                }else{
                    pdo_update($this->tb_setup , $set , array('id' => $row['id']));
                }
                message('保存成功',$this->createWebUrl('setup', array('op'=>'display')),'success');
            }    
            load()->func('tpl');
            include $this->template('setup');
        }
    }
    public function doWebFocus() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display', 'create', 'delete')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            $banner = $this->getAllBanner();
            load()->func('tpl');
            include $this->template('banner');    
        }else if ($op == 'create') {
            $id = intval($_GET['id']);
            if($id > 0){
                $sql = 'SELECT * FROM '.tablename($this->tb_banner).' WHERE id=:id AND uniacid=:uniacid LIMIT 1';
                $params = array(':id'=>$id, ':uniacid'=>$_W['uniacid']);
                $rs = pdo_fetch($sql, $params);
            }
            if (checksubmit()) {
                $banner = $_GPC['focus'];
                $banner['uniacid'] = $_W['uniacid'];
                $banner['displayorder'] = $banner['displayorder'] ? $banner['displayorder'] : 255;
                if($id == 0){
                    pdo_insert($this->tb_banner, $banner);
                }else{
                    pdo_update($this->tb_banner , $banner , array('id' => $id));
                }
                message('保存成功',$this->createWebUrl('focus', array('op'=>'display')),'success');
            }
            include $this->template('banner');
        }else if($op == 'delete'){
            $id = intval($_GPC['id']);
            if(empty($id)){
                message('未找到指定ID');
            }
            $result = pdo_delete($this->tb_banner, array('id'=>$id, 'uniacid'=>$_W['uniacid']));
            if(intval($result) == 1){
                message('删除焦点图成功.', $this->createWebUrl('focus' , array('op'=>'display')), 'success');
            } else {
                message('删除焦点图失败.');
            }
        }
    }
    public function doWebCat() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display', 'create', 'delete')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            $pid = intval($_GPC['pid']);
            $categories = $this->getAllCategory($pid);
            load()->func('tpl');
            include $this->template('category');    
        }else if ($op == 'create') {
            $id = intval($_GET['id']);
            if($id > 0){
                $sql = 'SELECT * FROM '.tablename($this->tb_category).' WHERE id=:id AND uniacid=:uniacid LIMIT 1';
                $params = array(':id'=>$id, ':uniacid'=>$_W['uniacid']);
                $rs = pdo_fetch($sql, $params);
            }
            if($_GPC['pid'] > 0){
                $rs['pid'] = intval($_GPC['pid']);
            }
            $options = $this->getAllOption($rs['pid'] ? $rs['pid'] : 0);
            if (checksubmit()) {
                $category = $_GPC['category']; // 获取打包值
                if(empty($category['cname'])){
                    message('未添加分类名称, 无法保存');
                }
                $category['uniacid'] = $_W['uniacid'];
                $category['displayorder'] = $category['displayorder'] ? $category['displayorder'] : 255;
                if($id == 0){
                    pdo_insert($this->tb_category, $category);
                }else{
                    pdo_update($this->tb_category , $category , array('id' => $id));
                }
                message('保存分类成功',$this->createWebUrl('cat', array('op'=>'display')),'success');
            }
            
            include $this->template('category');
        }else if($op == 'delete'){
            $id = intval($_GPC['id']);
            if(empty($id)){
                message('未找到指定分类');
            }
            $this->delateChilend($id);
            $result = pdo_delete($this->tb_category, array('id'=>$id, 'uniacid'=>$_W['uniacid']));
            if(intval($result) == 1){
                message('删除分类成功.', $this->createWebUrl('cat' , array('op'=>'display')), 'success');
            } else {
                message('删除分类失败.');
            }
        }
    }
    public function doWebUser() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display','create', 'delete')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            $title = $_GPC['title'];
            $pageindex = max(intval($_GPC['page']), 1);
            $pagesize = 20; 
            $where = ' WHERE mid='.$_W['uniacid'];
            
            if($title != ''){
                $where .= ' and (nickname like "%'.$title.'%") or (uname like "%'.$title.'%")';
            }
            if($_GET['id'] > 0){
                $where .= " and id=".$_GET['id'];
            }
            $sql = 'SELECT COUNT(*) FROM '.tablename($this->tb_user).$where;
            $total = pdo_fetchcolumn($sql);
            $pager = pagination($total, $pageindex, $pagesize);
            
            $sql = 'SELECT * FROM '.tablename($this->tb_user)."  {$where} ORDER BY id desc LIMIT ".(($pageindex -1) * $pagesize).','. $pagesize;
            $list = pdo_fetchall($sql);
            load()->func('tpl');
            include $this->template('user');
        }else if($op == 'delete'){
            $id = intval($_GPC['id']);
            if(empty($id)){
                message('未找到指定ID');
            }
            $result = pdo_delete($this->tb_user, array('id'=>$id));
            if(intval($result) == 1){
                message('删除成功.', $this->createWebUrl('user' , array('op'=>'display')), 'success');
            } else {
                message('删除失败.');
            }
        }
    }
    public function doWebProject() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display', 'create', 'delete')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            $title = $_GPC['title'];
            $catid = intval($_GPC['catid']);
            $aid = intval($_GPC['aid']);
            $addrop = $this->getAllAddrOption($aid);
            $catop = $this->getAllOption($catid);
            $pageindex = max(intval($_GPC['page']), 1);
            $pagesize = 20; 
            $where = ' WHERE uniacid='.$_W['uniacid'];
            
            if($title != ''){
                $where .= ' and (pname like "%'.$title.'%")';
            }
            if($catid > 0){
                $where .= " and catid=".$catid;
            }
            if($aid > 0){
                $where .= " and aid=".$aid;
            }
            $id = $_GPC['id'];
            if($id > 0){
                $where .= " and id=".$id;
            }
            $sql = 'SELECT COUNT(*) FROM '.tablename($this->tb_project).$where;
            $total = pdo_fetchcolumn($sql);
            $pager = pagination($total, $pageindex, $pagesize);
            
            $sql = 'SELECT * FROM '.tablename($this->tb_project)."  {$where} ORDER BY id desc LIMIT ".(($pageindex -1) * $pagesize).','. $pagesize;
            $list = pdo_fetchall($sql);
            if($list){
                foreach ($list as $key => $val){
                    $list[$key]['catname'] = $this->getAllByIDCat($val['catid']);
                    $list[$key]['addrname'] = $this->getAllByIDAddr($val['aid']);
                }
            }
            load()->func('tpl');
            include $this->template('project');    
        }elseif ($op == 'create'){
            $id = intval($_GET['id']);
            if($id > 0){
                $rs = $this->getProjectRow($id);
            }
            $addrop = $this->getAllAddrOption($rs['aid']);
            $catop = $this->getAllOption($rs['catid']);
            if (checksubmit()) {
                $project = $_GPC['project']; // 获取打包值
                $project['uniacid'] = $_W['uniacid'];
                $project['addtime'] = time();
                if($id == 0){
                    pdo_insert($this->tb_project, $project);
                }else{
                    pdo_update($this->tb_project , $project , array('id' => $id));
                }
                message('保存成功',$this->createWebUrl('project', array('op'=>'display')),'success');
            }
            load()->func('tpl');
            include $this->template('project');    
        }else if($op == 'delete'){
            $id = intval($_GPC['id']);
            if(empty($id)){
                message('未找到指定ID');
            }
            $result = pdo_delete($this->tb_project, array('id'=>$id));
            if(intval($result) == 1){
                message('删除成功.', $this->createWebUrl('project' , array('op'=>'display')), 'success');
            } else {
                message('删除失败.');
            }
        }
    }
    public function doWebPoseal() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display', 'create', 'delete')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            
            $title = $_GPC['title'];
            $catid = intval($_GPC['catid']);
            $aid = intval($_GPC['aid']);
            $addrop = $this->getAllAddrOption($aid);
            $catop = $this->getAllOption($catid);
            $pageindex = max(intval($_GPC['page']), 1);
            $pagesize = 20; 
            $where = ' WHERE uniacid='.$_W['uniacid'];
            
            if($title != ''){
                $where .= ' and (uname like "%'.$title.'%")';
            }
            if($catid > 0){
                $where .= " and catid=".$catid;
            }
            if($aid > 0){
                $where .= " and aid=".$aid;
            }
            $id = $_GPC['id'];
            if($id > 0){
                $where .= " and id=".$id;
            }
            $sql = 'SELECT COUNT(*) FROM '.tablename($this->tb_poseal).$where;
            $total = pdo_fetchcolumn($sql);
            $pager = pagination($total, $pageindex, $pagesize);
            
            $sql = 'SELECT * FROM '.tablename($this->tb_poseal)."  {$where} ORDER BY id desc LIMIT ".(($pageindex -1) * $pagesize).','. $pagesize;
            $list = pdo_fetchall($sql);
            if($list){
                foreach ($list as $key => $val){
                    $list[$key]['catname'] = $this->getAllByIDCat($val['catid']);
                    $list[$key]['addrname'] = $this->getAllByIDAddr($val['aid']);
                }
            }
            load()->func('tpl');
            include $this->template('poseal');    
        }elseif ($op == 'create'){
            $id = intval($_GET['id']);
            if($id > 0){
                $rs = $this->getPosealRow($id);
                $rs['multi'] = unserialize($rs['multi']);
            }
            $addrop = $this->getAllAddrOption($rs['aid']);
            $catop = $this->getAllOption($rs['catid']);
            if (checksubmit()) {
                $poseal = $_GPC['poseal'];
                $lag = $_GPC['lag'];
                $poseal['lng'] =  $lag['lng'];
                $poseal['lat'] =  $lag['lat'];
                $poseal['uniacid'] = $_W['uniacid'];
                $poseal['multi'] = serialize($poseal['multi']);
                $poseal['addtime'] = time();
                
                if($id == 0){
                    pdo_insert($this->tb_poseal, $poseal);
                }else{
                    pdo_update($this->tb_poseal , $poseal , array('id' => $id));
                }
                message('保存成功',$this->createWebUrl('poseal', array('op'=>'display')),'success');
            }
            load()->func('tpl');
            include $this->template('poseal');    
        }else if($op == 'delete'){
            $id = intval($_GPC['id']);
            if(empty($id)){
                message('未找到指定ID');
            }
            $result = pdo_delete($this->tb_project, array('id'=>$id));
            if(intval($result) == 1){
                message('删除成功.', $this->createWebUrl('poseal' , array('op'=>'display')), 'success');
            } else {
                message('删除失败.');
            }
        }
    }
    public function doWebAddress() {
        global $_W, $_GPC;
        $op = in_array($_GPC['op'], array('display', 'create', 'delete')) ? $_GPC['op'] : 'display';
        if($op == 'display'){
            $pid = intval($_GPC['pid']);
            $addess = $this->getAllAddr($pid);
            load()->func('tpl');
            include $this->template('address');    
        }else if ($op == 'create') {
            $id = intval($_GET['id']);
            if($id > 0){
                $sql = 'SELECT * FROM '.tablename($this->tb_addr).' WHERE id=:id AND uniacid=:uniacid LIMIT 1';
                $params = array(':id'=>$id, ':uniacid'=>$_W['uniacid']);
                $rs = pdo_fetch($sql, $params);
            }
            if($_GPC['pid'] > 0){
                $rs['pid'] = intval($_GPC['pid']);
            }
            $options = $this->getAllAddrOption($rs['pid'] ? $rs['pid'] : 0);
            if (checksubmit()) {
                $addr = $_GPC['addr'];
                $addr['uniacid'] = $_W['uniacid'];
                if($id == 0){
                    pdo_insert($this->tb_addr, $addr);
                }else{
                    pdo_update($this->tb_addr , $addr , array('id' => $id));
                }
                message('保存地址成功',$this->createWebUrl('address', array('op'=>'display')),'success');
            }
            
            include $this->template('address');
        }else if($op == 'delete'){
            $id = intval($_GPC['id']);
            if(empty($id)){
                message('未找到指定地址');
            }
            $this->delAddr($id);
            $result = pdo_delete($this->tb_addr, array('id'=>$id, 'uniacid'=>$_W['uniacid']));
            if(intval($result) == 1){
                message('删除成功.', $this->createWebUrl('address' , array('op'=>'display')), 'success');
            } else {
                message('删除失败.');
            }
        }
    }
    public function doWebOrder() {
            global $_W, $_GPC;
            $op = in_array($_GPC['op'], array('display', 'state', 'delete')) ? $_GPC['op'] : 'display';
            if($op == 'display'){
                $title = $_GPC['title'];
                $state = $_GET['state'];
                $pageindex = max(intval($_GPC['page']), 1);
                $pagesize = 20; 
                $where = ' WHERE o.uniacid='.$_W['uniacid'];
                
                if($title != ''){
                    $where .= ' and (o.username like "%'.$title.'%" or u.uname like "%'.$title.'%" or p.pname like "%'.$title.'%" or m.nickname like "%'.$title.'%" )';
                }
                if($state > 0){
                    $where .= " and o.state=".$state;
                }
                $sql = 'SELECT COUNT(*) FROM '.tablename($this->tb_order)." o inner join ".tablename($this->tb_poseal)." u on  u.id=o.aid 
                inner join ".tablename($this->tb_project)." p on p.id=o.pid inner join ".tablename($this->tb_user)." m on m.id=o.uid ".$where;
                $total = pdo_fetchcolumn($sql);
                $pager = pagination($total, $pageindex, $pagesize);
                
                $sql = 'SELECT o.*,m.nickname,p.pname,u.uname FROM '.tablename($this->tb_order)." o inner join ".tablename($this->tb_poseal)." u on  u.id=o.aid 
                inner join ".tablename($this->tb_project)." p on p.id=o.pid inner join ".tablename($this->tb_user)." m on m.id=o.uid ".$where." ORDER BY o.id desc LIMIT ".(($pageindex -1) * $pagesize).','. $pagesize;
                $list = pdo_fetchall($sql);
                if($list){
                    foreach ($list as $key => $val){
                        $list[$key]['state1'] = $this->getOrderState($val['state']);
                        $list[$key]['addtime'] = date('Y-m-d H:i:s' , $val['addtime']);
                    }
                }
                load()->func('tpl');
                include $this->template('order');
            }else if($op == 'state'){
                $id = intval($_GPC['id']);
                if(empty($id)){
                    message('未找到指定ID');
                }
                $s = $_GPC['s'];
                pdo_update($this->tb_order , array('state' => $s) , array('id' => $id));
                message('修改成功.', $this->createWebUrl('order' , array('op'=>'display')), 'success');
            }else if($op == 'delete'){
                $id = intval($_GPC['id']);
                if(empty($id)){
                    message('未找到指定ID');
                }
                $result = pdo_delete($this->tb_order, array('id'=>$id));
                if(intval($result) == 1){
                    message('删除成功.', $this->createWebUrl('order' , array('op'=>'display')), 'success');
                } else {
                    message('删除失败.');
                }
            }    
    }
    public function doWebComment(){
        global $_W, $_GPC;
            $op = in_array($_GPC['op'], array('display', 'state', 'delete')) ? $_GPC['op'] : 'display';
            if($op == 'display'){
                $title = $_GPC['title'];
                $state = $_GET['state'];
                $pageindex = max(intval($_GPC['page']), 1);
                $pagesize = 20; 
                $where = ' WHERE o.uniacid='.$_W['uniacid'];
                $id = $_GPC['id'];
                if($id > 0){
                    $where .= " and o.id=".$id;
                }
                if($title != ''){
                    $where .= ' and (o.username like "%'.$title.'%" or u.uname like "%'.$title.'%" or p.pname like "%'.$title.'%" or m.nickname like "%'.$title.'%" )';
                }
                if($state > 0){
                    $where .= " and o.state=".$state;
                }
                $sql = 'SELECT COUNT(*) FROM '.tablename($this->tb_comment).' c inner join '.tablename($this->tb_order)." o on c.oid=o.id inner join ".tablename($this->tb_poseal)." u on  u.id=o.aid 
                inner join ".tablename($this->tb_project)." p on p.id=o.pid inner join ".tablename($this->tb_user)." m on m.id=o.uid ".$where;
                $total = pdo_fetchcolumn($sql);
                $pager = pagination($total, $pageindex, $pagesize);
                
                $sql = 'SELECT c.*,m.nickname,p.pname,u.uname,o.aid,o.pid FROM '.tablename($this->tb_comment).' c inner join '.tablename($this->tb_order)." o on c.oid=o.id  inner join ".tablename($this->tb_poseal)." u on  u.id=o.aid 
                inner join ".tablename($this->tb_project)." p on p.id=o.pid inner join ".tablename($this->tb_user)." m on m.id=o.uid ".$where." ORDER BY o.id desc LIMIT ".(($pageindex -1) * $pagesize).','. $pagesize;
                $list = pdo_fetchall($sql);
                if($list){
                    foreach ($list as $key => $val){
                        $list[$key]['addtime'] = date('Y-m-d H:i:s' , $val['addtime']);
                    }
                }
                load()->func('tpl');
                include $this->template('comment');
            }else if($op == 'delete'){
                $id = intval($_GPC['id']);
                if(empty($id)){
                    message('未找到指定ID');
                }
                $result = pdo_delete($this->tb_comment, array('id'=>$id));
                if(intval($result) == 1){
                    message('删除成功.', $this->createWebUrl('comment' , array('op'=>'display')), 'success');
                } else {
                    message('删除失败.');
                }
            }    
    }
    
    /*********************************   以下是私有方法   ********************************/
    private  function getOrderState($state){
        switch ($state) {
            case 1:$state = '未支付';break;
            case 2:$state = '已付款';break;
            case 3:$state = '服务中';break;
            case 4:$state = '已完成';break;
            case 5:$state = '已评价';break;
        }
        return $state;
    }
    private function getAllBanner(){
        global $_W;
        $ReturnClassList = array();
        $sql = 'SELECT * FROM '.tablename($this->tb_banner).' WHERE uniacid=:uniacid  ORDER BY `displayorder` asc, id asc';
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        return pdo_fetchall($sql, $params, 'id');
    }
    /**
     * 获取所有商品分类
     * @return array()
     */
    private function getAllCategory($pid = 0){
        global $_W;
        $sql = 'SELECT * FROM '.tablename($this->tb_category).' WHERE uniacid=:uniacid and pid='.$pid;
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        $sql .= " ORDER BY `displayorder` asc, id asc";
        return pdo_fetchall($sql, $params, 'id');
    }
    private function getAllAddr($pid = 0){
        global $_W;
        $sql = 'SELECT * FROM '.tablename($this->tb_addr).' WHERE uniacid=:uniacid and pid='.$pid;
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        $sql .= " ORDER BY id asc";
        return pdo_fetchall($sql, $params, 'id');
    }
    
    /**
     * 递归删除分类
     * Enter 
     * @param 分类 $id
     */
    private function delateChilend($id){
        global  $_W;
        $list = $this->getAllCategory($id);
        if($list){
            foreach ($list as $val){
                pdo_delete($this->tb_category, array('id' => $val['id'], 'uniacid'=>$_W['uniacid']));
                return $this->delateChilend($val['id']);
            }
        }else{
            return true;
        }
    }
    private function delAddr($id){
        global  $_W;
        $list = $this->getAllAddr($id);
        if($list){
            foreach ($list as $val){
                pdo_delete($this->tb_addr, array('id' => $val['id'], 'uniacid'=>$_W['uniacid']));
                return $this->delAddr($val['id']);
            }
        }else{
            return true;
        }
    }
    /**
     * 处理select  
     * 
     * @param 选中的值 $selected
     */
    private function getAllOption($selected  = 0){
        global $_W;
        $html .= '<option value="0">顶级分类</option>';
        $sql = 'SELECT * FROM '.tablename($this->tb_category).' WHERE uniacid=:uniacid  ORDER BY `displayorder` asc, id asc';
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        $arr = pdo_fetchall($sql, $params, 'id');
        $arr1 = array();
        if($arr){
            foreach ($arr as $key => $val){
                $arr1[$key] = array('cid' => $val['id'] , 'pid' => $val['pid'] , 'name' => $val['cname']);
            }
        }
        $list = $this->getTree($arr1, 0, 0);
        if($list){
            foreach ($list as $val){
                $html .= '<option value="'.$val['cid'].'"'.($val['cid'] == $selected ? 'selected="selected"' : '').'>'.str_repeat('└―',$val['level']).$val['name'].'</option>';
            }
        }
        return $html;
    }
    private function getAllAddrOption($selected  = 0){
        global $_W;
        $html .= '<option value="0">顶级地址</option>';
        $sql = 'SELECT * FROM '.tablename($this->tb_addr).' WHERE uniacid=:uniacid  ORDER BY id asc';
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        $arr = pdo_fetchall($sql, $params, 'id');
        $arr1 = array();
        if($arr){
            foreach ($arr as $key => $val){
                $arr1[$key] = array('cid' => $val['id'] , 'pid' => $val['pid'] , 'name' => $val['aname']);
            }
        }
        $list2 = $this->getTree2($arr1, 0, 0);
        if($list2){
            foreach ($list2 as $val){
                $html .= '<option value="'.$val['cid'].'"'.($val['cid'] == $selected ? 'selected="selected"' : '').'>'.str_repeat('└―',$val['level']).$val['name'].'</option>';
            }
        }
        return $html;
    }
    
    /**
     * 得到分类树
     * 
     * @param 数组 $list
     * @param 父级 $pid
     * @param 级别 $level
     */
    private function getTree($list, $pid = 0, $level=1){
      static $newlist = array();
      foreach($list as $key => $value){
          if($value['pid']==$pid){
               $value['level'] = $level;
               $newlist[] = $value;
               unset($list[$key]);
               $this->getTree($list, $value['cid'], $level+1);
           }
      }
       return $newlist;
    }
    private function getTree2($list, $pid = 0, $level=1){
      static $newlist2 = array();
      foreach($list as $key => $value){
          if($value['pid']==$pid){
               $value['level'] = $level;
               $newlist2[] = $value;
               unset($list[$key]);
               $this->getTree2($list, $value['cid'], $level+1);
           }
      }
       return $newlist2;
    }
    /**
     * 
     * 得到 单个分类
     * @param id $id
     */
    private function getCatRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_category).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getAddrRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_addr).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getProjectRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_project).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getPosealRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_poseal).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getAllByIDCat($id , $arr = array()){
        global $_W;
        $rs = $this->getCatRow($id);
        $arr[] = $rs['cname'];
        if($rs['pid'] > 0){
            return $this->getAllByIDCat($rs['pid'] , $arr);
        }
        return implode('-', array_reverse($arr));
    }
    private function getAllByIDAddr($id , $arr = array()){
        global $_W;
        $rs = $this->getAddrRow($id);
        $arr[] = $rs['aname'];
        if($rs['pid'] > 0){
            return $this->getAllByIDAddr($rs['pid'] , $arr);
        }
        return implode('-', array_reverse($arr));
    }
    private function getImg($img){
        global $_W;
        return count(explode('http' , $img)) > 1 ? $img : $_W['attachurl'].$img;
    }
    private function getSetUpRow(){
        global $_W;
        $rs =  pdo_fetch('SELECT * FROM '.tablename($this->tb_setup).' WHERE uniacid=:uniacid LIMIT 1', array(':uniacid'=> $_W['uniacid']));
        return $rs;
    }
}
                   WXAPP
<?php
/**
 * md_daojia模块小程序接口定义
 *

 * @url 
 */
defined('IN_IA') or exit('Access Denied');

class Md_daojiaModuleWxapp extends WeModuleWxapp {

    private $tb_banner = 'daojia_focus';
    private $tb_category = 'daojia_cat';
    private $tb_user = 'daojia_user';
    private $tb_addr = 'daojia_addr';
    private $tb_project = 'daojia_project';
    private $tb_poseal = 'daojia_poseal';
    private $tb_setup = 'daojia_setup';
    private $tb_order = 'daojia_order';
    private $tb_comment = 'daojia_comment';
    
    public function doPageConfig(){
        global $_GPC, $_W;
        return $this->result(0, '', $this->getSetUpRow());
    }
    public function doPageIndex(){
        global $_GPC, $_W;
        $data = array();
        $banner = $this->getAllBanner();
        if($banner){
            foreach ($banner as $key => $val){
                $banner[$key]['img'] = $this->getImg($val['img']);
            }
        }
        $data['focus'] = $banner;
        $data['cat'] = $this->getAllCategory(0);
        $data['cat'] = $data['cat'] ? array_chunk($data['cat'], 5) : array();
        $config = $this->getSetUpRow();
        $where = ' WHERE hot=2 and uniacid='.$_W['uniacid'];
        $sql = 'SELECT * FROM '.tablename($this->tb_poseal)."  {$where} ORDER BY hot desc LIMIT 0,".$config['hotnums'];
        $poseal = pdo_fetchall($sql);
        
        if($poseal){
            foreach ($poseal as $key => $val){
                if($val['lat'] && $_GPC['lat']){
                    $poseal[$key]['dis'] = $this->getDistance($val['lng'], $val['lat'],  $_GPC['lng'],  $_GPC['lat']);
                }
                $poseal[$key]['logo'] = $this->getImg($val['logo']);
                $poseal[$key]['info'] = cutstr($val['info'], 30);
            }
        }
        $sql = 'SELECT * FROM '.tablename($this->tb_project)."  {$where} ORDER BY id desc LIMIT 0,".$config['projectnums'];
        $project = pdo_fetchall($sql);
        if($project){
            foreach ($project as $key => $val){
                $project[$key]['logo'] = $this->getImg($val['logo']);
            }
        }
        $data['poseal'] = $poseal;
        $data['project'] = array_chunk($project, 2);
        return $this->result(0, '', $data);
    }
    public function doPageUser(){
        global $_GPC, $_W;
        $row = pdo_fetch("select * from ".tablename($this->tb_user)."  where id=".$_GPC['uid']);
        return $this->result(0, '', $row);
    }
    public function doPageFlow(){
        global $_GPC, $_W;
        pdo_insert($this->tb_order , array('stime' => $_GPC['stime'], 'uid' => $_GPC['uid'],
        'username' => $_GPC['username'],'mobile' => $_GPC['mobile'],'address' => $_GPC['address'],'bz' => $_GPC['bz'],
        'aid' => $_GPC['poseal'],'pid' => $_GPC['project'],'uniacid' => $_W['uniacid'],'addtime' => time()));
        pdo_update($this->tb_user , array('uname' => $_GPC['username'] , 'mobile' => $_GPC['mobile'] , 'address' => $_GPC['address'])
        , array('id' => $_GPC['uid']));
        return $this->result(0, '', 1);
    }
    public function doPageOrder(){
        global $_GPC, $_W;
        $uid = $_GPC['uid'];
        $state = $_GPC['state'];
        $page = $_GPC['page'];
        $nums = 5;
           $start = ($page - 1) * $nums;
        $where = ' WHERE uniacid='.$_W['uniacid'];
        if($uid > 0 ){
            $where .= " and  uid=$uid ";
        }
        if($state > 0 ){
            if($state < 3){
                $where .= " and  state=$state ";
            }else{
                $where .= " and  state in(4,5)";
            }
            
        }
        $sql = 'SELECT * FROM '.tablename($this->tb_order)."  {$where} ORDER BY id desc limit $start , $nums";
        $list = pdo_fetchall($sql);
        // 1 未付款 2 已付款 3 服务中  4 已完成 5 已取消
        if($list){
            foreach ($list as $key => $val){
                $list[$key]['user'] = $this->getPosealRow($val['aid']);
                $list[$key]['ps'] = $this->getProjectRow($val['pid']);
                $list[$key]['state1'] = $this->getOrderState($val['state']);
                $list[$key]['user']['logo'] = $this->getImg($list[$key]['user']['logo']);
                if($val['state'] == 5){
                    $list[$key]['comment'] = $this->getCommentRow($val['id']);
                }
            }
        }
        $count = pdo_fetchcolumn("select count(*) from ".tablename($this->tb_order).$where);
        $totalPage = ceil($count / $nums);
        $this->result(0 , '' , array('totalPage' => $totalPage , 'list' => $list ));
    }
    public function doPageQx(){
        global $_GPC, $_W;
        pdo_delete($this->tb_order , array('id' => $_GPC['id']));
        $this->result(0, '' , 1);
    }
    public function doPagePay(){
        global $_GPC, $_W;
        $price = $_GPC['price'];
        $order = array(
            'tid' => date('YmdHis'), 
            'fee' => floatval($price), 
            'title' => '预定到家服务', 
        );
        $paydata = $this->pay($order);
        $this->result(0, '', $paydata);
    }
    public function doPagePay2(){
        global $_GPC, $_W;
        $price = $_GPC['price'];
        $order = $this->getOrderRow($_GPC['id']);
        $ps = $this->getProjectRow($order['pid']);
        $user = $this->getPosealRow($order['aid']);
        pdo_update($this->tb_poseal , array('sale' => $user['sale'] + 1) , array('id' => $user['aid']));
        pdo_update($this->tb_order , array('price' => $ps['price'] , 'state' => 2) ,array('id' => $_GPC['id']));
        $config = $this->getSetUpRow();
        $u = $this->getUserRow($_GPC['uid']);
        $content = '您好:'.$u['uname'].($u['gender'] == 1 ? '先生':'女士').'的预约已经付款,联系电话:'.$u['mobile'].'请尽快再后台查看安排处理';
        $this->sendMobile($config['shopmobile'], $content);
        $this->result(0, '' , 1);
    }
    public function dopageUinfo(){
        global $_GPC, $_W;
        $val = $this->getPosealRow($_GPC['id']);
        $val['dis'] = $this->getDistance($val['lng'], $val['lat'],  $_GPC['lng'],  $_GPC['lat']);
        $val['logo'] = $this->getImg($val['logo']);
        $val['multi'] = unserialize($val['multi']);
        if($val['multi']){
            foreach ($val['multi'] as $key => $img){
                $val['multi'][$key] = $this->getImg($img);
            }
        }
        $arr = array();
        $arr[] = $val['catid'];
        $where = ' WHERE catid in ('.implode(',', $arr).') and uniacid='.$_W['uniacid'];
        $val['ps'] = pdo_fetchall('SELECT * FROM '.tablename($this->tb_project)."  {$where} group by id ORDER BY id desc ");
        
        
        
        if($val['ps']){
            foreach ($val['ps'] as $key => $val2){
                $val['ps'][$key]['logo'] = $this->getImg($val2['logo']); 
            }
        }
        
        $where = ' WHERE o.aid='.$_GPC['id'].' and state=5 and o.uniacid='.$_W['uniacid'];
        $val['order'] = pdo_fetchall('SELECT o.*,u.nickname FROM '.tablename($this->tb_order)." o inner join ".tablename($this->tb_user)." u on u.id=o.uid  {$where} ORDER BY o.id desc ");
        if($val['order']){
            foreach ($val['order'] as $key => $sval){
                $val['order'][$key]['addtime'] = date('Y-m-d' , $sval['addtime']);
                $val['order'][$key]['ctime'] = date('Y-m-d' , $sval['ctime']);
            }
        }
        $val['order'] = $val['order'] ? $val['order'] : false;
        
        $where = ' WHERE o.aid='.$_GPC['id'].' and state=5 and o.uniacid='.$_W['uniacid'];
        $comment = pdo_fetchall('SELECT * FROM '.tablename($this->tb_order)." o inner join ".tablename($this->tb_comment)." u on u.oid=o.id  {$where}  ");
        $s = $s1 = $s2 = 0;
        if($comment){
            foreach ($comment as $c){
                $s1 += $c['score1'];
                $s2 += $c['score1'];
            }
        }
        $s = $s1 + $s2;    
        $val['s'] = $s;$val['s1'] = $s1;$val['s2'] = $s2;
        $val['code'] = substr_replace($val['code'],"****",8,4);
        $val['addr1'] = $this->getAllByIDAddr($val['aid']);
        $val['catname'] = $this->getAllByIDCat($val['catid']);
        return $this->result(0, '', $val);
    }
    public function doPageComment(){
        global $_GPC, $_W;
        $rs = $this->getCommentRow($_GPC['oid']);
        if($rs){
            pdo_update($this->tb_comment , array('score1' => $_GPC['score1'],'score2'=>$_GPC['score2'],'content'=>$_GPC['content']    ),array('oid' => $_GPC['oid']));
        }else{
            pdo_insert($this->tb_comment,
                array(
                    'uniacid' => $_W['uniacid'] , 'addtime' => time() , 'uid' => $_GPC['uid'] , 'oid' => $_GPC['oid'],
                    'score1' => $_GPC['score1'],'score2'=>$_GPC['score2'],'content'=>$_GPC['content']    
                )
            );
        }
        pdo_update($this->tb_order , array('state' => 5,'ctime' => time()) , array('id' => $_GPC['oid']));
        return $this->result(0, '', 1);
    }
    public function doPagePinfo() {
        global $_GPC, $_W;
        $val = $this->getProjectRow($_GPC['id']);
        $val['logo'] = $this->getImg($val['logo']);
        $arr = array();
        $arr[] = $val['catid'];
        $where = ' WHERE catid in ('.implode(',', $arr).')  and uniacid='.$_W['uniacid'];
        $val['ps'] = pdo_fetchall('SELECT * FROM '.tablename($this->tb_poseal)."  {$where} ORDER BY id desc ");
        if($val['ps']){
            foreach ($val['ps'] as $key => $val2){
                $val['ps'][$key]['logo'] = $this->getImg($val2['logo']); 
            }
        }
        
        $where = ' WHERE o.pid='.$_GPC['id'].' and state=5 and o.uniacid='.$_W['uniacid'];
        $val['order'] = pdo_fetchall('SELECT o.*,u.nickname FROM '.tablename($this->tb_order)." o inner join ".tablename($this->tb_user)." u on u.id=o.uid  {$where} ORDER BY o.id desc ");
        if($val['order']){
            foreach ($val['order'] as $key => $sval){
                $val['order'][$key]['addtime'] = date('Y-m-d' , $sval['addtime']);
                $val['order'][$key]['ctime'] = date('Y-m-d' , $sval['ctime']);
            }
        }
        $val['order'] = $val['order'] ? $val['order'] : false;
        $where = ' WHERE o.pid='.$_GPC['id'].' and state=5 and o.uniacid='.$_W['uniacid'];
        $comment = pdo_fetchall('SELECT * FROM '.tablename($this->tb_order)." o inner join ".tablename($this->tb_comment)." u on u.oid=o.id  {$where}  ");
        $s = $s1 = $s2 = 0;
        if($comment){
            foreach ($comment as $c){
                $s1 += $c['score1'];
                $s2 += $c['score1'];
            }
        }
        $s = $s1 + $s2;    
        $val['s'] = $s;$val['s1'] = $s1;$val['s2'] = $s2;
        return $this->result(0, '', $val);
    }
    public function doPagePeasel(){
        global $_GPC, $_W;
        $data = array();
        $page = $_GPC['page'];
        $desc = str_ireplace(array(1,2,3,4), array('id' , 'work' , 'year','sale'), $_GPC['desc']);
        $a1 = $_GPC['a1'];
        $a2 = $_GPC['a2'];
        $c1 = $_GPC['c1'];
        $c2 = $_GPC['c2'];
        $keyword = $_GPC['keyword'];
        $where = ' WHERE uniacid='.$_W['uniacid'];
        if($keyword != ''){
            $where .= " and uname like '%$keyword%' ";
        }
        $nums = 5;
           $start = ($page - 1) * $nums;
        if($c2 > 0){
            $where .= " and catid=$c2";
        }else if($c2 == 0 && ($c1 > 0)){
            $ps1 = $this->getAllCategory($c1);
            $ps2 = array();
            if($ps1){
                foreach ($ps1 as $val){
                    $ps2[] = $val['id'];
                }
                if($ps2){
                    $where .= " and catid in (".implode(',', $ps2).") or catid=$c1";
                }
            }
        }
        if($a2 > 0){
            $where .= " and aid=$a2";
        }else if($a2 == 0 && ($a1 > 0)){
            $cs1 = $this->getAllAddr($a1);
            $cs2 = array();
            if($cs1){
                foreach ($cs1 as $val){
                    $cs2[] = $val['id'];
                }
                if($cs2){
                    $where .= " and aid in (".implode(',', $cs2).") or aid=$a1";
                }
            }
        }
        if($_GPC['desc'] == 5){
            $sql = 'SELECT * FROM '.tablename($this->tb_poseal)."  {$where} ORDER BY $desc desc ";
            $list = pdo_fetchall($sql);
            if($list){
                foreach ($list as $key => $val){
                    if($val['lat'] && $_GPC['lat']){
                        $list[$key]['dis'] = $this->getDistance1($val['lng'], $val['lat'],  $_GPC['lng'],  $_GPC['lat']);
                    }
                    $list[$key]['logo'] = $this->getImg($val['logo']);
                    $list[$key]['info'] = cutstr($list[$key]['info'], 30);
                }
                $list = array_slice($this->array2sort($list, 'dis') , $start , $nums);
                if($list){
                    foreach ($list as $key1 => $val1){
                        $list[$key1]['dis'] = $val1['dis'] < 1 ? $val1['dis'].'m' : $val1['dis'].'km';
                    }
                }
            }
        }else{
            $sql = 'SELECT * FROM '.tablename($this->tb_poseal)."  {$where} ORDER BY $desc desc limit $start , $nums";
            $list = pdo_fetchall($sql);
            if($list){
                foreach ($list as $key => $val){
                    if($val['lat'] && $_GPC['lat']){
                        $list[$key]['dis'] = $this->getDistance($val['lng'], $val['lat'],  $_GPC['lng'],  $_GPC['lat']);
                    }
                    $list[$key]['logo'] = $this->getImg($val['logo']);
                    $list[$key]['info'] = cutstr($list[$key]['info'], 30);
                }
            }
        }
        $count = pdo_fetchcolumn("select count(*) from ".tablename($this->tb_poseal).$where);
        $totalPage = ceil($count / $nums);
        
        
        
        $this->result(0 , '' , array('totalPage' => $totalPage , 'list' => $list ));
    }
    public function doPageProject(){
        global $_GPC, $_W;
        $data = array();
        $page = $_GPC['page'];
        $desc = str_ireplace(array(1,2), array('id' , 'price'), $_GPC['desc']);
        $a1 = $_GPC['a1'];
        $a2 = $_GPC['a2'];
        $c1 = $_GPC['c1'];
        $c2 = $_GPC['c2'];
        $keyword = $_GPC['keyword'];
        $where = ' WHERE uniacid='.$_W['uniacid'];
        if($keyword != ''){
            $where .= " and pname like '%$keyword%' ";
        }
        $nums = 5;
           $start = ($page - 1) * $nums;
        if($c2 > 0){
            $where .= " and catid=$c2";
        }else if($c2 == 0 && ($c1 > 0)){
            $ps1 = $this->getAllCategory($c1);
            $ps2 = array();
            if($ps1){
                foreach ($ps1 as $val){
                    $ps2[] = $val['id'];
                }
                if($ps2){
                    $where .= " and catid in (".implode(',', $ps2).") or catid=$c1";
                }
            }
        }
        if($a2 > 0){
            $where .= " and aid=$a2";
        }else if($a2 == 0 && ($a1 > 0)){
            $cs1 = $this->getAllAddr($a1);
            $cs2 = array();
            if($cs1){
                foreach ($cs1 as $val){
                    $cs2[] = $val['id'];
                }
                if($cs2){
                    $where .= " and aid in (".implode(',', $cs2).") or aid=$a1";
                }
            }
        }
        $sql = 'SELECT * FROM '.tablename($this->tb_project)."  {$where} ORDER BY $desc desc limit $start , $nums";
        $list = pdo_fetchall($sql);
        if($list){
            foreach ($list as $key => $val){
                if($val['lat'] && $_GPC['lat']){
                    $list[$key]['dis'] = $this->getDistance($val['lng'], $val['lat'],  $_GPC['lng'],  $_GPC['lat']);
                }
                $list[$key]['logo'] = $this->getImg($val['logo']);
            }
        }
        $count = pdo_fetchcolumn("select count(*) from ".tablename($this->tb_project).$where);
        $totalPage = ceil($count / $nums);
        $this->result(0 , '' , array('totalPage' => $totalPage , 'list' => $list ));
    }
    public function doPageClass(){
        global $_GPC, $_W;
        $data = array();
        $cat = $this->getAllCategory(0);
        if($cat){
            foreach ($cat as $key => $val){
                $cat[$key]['child'] = $this->getAllCategory($val['id']);
            }
        }
        $addr = $this->getAllAddr(0);
        if($addr){
            foreach ($addr as $key1 => $val){
                $addr[$key1]['child'] = $this->getAllAddr($val['id']);
            }
        }
        return $this->result(0, '', array('cat' => $cat , 'addr' => $addr));
    }
    public function doPageSetuser(){
        global $_W, $_GPC;
          $code = $_GPC['code'];
        $appid = $_W['oauth_account']['key'];
        $secret = $_W['oauth_account']['secret'];
        $url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$secret&js_code=$code&grant_type=authorization_code";
        load()->func('communication');
        $response = ihttp_request($url, '', array('CURLOPT_HTTPHEADER' => array('Content-Type: text/xml; charset=utf-8')));
        $content = json_decode($response['content']);
        $openid = $content->openid;
        if($openid != ''){
            $row = pdo_fetch("select * from ".tablename($this->tb_user)."  where mid={$_W['uniacid']} and openid='$openid'");
            if(!$row){
                pdo_insert($this->tb_user, array('addtime' => time(),'mid' => $_W['uniacid'],'openid' => $openid , 'nickname' => $_GPC['nickName'],'gender'=>$_GPC['gender'] , 'avatar' => $_GPC['avatar']));
            }
            $row = pdo_fetch("select * from ".tablename($this->tb_user)."  where mid={$_W['uniacid']} and openid='$openid'");
        }
        $this->result(0 , '' , $row);
    }
    /*********************************   以下是私有方法   ********************************/
    private function getImg($img){
        global $_W;
        return count(explode('http' , $img)) > 1 ? $img : $_W['attachurl'].$img;
    }
    private function getAllBanner(){
        global $_W;
        $ReturnClassList = array();
        $sql = 'SELECT * FROM '.tablename($this->tb_banner).' WHERE uniacid=:uniacid  ORDER BY `displayorder` asc, id asc';
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        return pdo_fetchall($sql, $params, 'id');
    }
    /**
     * 获取所有商品分类
     * @return array()
     */
    private function getAllCategory($pid = 0){
        global $_W;
        $sql = 'SELECT * FROM '.tablename($this->tb_category).' WHERE uniacid=:uniacid and pid='.$pid;
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        $sql .= " ORDER BY `displayorder` asc, id asc";
        return pdo_fetchall($sql, $params);
    }
    private function getSetUpRow(){
        global $_W;
        $rs =  pdo_fetch('SELECT * FROM '.tablename($this->tb_setup).' WHERE uniacid=:uniacid LIMIT 1', array(':uniacid'=> $_W['uniacid']));
        $rs['projectimg'] = $this->getImg($rs['projectimg']);
        $rs['posealimg'] = $this->getImg($rs['posealimg']);
        $rs['indeximg1'] = $this->getImg($rs['indeximg1']);
        $rs['staff_ul_bg'] = $_W['siteroot'].'addons/md_daojia/img/staff_ul_bg.png';
        $rs['service_ul_bg'] = $_W['siteroot'].'addons/md_daojia/img/service_ul_bg.png';
        
        $rs['six1'] = $_W['siteroot'].'addons/md_daojia/img/six-sys-1.jpg';
        $rs['six2'] = $_W['siteroot'].'addons/md_daojia/img/six-sys-2.jpg';
        $rs['six3'] = $_W['siteroot'].'addons/md_daojia/img/six-sys-3.jpg';
        $rs['six4'] = $_W['siteroot'].'addons/md_daojia/img/six-sys-4.jpg';
        $rs['slogo'] = $rs['slogo'] ? $this->getImg($rs['slogo']) : '';
        return $rs;
    }
    private function getDistance($longitude1, $latitude1, $longitude2, $latitude2, $unit=2, $decimal=2){
        $EARTH_RADIUS = 6370.996; // 地球半径系数
        $PI = 3.1415926;
        $radLat1 = $latitude1 * $PI / 180.0;
        $radLat2 = $latitude2 * $PI / 180.0;
        $radLng1 = $longitude1 * $PI / 180.0;
        $radLng2 = $longitude2 * $PI /180.0;
        $a = $radLat1 - $radLat2;
        $b = $radLng1 - $radLng2;
    
        $distance = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));
        $distance = $distance * $EARTH_RADIUS * 1000;
        if($unit==2){
            $distance = $distance / 1000;
        }
        $d =  round($distance, $decimal);
        return $d < 1 ? $d.'m' : $d.'km';
    }
    private function getDistance1($longitude1, $latitude1, $longitude2, $latitude2, $unit=2, $decimal=2){
        $EARTH_RADIUS = 6370.996; // 地球半径系数
        $PI = 3.1415926;
        $radLat1 = $latitude1 * $PI / 180.0;
        $radLat2 = $latitude2 * $PI / 180.0;
        $radLng1 = $longitude1 * $PI / 180.0;
        $radLng2 = $longitude2 * $PI /180.0;
        $a = $radLat1 - $radLat2;
        $b = $radLng1 - $radLng2;
    
        $distance = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));
        $distance = $distance * $EARTH_RADIUS * 1000;
        if($unit==2){
            $distance = $distance / 1000;
        }
        $d =  round($distance, $decimal);
        return $d;
    }
    private function getAllAddr($pid = 0){
        global $_W;
        $sql = 'SELECT * FROM '.tablename($this->tb_addr).' WHERE uniacid=:uniacid and pid='.$pid;
        $params = array(
            ':uniacid' => $_W['uniacid'],
        );
        $sql .= " ORDER BY id asc";
        return pdo_fetchall($sql, $params);
    }
    private function getProjectRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_project).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getPosealRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_poseal).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getCommentRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_comment).' WHERE oid='.$id);
    }
    
    private function getAllByIDAddr($id , $arr = array()){
        global $_W;
        $rs = $this->getAddrRow($id);
        $arr[] = $rs['aname'];
        if($rs['pid'] > 0){
            return $this->getAllByIDAddr($rs['pid'] , $arr);
        }
        return implode(' ', array_reverse($arr));
    }
    private function getCatRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_category).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getUserRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_user).' WHERE id=:id', array(':id'=> $id));
    }
    private function getAddrRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_addr).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getOrderRow($id){
        global $_W;
        return pdo_fetch('SELECT * FROM '.tablename($this->tb_order).' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=> $id, ':uniacid'=> $_W['uniacid']));
    }
    private function getAllByIDCat($id , $arr = array()){
        global $_W;
        $rs = $this->getCatRow($id);
        $arr[] = $rs['cname'];
        if($rs['pid'] > 0){
            return $this->getAllByIDCat($rs['pid'] , $arr);
        }
        return implode(' ', array_reverse($arr));
    }
    private  function getOrderState($state){
        switch ($state) {
            case 1:$state = '未支付';break;
            case 2:$state = '已付款';break;
            case 3:$state = '服务中';break;
            case 4:$state = '已完成';break;
            case 5:$state = '已评价';break;
        }
        return $state;
    }
    private function sendMobile($phone , $content){
        $config = $this->getSetUpRow();
        $smsapi = "http://api.smsbao.com/";
        $user = $config['baouser'];
        $pass = md5($config['baopass']); 
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        load()->func('communication');
        $response = ihttp_request($sendurl, '', array('CURLOPT_HTTPHEADER' => array('Content-Type: text/xml; charset=utf-8')));
        return true;
    }
    private function array2sort($a,$sort,$d='') {
        $num=count($a);
        if(!$d){
            for($i=0;$i<$num;$i++){
                for($j=0;$j<$num-1;$j++){
                    if($a[$j][$sort] > $a[$j+1][$sort]){
                        foreach ($a[$j] as $key=>$temp){
                            $t=$a[$j+1][$key];
                            $a[$j+1][$key]=$a[$j][$key];
                            $a[$j][$key]=$t;
                        }
                    }
                }
            }
        }
        else{
            for($i=0;$i<$num;$i++){
                for($j=0;$j<$num-1;$j++){
                    if($a[$j][$sort] < $a[$j+1][$sort]){
                        foreach ($a[$j] as $key=>$temp){
                            $t=$a[$j+1][$key];
                            $a[$j+1][$key]=$a[$j][$key];
                            $a[$j][$key]=$t;
                        }
                    }
                }
            }
        }
        return $a;
    }
}

 

posted @ 2019-06-25 02:22  我是bug  阅读(514)  评论(0编辑  收藏  举报