Пример #1
0
    public function payResult($params)
    {
        global $_W, $_GPC;
        $fee = intval($params['fee']);
        $data = array('status' => $params['result'] == 'success' ? 1 : 0);
        $paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 2, 'delivery' => 3);
        $data['pay_type'] = $paytype[$params['type']];
        if ($params['type'] == 'wechat') {
            $data['transid'] = $params['tag']['transaction_id'];
        }
        $goodsId = pdo_fetchcolumn("SELECT `g_id` FROM" . tablename('tg_order') . "WHERE `orderno` = :orderid ", array(':orderid' => $params['tid']));
        $goodsInfo = pdo_fetch("SELECT * FROM" . tablename('tg_goods') . "WHERE `id` = :id ", array(':id' => $goodsId));
        // //货到付款
        if ($params['type'] == 'delivery') {
            $data['status'] = 1;
            $data['starttime'] = TIMESTAMP;
            $data['ptime'] = TIMESTAMP;
        }
        if ($params['result'] == 'success') {
            $data['ptime'] = TIMESTAMP;
            $data['starttime'] = TIMESTAMP;
        }
        $tuan_id = pdo_fetch("select * from" . tablename('tg_order') . "where orderno = '{$params['tid']}'");
        $goods = pdo_fetch("select * from" . tablename('tg_order') . "where id = '{$tuan_id['g_id']}'");
        if ($params['from'] == 'return') {
            $pay_suc = $this->module['config']['pay_suc'];
            $pay_remark = $this->module['config']['pay_remark'];
            $m_pay = $this->module['config']['m_pay'];
            //支付成功模板消息提醒
            $content = "";
            if ($tuan_id['tuan_first'] == 1) {
                $content .= "您已成功付款开团,恭喜您荣升团长,组团成功才会享受优惠哦";
            } else {
                $content .= "您已成功付款参团,组团成功才会享受优惠哦";
            }
            load()->func('communication');
            load()->model('account');
            $access_token = WeAccount::token();
            $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . "";
            $url2 = $_W['siteroot'] . 'app/' . $this->createMobileUrl('orderdetails', array('id' => $params['tid']));
            //点击模板详情跳转的地址url2
            $time = date("Y-m-d H:i:s", time());
            $openid = trim($_W['openid']);
            $msg_json = '{

               	"touser":"******",

               	"template_id":"' . $m_pay . '",

               	"url":"' . $url2 . '",

               	"topcolor":"#FF0000",

               	"data":{

                   	"first":{

                       "value":"\\n' . $pay_suc . '\\n",

                       "color":"#000000"

                   	},

                   	"orderProductName":{

						"value":"' . $goodsInfo['gname'] . '\\n",

                   		"color":"#000000"

					},

                   	"orderMoneySum":{

						"value":"' . $tuan_id['price'] . '\\n",

                   	    "color":"#000000"

					},

                   	"remark":{

                       "value":"\\n\\n' . $pay_remark . '",

                       "color":"#0099FF"

                   	}

               	}

           	}';
            include_once 'message.php';
            $sendmessage = new WX_message();
            $res = $sendmessage->WX_request($url, $msg_json);
            $setting = uni_setting($_W['uniacid'], array('creditbehaviors'));
            $credit = $setting['creditbehaviors']['currency'];
            if ($tuan_id['status'] != 1) {
                pdo_update('tg_order', $data, array('orderno' => $params['tid']));
                // 更改库存
                if (!empty($goodsInfo['gnum'])) {
                    pdo_update('tg_goods', array('gnum' => $goodsInfo['gnum'] - 1, 'salenum' => $goodsInfo['salenum'] + 1), array('id' => $goodsId));
                }
            }
            $order_out = pdo_fetch("select * from" . tablename('tg_order') . "where orderno = '{$params['tid']}'");
            //判断人数,是否团购成功
            $sql = "SELECT * FROM" . tablename('tg_order') . "where tuan_id=:tuan_id and status =:status ";
            $params = array(':tuan_id' => $tuan_id['tuan_id'], ':status' => 1);
            $alltuan = pdo_fetchall($sql, $params);
            $item = array();
            foreach ($alltuan as $num => $all) {
                $item[$num] = $all['id'];
                if ($all['tuan_first'] == 1) {
                    $tuan_firstopenid = $all['openid'];
                }
            }
            $profile = pdo_fetch("SELECT * FROM " . tablename('tg_member') . " WHERE uniacid ='{$_W['uniacid']}' and from_user = '******'");
            $n = $goodsInfo['groupnum'] - count($item);
            if ($n == 0) {
                pdo_update('tg_order', array('success' => 0), array('tuan_id' => $tuan_id['tuan_id'], 'status' => 1));
                //组团成功模板消息提醒
                $m_tuan = $this->module['config']['m_tuan'];
                $tuan_suc = $this->module['config']['tuan_suc'];
                $tuan_remark = $this->module['config']['tuan_remark'];
                $content = "组团成功!!!";
                load()->func('communication');
                load()->model('account');
                $access_token = WeAccount::token();
                $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . "";
                $url2 = "";
                //点击模板详情跳转的地址url2
                $time = date("Y-m-d H:i:s", time());
                foreach ($alltuan as $num => $all) {
                    $openid = trim($all['openid']);
                    $msg_json = '{

	                   	"touser":"******",

	                   	"template_id":"' . $m_tuan . '",

	                   	"url":"' . $url2 . '",

	                   	"topcolor":"#FF0000",

	                   	"data":{

	                       	"first":{

	                           "value":"\\n' . $tuan_suc . '\\n",

	                           "color":"#000000"

	                       	},

	                       	"Pingou_ProductName":{

								"value":"' . $goodsInfo['gname'] . '\\n",

	                       		"color":"#000000"

							},

	                       	"Weixin_ID":{

								"value":"' . $profile['nickname'] . '\\n",

	                       	    "color":"#000000"

							},

	                       	"remark":{

	                           "value":"\\n\\n' . $tuan_remark . '",

	                           "color":"#0099FF"

	                       	}

	                   	}

	               	}';
                    $sendme = new WX_message();
                    $res = $sendme->WX_request($url, $msg_json);
                    //获取所有打印机
                    $prints = pdo_fetchall('SELECT * FROM ' . tablename('tg_print') . ' WHERE uniacid = :aid AND status = 1', array(':aid' => $_W['uniacid']));
                    if (!empty($prints)) {
                        include_once 'wprint.class.php';
                        //遍历所有打印机
                        foreach ($prints as $li) {
                            if (!empty($li['print_no']) && !empty($li['key'])) {
                                $wprint = new wprint();
                                if ($li['mode'] == 1) {
                                    $orderinfo .= "<CB>组团成功</CB><BR>";
                                    $orderInfo .= "商品信息:<BR>";
                                    $orderinfo .= '------------------------------<BR>';
                                    $orderinfo .= "商品名称:{$goodsInfo['gname']}<BR>";
                                    $orderinfo .= '------------------------------<BR>';
                                    $orderinfo .= "用户信息:<BR>";
                                    $orderinfo .= '------------------------------<BR>';
                                    foreach ($alltuan as $row) {
                                        $user = pdo_fetch("select * from" . tablename('tg_address') . "where id='{$row['addressid']}'");
                                        $orderinfo .= "用户名:{$user['cname']}<BR>";
                                        $orderinfo .= "手机号:{$user['tel']}<BR>";
                                        $orderinfo .= "地址:{$user['province']}{$user['city']}{$user['county']}{$user['detailed_address']}<BR>";
                                        $orderinfo .= '------------------------------<BR>';
                                    }
                                    $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, $li['print_nums']);
                                } else {
                                    $orderinfo .= "组团成功";
                                    $orderInfo .= "商品信息:";
                                    $orderinfo .= '------------------------------';
                                    $orderinfo .= "商品名称:{$goodsInfo['gname']}";
                                    $orderinfo .= '------------------------------';
                                    $orderinfo .= "用户信息:";
                                    $orderinfo .= '------------------------------';
                                    foreach ($alltuan as $row) {
                                        $user = pdo_fetch("select * from" . tablename('tg_address') . "where id='{$row['addressid']}'");
                                        $orderinfo .= "用户名:{$user['cname']}";
                                        $orderinfo .= "手机号:{$user['tel']}";
                                        $orderinfo .= "地址:{$user['province']}{$user['city']}{$user['county']}{$user['detailed_address']}";
                                        $orderinfo .= '------------------------------';
                                    }
                                    $status = $wprint->testSendFreeMessage($li['member_code'], $li['print_no'], $li['key'], $orderinfo);
                                }
                                if (!is_error($status)) {
                                    $i++;
                                    $data = array('uniacid' => $_W['uniacid'], 'sid' => $sid, 'pid' => $li['id'], 'oid' => $id, 'status' => 1, 'foid' => $status, 'addtime' => TIMESTAMP);
                                    pdo_insert('tg_order_print', $data);
                                }
                            }
                        }
                    }
                }
            } elseif ($n < 0) {
                echo "<script>location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('more_refund', array('transid' => $order_out['transid'])) . "';</script>";
                exit;
            }
            if ($params['type'] == $credit) {
                if ($tuan_id['is_tuan'] == 0) {
                    //					message('支付成功!', $this->createMobileUrl('myorder'), 'success');
                    echo "<script>alert('支付成功!');location.href='" . $this->createMobileUrl('myorder') . "';</script>";
                    exit;
                } else {
                    //					message('支付成功!', $this->createMobileUrl('group',array('tuan_id' => $tuan_id['tuan_id'])), 'success');
                    echo "<script>alert('支付成功!');location.href='" . $this->createMobileUrl('group', array('tuan_id' => $tuan_id['tuan_id'])) . "';</script>";
                    exit;
                }
            } else {
                if ($tuan_id['is_tuan'] == 0) {
                    //					message('支付成功!', '../../app/' . $this->createMobileUrl('myorder'), 'success');
                    echo "<script>alert('支付成功!');location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder') . "';</script>";
                    exit;
                } else {
                    //			   		message('支付成功!', '../../app/' . $this->createMobileUrl('group',array('tuan_id' => $tuan_id['tuan_id'])), 'success');
                    echo "<script>alert('支付成功!');location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('group', array('tuan_id' => $tuan_id['tuan_id'])) . "';</script>";
                    exit;
                }
            }
        }
    }
Пример #2
0
 public function payResult($params)
 {
     global $_W, $_GPC;
     $fee = intval($params['fee']);
     $data = array('status' => $params['result'] == 'success' ? 1 : 0);
     $paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 2, 'delivery' => 3);
     $data['pay_type'] = $paytype[$params['type']];
     if ($params['type'] == 'wechat') {
         $data['transid'] = $params['tag']['transaction_id'];
     }
     $data['ptime'] = TIMESTAMP;
     $data['starttime'] = TIMESTAMP;
     $order_out = pdo_fetch("select * from" . tablename('tg_order') . "where orderno = '{$params['tid']}'");
     $goodsInfo = pdo_fetch("SELECT * FROM" . tablename('tg_goods') . "WHERE `id` = :id ", array(':id' => $order_out['g_id']));
     $nowtuan = pdo_fetch("select * from" . tablename('tg_group') . "where groupnumber = '{$order_out['tuan_id']}'");
     if (!empty($nowtuan)) {
         if ($nowtuan['lacknum'] == 0 && $order_out['status'] == 0) {
             $data['status'] = 6;
             $data['is_tuan'] = 2;
             echo "<script>location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('more_refund', array('data' => $data, 'orderno' => $params['tid'])) . "';</script>";
             exit;
         }
     }
     //后台通知,修改状态
     if ($params['result'] == 'success' && $params['from'] == 'notify') {
         /*支付成功消息模板*/
         require_once MB_ROOT . '/source/Message.class.php';
         load()->model('account');
         $access_token = WeAccount::token();
         $url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . "";
         $url2 = $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder', array('id' => $order_out['id']));
         $sendmessage = new Message();
         $res = $sendmessage->pay_success($order_out['openid'], $order_out['orderno'], $goodsInfo['gname'], $this, $url1, $url2);
         /*支付成功模板消息*/
         if ($order_out['status'] == 0) {
             pdo_update('tg_order', $data, array('orderno' => $params['tid']));
             if ($order_out['is_tuan'] == 0) {
                 pdo_update('tg_order', array('status' => 2), array('orderno' => $params['tid']));
             } else {
                 if ($nowtuan['lacknum'] > 0) {
                     pdo_update('tg_group', array('lacknum' => $nowtuan['lacknum'] - 1), array('groupnumber' => $order_out['tuan_id']));
                 }
             }
             // 更改库存
             if ($goodsInfo['gnum'] == 1) {
                 pdo_update('tg_goods', array('gnum' => $goodsInfo['gnum'] - 1, 'salenum' => $goodsInfo['salenum'] + 1, 'isshow' => 0), array('id' => $order_out['g_id']));
             } elseif (!empty($goodsInfo['gnum'])) {
                 pdo_update('tg_goods', array('gnum' => $goodsInfo['gnum'] - 1, 'salenum' => $goodsInfo['salenum'] + 1), array('id' => $order_out['g_id']));
             }
         }
         $now = pdo_fetch("select * from" . tablename('tg_group') . "where groupnumber = '{$order_out['tuan_id']}'");
         if (!empty($now) && $now['lacknum'] == 0) {
             pdo_update('tg_group', array('groupstatus' => 2), array('groupnumber' => $now['groupnumber']));
             pdo_update('tg_order', array('status' => 2), array('tuan_id' => $now['groupnumber'], 'status' => 1));
             /*组团成功成功消息模板*/
             require_once MB_ROOT . '/source/Message.class.php';
             load()->model('account');
             $access_token = WeAccount::token();
             $url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . "";
             $url2 = '';
             $sendmessage = new Message();
             $res = $sendmessage->group_success($order_out['tuan_id'], $this, $url1, $url2);
             /*组团成功模板消息*/
             //获取所有打印机
             $prints = pdo_fetchall('SELECT * FROM ' . tablename('tg_print') . ' WHERE uniacid = :aid AND status = 1', array(':aid' => $_W['uniacid']));
             if (!empty($prints)) {
                 include_once MB_ROOT . '/source/wprint.class.php';
                 //遍历所有打印机
                 foreach ($prints as $li) {
                     if (!empty($li['print_no']) && !empty($li['key'])) {
                         $wprint = new wprint();
                         $alltuan = pdo_fetchall("select * from" . tablename('tg_order') . "where tuan_id = '{$now['groupnumber']}' and status = 2 ");
                         if ($li['mode'] == 1) {
                             $orderinfo .= "<CB>组团成功</CB><BR>";
                             $orderInfo .= "商品信息:<BR>";
                             $orderinfo .= '------------------------------<BR>';
                             $orderinfo .= "商品名称:{$goodsInfo['gname']}<BR>";
                             $orderinfo .= '------------------------------<BR>';
                             $orderinfo .= "用户信息:<BR>";
                             $orderinfo .= '------------------------------<BR>';
                             foreach ($alltuan as $row) {
                                 $orderinfo .= "用户名:{$row['addname']}<BR>";
                                 $orderinfo .= "手机号:{$row['mobile']}<BR>";
                                 $orderinfo .= "地址:{$row['address']}<BR>";
                                 $orderinfo .= '------------------------------<BR>';
                             }
                             $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, $li['print_nums']);
                         } else {
                             $orderinfo .= "组团成功";
                             $orderInfo .= "商品信息:";
                             $orderinfo .= '------------------------------';
                             $orderinfo .= "商品名称:{$goodsInfo['gname']}";
                             $orderinfo .= '------------------------------';
                             $orderinfo .= "用户信息:";
                             $orderinfo .= '------------------------------';
                             foreach ($alltuan as $row) {
                                 $orderinfo .= "用户名:{$row['addname']}";
                                 $orderinfo .= "手机号:{$row['mobile']}";
                                 $orderinfo .= "地址:{$row['address']}";
                                 $orderinfo .= '------------------------------';
                             }
                             $status = $wprint->testSendFreeMessage($li['member_code'], $li['print_no'], $li['key'], $orderinfo);
                         }
                     }
                 }
             }
         }
     }
     //前台通知
     if ($params['from'] == 'return') {
         $setting = uni_setting($_W['uniacid'], array('creditbehaviors'));
         $credit = $setting['creditbehaviors']['currency'];
         if ($params['type'] == $credit) {
             if ($order_out['is_tuan'] == 0) {
                 echo "<script> location.href='" . $this->createMobileUrl('myorder', array('payreslut' => 'success')) . "';</script>";
                 exit;
             } else {
                 echo "<script>  location.href='" . $this->createMobileUrl('group', array('tuan_id' => $order_out['tuan_id'], 'payreslut' => 'success')) . "';</script>";
                 exit;
             }
         } else {
             if ($order_out['is_tuan'] == 0) {
                 echo "<script>  location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder', array('payreslut' => 'success')) . "';</script>";
                 exit;
             } else {
                 echo "<script>  location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('group', array('tuan_id' => $order_out['tuan_id'], 'payreslut' => 'success')) . "';</script>";
                 exit;
             }
         }
     }
 }