Initial commit

This commit is contained in:
易焱
2021-04-18 18:51:51 +08:00
commit ec705f2fa8
3240 changed files with 623103 additions and 0 deletions
@@ -0,0 +1,149 @@
<?php
namespace Shop\Controller;
use Think\Controller;
class PayController extends Controller {
public function __construct() {
parent::__construct();
$this->order_id=I("get.order_id",0,"intval");
$this->order=M("shop_order")->find($this->order_id);
if(!$this->order){
$this->error("订单不存在");
}
if($this->order["is_pay"]){
$this->error("该订单已支付");
}
}
//线下付款
public function bankPay(){
if(I("get.is_submit")){
M("shop_order")->save(array(
"order_id"=>$this->order_id,
"is_offline_pay"=>1,
));
//设置订单状态
D("shop_order")->setOrderState($this->order_id);
//订单日志
D("shop_order")->log($this->order_id,"用户选择对公转账付款");
$this->success("操作成功");
}else{
$this->display();
}
}
//支付宝pc端支付
public function aliPay(){
if(isMobile()){
if(isWxClient()){
//$this->success("微信端不支持支付宝付款,请点击右上角【浏览器打开】这个链接,使用支付宝付款",U("Shop/ShopOrder/index"),60);
}
$this->aliWapPay();
}else{
$this->aliPcPay();
}
}
//支付宝pc端支付
public function aliPcPay(){
//
$proName="订单号:".$this->order["order_num"];
$out_trade_no=$this->order["order_num"];
$total_amount =$this->order['pay_money'];
$body="";
//
Vendor('AlipaySdk.aop.AopClient');
Vendor('AlipaySdk.aop.request.AlipayTradePagePayRequest');
$c = new \AopClient();
$config = C('alipay');
$c->gatewayUrl = $config['gatewayUrl'];;
$c->appId = $config['app_id'];
$c->rsaPrivateKey = $config['merchant_private_key'];
$c->format = "json";
$c->charset= "UTF-8";
$c->signType= "RSA2";
$c->alipayrsaPublicKey = $config['alipay_public_key'];
$request = new \AlipayTradePagePayRequest();
$request->setReturnUrl($config['return_url']);
$request->setNotifyUrl($config['notify_url']);
$request->setBizContent("{" .
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," .
" \"subject\":\"$proName\"," .
" \"out_trade_no\":\"$out_trade_no\"," .
" \"total_amount\":$total_amount," .
" \"body\":\"$body\"" .
" }");
$result = $c->pageExecute ($request);
//输出
echo $result;
}
//支付宝手机端支付
public function aliWapPay(){
Vendor('AlipaySdk.aop.AopClient');
Vendor('AlipaySdk.aop.request.AlipayTradeWapPayRequest');
Vendor('AlipaySdk.wappay.service.AlipayTradeService');
Vendor('AlipaySdk.wappay.buildermodel.AlipayTradeWapPayContentBuilder');
$c = new \AopClient();
$config = C('alipay');
//商户订单号,商户网站订单系统中唯一订单号,必填
$out_trade_no = $this->order["order_num"];
//订单名称,必填
$subject = "订单号:".$this->order["order_num"];
//付款金额,必填
$total_amount = $this->order['pay_money'];
//商品描述,可空
$body = "";
//超时时间
$timeout_express="1m";
$payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
$payRequestBuilder->setBody($body);
$payRequestBuilder->setSubject($subject);
$payRequestBuilder->setOutTradeNo($out_trade_no);
$payRequestBuilder->setTotalAmount($total_amount);
$payRequestBuilder->setTimeExpress($timeout_express);
//这里要把return_url和notify_url重新改变成手机的
$config["return_url"]=$config['wap_return_url'];
$config["notify_url"]=$config['wap_notify_url'];
$payResponse = new \AlipayTradeService($config);
$result=$payResponse->wapPay($payRequestBuilder,$config['return_url'],$config['notify_url']);
}
//异步通知(PC支付)
public function notify_url(){
$arr=$_POST;
Vendor('AlipaySdk.pagepay.service.AlipayTradeService');
$alipaySevice = new \AlipayTradeService(C('alipay'));
$result = $alipaySevice->check($arr);
if($result){
$out_trade_no = $_POST['out_trade_no'];
$total_amount= $_POST['total_amount'];
if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
//这里加入商业逻辑处理
$order=D("shop_order")->where(array("order_num"=>$out_trade_no))->find();
//这里要判断是否is_pay为0才执行商业处理,防止异步通知执行两次以上从而造成多条付款明细
if($order&&!$order["is_pay"]){
M("shop_order")->save(array(
"order_id"=>$order["order_id"],
"is_pay"=>1,
));
//设置订单状态
D("shop_order")->setOrderState($order["order_id"]);
//订单日志
D("shop_order")->log($order["order_id"],"用户在线支付,金额:{$total_amount},支付方式:阿里云");
//
$this->payMent($order["order_id"],"alipay",json_encode($_POST));
}
}
echo "success";//请不要修改或删除
}else{
}
}
public function return_url(){
redirect(U("Shop/ShopOrder/index"));
}
//付款记录
private function payMent($orderid,$paytype,$detail){
M("shop_order_payment")->add(array(
"order_id" =>$orderid,
"addtime" =>time(),
"paytype" =>$paytype,
"detail" =>$detail,
));
}
}
@@ -0,0 +1,81 @@
<?php
namespace Shop\Controller;
use Think\Controller;
class PayNotifyController extends Controller {
//异步通知(PC支付)
public function notify_url(){
$arr=$_POST;
Vendor('AlipaySdk.pagepay.service.AlipayTradeService');
$alipaySevice = new \AlipayTradeService(C('alipay'));
$alipaySevice->writeLog(var_export($_POST,true));
$result = $alipaySevice->check($arr);
if($result){
$out_trade_no = $_POST['out_trade_no'];
$total_amount= $_POST['total_amount'];
if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
//这里加入商业逻辑处理
$order=D("shop_order")->where(array("order_num"=>$out_trade_no))->find();
//这里要判断是否is_pay为0才执行商业处理,防止异步通知执行两次以上从而造成多条付款明细
if($order&&!$order["is_pay"]){
M("shop_order")->save(array(
"order_id"=>$order["order_id"],
"is_pay"=>1,
));
//设置订单状态
D("shop_order")->setOrderState($order["order_id"]);
//订单日志
D("shop_order")->log($order["order_id"],"用户在线支付,金额:{$total_amount},支付方式:支付宝");
//
$this->payMent($order["order_id"],"alipay",json_encode($_POST));
}
}
echo "success";//请不要修改或删除
}else{
}
}
//异步通知(手机支付)
public function wap_notify_url(){
$arr=$_POST;
Vendor('AlipaySdk.aop.AopClient');
Vendor('AlipaySdk.wappay.service.AlipayTradeService');
$alipaySevice = new \AlipayTradeService(C('alipay'));
$result = $alipaySevice->check($arr);
if($result){
$out_trade_no = $_POST['out_trade_no'];
$total_amount= $_POST['total_amount'];
if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
//这里加入商业逻辑处理
$order=D("shop_order")->where(array("order_num"=>$out_trade_no))->find();
//这里要判断是否is_pay为0才执行商业处理,防止异步通知执行两次以上从而造成多条付款明细
if($order&&!$order["is_pay"]){
M("shop_order")->save(array(
"order_id"=>$order["order_id"],
"is_pay"=>1,
));
//设置订单状态
D("shop_order")->setOrderState($order["order_id"]);
//订单日志
D("shop_order")->log($order["order_id"],"用户在线支付,金额:{$total_amount},支付方式:支付宝(wap)");
//
$this->payMent($order["order_id"],"alipay",json_encode($_POST));
}
}
echo "success";//请不要修改或删除
}else{
}
}
//支付定同步返回
public function return_url(){
redirect(U("Shop/ShopOrder/index"));
}
//付款记录
private function payMent($orderid,$paytype,$detail){
M("shop_order_payment")->add(array(
"order_id" =>$orderid,
"addtime" =>time(),
"paytype" =>$paytype,
"detail" =>$detail,
));
}
}
@@ -0,0 +1,209 @@
<?php
namespace Shop\Controller;
use Member\Controller\BaseController;
class ShopCartController extends BaseController{
public function __construct() {
parent::__construct();
$this->ShopCart = D("ShopCart");
}
public function confirmation_order(){
$ids = session("confirmation_order_ids");
$member_id = session("member.member_id");
if(!$ids){
$this->error("请选择购买商品");
}
$where["id"] = array("in",$ids);
$where["member_id"] = $member_id;
$data = $this->ShopCart->relation(true)->where($where)->select();
if(!$data){
$this->error('数据错误');
}
if(IS_POST){
//收货地址
$sh_address=M("member_address")->where(array(
"member_id"=>$member_id,
"id"=>I("post.order_sh_address_id")
))->find();
//发票信息
$order_invoice=M("member_invoice")->where(array(
"member_id"=>$member_id,
"id"=>I("post.order_invoice_id")
))->find();
//收票地址
$sp_address=M("member_address")->where(array(
"member_id"=>$member_id,
"id"=>I("post.order_sp_address_id")
))->find();
//
if(!$sh_address){
$this->error('请选择收货地址');
}
if(!I("post.order_invoice_id")){
$this->error('请设置发票信息');
}
//
if(!$sp_address){
$this->error('请选择收票地址');
}
$order_id = D("ShopOrder")->add_order($data,$sh_address,$order_invoice,$sp_address);
$url=U("pay",array("order_id"=>$order_id));
$this->success($url);
}else{
//默认收货地址
$this->sh_address = M("member_address")->where(array(
"member_id"=>$member_id,
"sh_status"=>1,
))->find();
//默认发票
$this->invoice = M("member_invoice")->where(array(
"member_id"=>$member_id,
"status"=>1,
))->find();
//默认收票地址
$this->sp_address = M("member_address")->where(array(
"member_id"=>$member_id,
"sp_status"=>1,
))->find();
$this->pagetitle="确认订单信息";
$this->data = $data;
$this->display();
}
}
public function pay($order_id){
$this->order=M("shop_order")->find($order_id);
if(!$this->order){
$this->error("订单不存在");
}
$this->display();
}
public function index(){
if(IS_POST){
$ids = I("post.ids");
if(count($ids) <= 0){
$this->error("请选择购物车商品提交");
}
session("confirmation_order_ids",$ids);
$this->success("提交成功");
}else{
$this->pagetitle="我的购物车";
$member_id = session("member.member_id");
$where["member_id"] = $member_id;
$data = $this->ShopCart->relation(true)->where($where)->select();
$this->data = $data;
$this->shopcart_act = "on";
$this->display();
}
}
public function change_shop_cart(){
$id = I("get.id");
$quantity = I("get.num");
// 修改条件
$where["id"] = $id;
$where["member_id"] = session("member.member_id");
// 保存数据
$data["quantity"] = $quantity;
$res = $this->ShopCart->where($where)->save($data);
$this->success($res);
}
public function add_shop_cart(){
$product_id = I("post.id");
$member_id = session("member.member_id");
$quantity = I("post.num");
$where["product_id"] = $product_id;
$where["member_id"] = $member_id;
$res = $this->ShopCart->where($where)->find();
if($res){
$res["quantity"] += $quantity;
$this->ShopCart->save($res);
}else{
$data["quantity"] = $quantity;
$data["catid"] = M("cms_product")->where(array("id"=>$product_id))->getField("catid");
$data["product_id"] = $product_id;
$data["member_id"] = $member_id;
$data["addtime"] = time();
$this->ShopCart->add($data);
}
$this->success("加入购物车成功!");
}
public function move_collect(){
$member_id = session("member.member_id");
$ids = I("post.ids");
if(is_array($ids)){
$where["id"] = array("in",$ids);
}else if($ids){
$where["id"] = $ids;
}else{
$this->error("请选择购物车商品");
}
$where["member_id"] = $member_id;
// 查询所有需要修改的购物车信息
$res_data = $this->ShopCart->where($where)->select();
// 删除购物车信息
// $this->ShopCart->where($where)->delete();
$collect = M("collect");
foreach($res_data as $k => $v){
$where = array();
$where["product_id"] = $v["product_id"];
$where["member_id"] = $member_id;
$rs = $collect->where($where)->find();
if(!$rs){
$data[$k]["product_id"] = $v["product_id"];
$data[$k]["member_id"] = $member_id;
$data[$k]["addtime"] = time();
$data[$k]["checked"] = 1;
}
if($rs["checked"] == 0){
$rs["checked"] = 1;
$collect->save($rs);
}
}
if($data){
$res = $collect->addAll($data);
}
$this->success("添加成功");
}
public function delete(){
$id = I("get.delete_id");
$member_id = session("member.member_id");
$where["id"] = $id;
$where["member_id"] = $member_id;
$this->ShopCart->where($where)->delete();
$this->success();
}
//当前用户收件地址列表
public function addressList(){
$member_id = session("member.member_id");
$where["member_id"] = $member_id;
$this->data= M("member_address")->where($where)->select();
$this->display();
}
//新增收件地址
public function addAddress(){
$this->display();
}
//编辑收货地址
public function editorAddress(){
$where["id"] = I("get.id");
$where["member_id"] = session("member.member_id");
$this->r= M("member_address")->where($where)->find();
$this->display();
}
//发票抬头列表
public function fpList(){
$member_id = session("member.member_id");
$where["member_id"] = $member_id;
$data= M("member_invoice")->where($where)->order("id desc")->select();
$this->success($data);
}
}
@@ -0,0 +1,162 @@
<?php
namespace Shop\Controller;
use Member\Controller\BaseController;
class ShopOrderController extends BaseController {
public function __construct() {
parent::__construct();
$this->table = D("ShopOrder");
//系统查询哪些超时付款,超时未收货自动做相关操作
$this->table->autoReceipt();
$this->table->autoCancelOrder();
}
public function index(){
$this->status_code=I("get.status_code");//订单状态
$where=array();
$where["member_id"]=session("member.member_id");
//订单号
$order_num=I("get.order_num");
if($order_num){
$where["db_shop_order.order_num"]=$order_num;
}
//订货号
$type_no=I("get.type_no");
if($type_no){
$where["type_no"]=$type_no;
}
//产品名称
$title=I("get.title");
if($title){
$where["title"]=array("like","%".$title."%");
}
//订单状态
if($this->status_code){
$where["status_code"]=$this->status_code;
}
//不同状态下的订单统计
$this->readyPayCount=$this->table->where(array(
"member_id"=>session("member.member_id"),
"status_code"=>101,
))->count();
$this->readyDeliveryCount=$this->table->where(array(
"member_id"=>session("member.member_id"),
"status_code"=>102,
))->count();
$this->readyReceiptCount=$this->table->where(array(
"member_id"=>session("member.member_id"),
"status_code"=>103,
))->count();
$this->ReceiptCount=$this->table->where(array(
"member_id"=>session("member.member_id"),
"status_code"=>104,
))->count();
//
$total=$this->table
->join("db_shop_order_detail on db_shop_order.order_id=db_shop_order_detail.order_id")
->where($where)->group("db_shop_order.order_id")->count();
$page = new \Think\Page($total,10);
$data=$this->table
->join("db_shop_order_detail on db_shop_order.order_id=db_shop_order_detail.order_id")
->relation(true)->where($where)->group("db_shop_order.order_id")->order("db_shop_order.order_id desc")->limit($page->firstRow,$page->listRows)->select();
$this->assign("listpage", $page->show());
$this->assign("data",$data);
$this->pagetitle="我的订单";
$this->navLight="wddj";//菜单高亮
$this->display();
}
//订单详情
public function show($order_id){
$where["member_id"]=session("member.member_id");
$where["order_id"]=$order_id;
$this->r=$this->table->relation(true)->where($where)->find();
$this->pagetitle="订单详情";
$this->navLight="wddj";//菜单高亮
$this->display();
}
//取消订单
public function cancelOrder($order_id){
$where["member_id"]=session("member.member_id");
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
//
if($order[status_code]!=101){
$this->error("订单状态不允许取消");
}
//调用模型里的取消订单
$this->table->cancelOrder($order_id,"用户取消订单");
$this->success("取消成功");
}
//用户申请退款
public function refundOrder($order_id){
$where["member_id"]=session("member.member_id");
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
//查看是否支付
if($order[is_pay]!=1){
$this->error("未付款订单不需要申请退款");
}
if(M("shop_order_refund")->find($order_id)){
$this->error("您已经申请过了");
}
//增加退款表
M("shop_order_refund")->add(array(
"order_id"=>$order_id,
"is_refund"=>1,
"is_refund_time"=>time(),
));
//改状态
$this->table->setOrderState($order_id);//改状态
//写日志
$this->table->log($order_id,"用户申请退款");
$this->success("操作成功");
}
//删除订单
public function deleteOrder($order_id){
$where["member_id"]=session("member.member_id");
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
//
if($order[status_code]!=201){
$this->error("订单状态不允许删除");
}
//调用模型里的取消订单
$this->table->deleteOrder($order_id);
$this->success("删除成功");
}
//用户确认收货
public function confirmReceipt($order_id){
$where["member_id"]=session("member.member_id");
$where["order_id"]=$order_id;
$order=$this->table->where($where)->find();
if(!$order){
$this->error("订单不存在");
}
//
if($order[status_code]!=103){
$this->error("订单状态不允许操作");
}
//调用模型里的确认收货
$this->table->confirmReceipt($order_id,"用户确认收货");
$this->success("取消成功");
}
//快递
public function kuaidi($com,$num){
$kuaidi=new \Model\KuaidiModel($com, $num);
$kuaidi_result=$kuaidi->getKuaidi();
if(!$kuaidi_result){
$this->error($kuaidi->getError());
}else{
$this->data=$kuaidi_result;
$this->pagetitle="物流查询";
$this->display();
}
}
}