免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1484 | 回复: 0
打印 上一主题 下一主题

wemall开源版微商城代码片段--post传值 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-08-08 11:16 |只看该作者 |倒序浏览
1. [代码]IndexController.class.php     
<?php
namespace App\Controller;
use Think\Controller;
// 本类由系统自动生成,仅供测试用途
class IndexController extends Controller {
    function _initialize() {
        // $_GET = I("get.");
        // $_POST = I("post.");
    }
    public function index() {
        if (I("get.uid")) {
            $info = R ( "Api/Api/gettheme" );
            C ( "DEFAULT_THEME", $info ["theme"] );
            $this->assign ( "info", $info );
            
            $menuresult = R ( "Api/Api/getmenu" );
            $this->assign ( "menu", $menuresult );
            
            $goodsresult = R ( "Api/Api/getgood" );
            $this->assign ( "goods", $goodsresult );
            
            $uid = I("get.uid");
            $usersresult = R ( "Api/Api/getuser",array($uid));
            
            $alipay = M ( "Alipay" )->find ();
            if ($alipay) {
                $this->assign ( "alipay", 1 );
            }
            
            $this->assign ( "users", $usersresult );
            $this->display ();
        } else {
            echo '请使用微信访问!';
        }
    }
    public function fetchgooddetail() {
        $where ["id"] = I("post.id");
        $result = M ( "Good" )->where ( $where )->find ();
        if ($result) {
            $this->ajaxReturn ( $result );
        }
    }
    public function getorders() {
        $uid = I("post.uid");
        $user_id = M ( "User" )->where ( array (
                "uid" => $uid
        ) )->find ();
        $result = M ( "Order" )->where ( array (
                "user_id" => $user_id ["id"]
        ) )->order ( 'id desc' )->select ();
        $this->ajaxReturn ( $result );
    }
    public function addorder() {
        $uid = htmlspecialchars ( I("post.uid"));
        $userData = I("post.userData");
        $username = $userData [0] [value];
        $phone = $userData [1] [value];
        $pay = $userData [2] [value];
        $address = $userData [3] [value];
        $note = $userData [4] [value];
         
        $totalprice = I("post.totalPrice");
        $cartdata = stripslashes ( I("post.cartData") );
         
        $orderid = date ( "ymdhis" ) . mt_rand ( 1, 9 );
        $time = date ( "Y/m/d H:i:s" );
        switch ($pay) {
            case 0 :
                $pay_style = "货到付款";
                break;
            case 1 :
                $pay_style = "微信支付";
                break;
        }
         
        $data ["orderid"] = $orderid;
        $data ["totalprice"] = $totalprice;
        $data ["pay_style"] = $pay_style;
        $data ["pay_status"] = "0";
        $data ["note"] = $note;
        $data ["order_status"] = '0';
        $data ["time"] = $time;
        $data ["cartdata"] = $cartdata;
         
        $userdata = M ( "User" )->where ( array (
                "uid" => $uid
        ) )->find ();
        if ($userdata) {
            $user_id = $userdata ["id"];
            $user ["id"] = $user_id;
            $user ["username"] = $username;
            $user ["phone"] = $phone;
            $user ["address"] = $address;
            M ( "User" )->save ( $user );
            
            $data ["user_id"] = $user_id;
            M ( "Order" )->add ( $data );
        } else {
            $user ["uid"] = $uid;
            $user ["username"] = $username;
            $user ["phone"] = $phone;
            $user ["address"] = $address;
            $user_id = M ( "User" )->add ( $user );
            $data ["user_id"] = $user_id;
            M ( "Order" )->add ( $data );
        }
         
        $config = M("Wxconfig")->find();
        if ($pay == 1) {
            echo 'http://' . $_SERVER ['SERVER_NAME'] . __ROOT__ . '/Api/wxPay/js_api_call.php?body=' . $config ['num'] . '&orderid=' . $orderid . '&totalprice=' . floatval($totalprice) * 100 . '&url=' . U("App/Index/index") . '&uid=' . $uid;
        }
    }
     
    // app start
    public function appregister() {
        $username = I("post.username");
        $password = I("post.password");
        $phone = I("post.phone");
         
        if ($username && $password && $phone) {
            $find = M ( "User" )->where ( array (
                    "phone" => $phone
            ) )->select ();
            if (! $find) {
                $data ["username"] = $username;
                $data ["phone"] = $phone;
                $data ["password"] = md5 ( $password );
                $data ["uid"] = date ( "His" ) . mt_rand ( 1, 9 );
                $data ["time"] = date ( "Y/m/d H:i:s" );
                 
                $result = M ( "User" )->add ( $data );
                if ($result) {
                    $this->ajaxReturn ( $result );
                }
            }
        }
    }
    public function applogin() {
        $phone = I("post.phone");
        $password = md5 ( I("post.password") );
         
        if ($phone && $password) {
            $result = M ( "User" )->where ( array (
                    "phone" => $phone,
                    "password" => $password
            ) )->find ();
            if ($result) {
                $this->ajaxReturn ( $result );
            }
        }
    }
    public function appgetgood() {
        $result = M ( "Good" )->select ();
        if ($result) {
            $this->ajaxReturn ( $result );
        }
    }
    public function appdoaddress() {
        $do = I("post.do");
        $uid = I("post.uid");
         
        switch ($do) {
            case 1 :
                $result = M ( "User" )->where ( array (
                        "uid" => $uid
                ) )->find ();
                if ($result) {
                    $this->ajaxReturn ( $result );
                }
                break;
            case 2 :
                $address = I("post.address");
                $data ["address"] = $address;
                $result = M ( "User" )->where ( array (
                        "uid" => $uid
                ) )->save ( $data );
                if ($result) {
                    $this->ajaxReturn ( $result );
                }
                break;
            default :
                ;
                break;
        }
    }
    public function appdoorder() {
        $do = I("post.do");
        $uid = I("post.uid");
         
        switch ($do) {
            case 1 :
                $cartdata = I("post.cartdata");
                $note = I("post.note");
                $cartarray = json_decode ( $cartdata, true );
                $totalprice = 0;
                for($i = 0; $i < count ( $cartarray ); $i ++) {
                    unset ( $cartarray [$i] ["id"] );
                    unset ( $cartarray [$i] ["image"] );
                    $totalprice += $cartarray [$i] ["num"] * $cartarray [$i] ["price"];
                }
                $cartdata = json_encode ( $cartarray );
                $orderid = date ( "YmdHis" ) . mt_rand ( 1, 9 );
                $time = date ( "Y/m/d H:i:s" );
                $user = M ( "User" )->where ( array (
                        "uid" => $uid
                ) )->find ();
                 
                $data ["orderid"] = $orderid;
                $data ["totalprice"] = $totalprice;
                $data ["pay_style"] = "货到付款";
                $data ["pay_status"] = "0";
                $data ["note"] = $note;
                $data ["order_status"] = '0';
                $data ["time"] = $time;
                $data ["cartdata"] = $cartdata;
                $data ["user_id"] = $user ["id"];
                 
                $result = M ( "Order" )->add ( $data );
                if ($result) {
                    $this->ajaxReturn ( $result );
                }
                 
                break;
            case 2 :
                $id = M ( "User" )->where ( array (
                        "uid" => $uid
                ) )->find ();
                $id = $id ["id"];
                 
                $result = M ( "Order" )->where ( array (
                        "user_id" => $id
                ) )->select ();
                if ($result) {
                    $this->ajaxReturn ( $result );
                }
                break;
            case 3 :
                $orderid = I("post.orderid");
                $result = M ( "Order" )->where ( array (
                        "orderid" => $orderid
                ) )->find ();
                 
                $user = M ( "User" )->where ( array (
                        "uid" => $uid
                ) )->find ();
                 
                $result = array_merge ( $result, $user );
                 
                if ($result) {
                    $this->ajaxReturn ( $result );
                }
                 
                break;
            default :
                ;
                break;
        }
    }
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP