123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\api\controller;
- use app\api\controller\Base;
- use think\Controller;
- use think\Db;
- use think\Model;
- use Alipay\EasySDK\Kernel\Factory;
- use Alipay\EasySDK\Kernel\Util\ResponseChecker;
- use Alipay\EasySDK\Kernel\Config;
- /**
- * 支付宝支付
- * Class Member
- * @package app\api\controller
- */
- class Alipay extends Base
- {
- /**
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- * 支付宝支付
- */
- public static function ali_pay($subject,$outTradeNo,$totalAmount,$notifyUrl){
- Factory::setOptions(self::getOptions($notifyUrl));
- try {
- //2. 发起API调用(以支付能力下的统一收单交易创建接口为例)
- //$result = Factory::payment()->common()->create("iPhone6 16G", "20200326235526001", "88.88", "2088002656718920");
- $result = Factory::payment()->App()->pay($subject,$outTradeNo , $totalAmount);
- $responseChecker = new ResponseChecker();
- //3. 处理响应或异常
- if ($responseChecker->success($result)) {
- return $result->body;
- } else {
- echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
- }
- } catch (Exception $e) {
- return false;
- }
- }
- public static function ali_pay_pc($subject='商品',$outTradeNo,$totalAmount,$notifyUrl,$returnUrl){
- Factory::setOptions(self::getOptions($notifyUrl));
- try {
- $result = Factory::payment()->Page()->pay($subject,$outTradeNo,$totalAmount,$returnUrl);
- $responseChecker = new ResponseChecker();
- //3. 处理响应或异常
- if ($responseChecker->success($result)) {
- return $result->body;
- } else {
- echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
- }
- } catch (Exception $e) {
- return false;
- }
- }
- /**
- * 支付宝支付退款
- */
- public static function ali_refund($outTradeNo,$totalAmount){
- Factory::setOptions(self::getOptions(''));
- $result = Factory::payment()->common()->refund($outTradeNo,$totalAmount);
- $responseChecker = new ResponseChecker();
- return $responseChecker->success($result);
- }
- /**
- * 单笔转账到支付宝账户
- */
- public static function ali_withdrawal($out_biz_no,$trans_amount,$identity,$name){
- require_once env('root_path').'/vendor/aop/AopCertClient.php';
- require_once env('root_path').'/vendor/aop/request/AlipayFundTransUniTransferRequest.php';
- $aop = new \AopCertClient();
- $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
- $aop->appId = '2021002142672998';
- $aop->rsaPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCTKpmmpfu6Hrn5xImo1dIQebMgJNh8KaTDdzPN6skQL8n/xELxbNZ5G1SF58H/ZzfQHaI0ZdDUhS01o7ujlh5TVdBkTEzanl2ctdFEQdCI3q6syYWs7P4gY3jLYH+XYjZs9beF3IpNRSEPj694dm3mvmVzcN9oYks2h3BNmAcbVx+IbMPRMbGKyXq2pxQguuYg+Yl7y7VpvY1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DzVk1dg+SYGyd88DwakwbM5Sgy87dqmmPRp+ZYuZDiKbxFBk9es0NL1luV6LUoxUGe7bsVwj2X2IFtKz/qAi7OvW3UdygxVA2GhpJUfEjwRr9Wc1h38CgYEAyTcugtxt6WIT1MtepWwxMgasiuEQgAYY0oQ/tgPxBqZyz5Pkm9yJNsyrvgNfBZFTdexqkby80UGksXt24WsPfhVinTmtuNo8/JOgKkFU4BR3rirfqGB11o/83Z52XFne7D+rR9a1XP4mT+Q+yLQWOT0ETo2+712/+86uUW+rjj8=';
- $aop->alipayrsaPublicKey='';
- $aop->apiVersion = '1.0';
- $aop->signType = 'RSA2';
- $aop->postCharset='UTF-8';
- $aop->format='json';
- $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
- //支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt
- $alipayCertPath = 'ali_cert/alipayCertPublicKey_RSA2.crt';
- //调用getPublicKey从支付宝公钥证书中提取公钥 alipayCertPath
- $aop->alipayrsaPublicKey =$aop->getPublicKey($alipayCertPath);
- // 应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt
- $appCertPath = 'ali_cert/appCertPublicKey_2021002142672998.crt';
- //调用getCertSN获取证书序列号
- $aop->appCertSN = $aop->getCertSN($appCertPath);
- //支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt
- $rootCertPath = 'ali_cert/alipayRootCert.crt';
- //调用getRootCertSN获取支付宝根证书序列号
- $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);
- $orderData= array(
- 'out_biz_no' => $out_biz_no,// 订单号
- 'trans_amount' => $trans_amount, // 提现实际金额
- 'product_code' => "TRANS_ACCOUNT_NO_PWD",
- 'biz_scene' => 'DIRECT_TRANSFER',
- 'payee_info' => [
- 'identity' => $identity,// 收款人帐户
- 'identity_type' => 'ALIPAY_LOGON_ID',
- 'name' => $name, // 收款人姓名
- ],
- 'remark' => "提现", // 转帐备注
- );
- $request = new \AlipayFundTransUniTransferRequest();
- $request->setBizContent(json_encode($orderData));
- $result = $aop->execute($request);
- //var_dump($result);exit();
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if(!empty($resultCode)&&$resultCode == 10000){
- return true;
- } else {
- return false;
- }
- }
- public static function getOptions($notifyUrl){
- $options = new Config();
- $options->protocol = 'https';
- $options->gatewayHost = 'openapi.alipay.com';
- $options->signType = 'RSA2';
- $options->appId = '2021002141666136';
- // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
- $options->merchantPrivateKey = 'MIIEpQIBAAKCAQEAhAunpRNIX2PaDe3wdTtMaWtUOGYBRUHBUTDdrwPbhJf7wd76EfUh6T/C6N+PcMjvsN6BJpMy/PqiP9aLKaY6W0oXaTILmTNk6v/Qdn+hLcrLhzN3sd+X9mZCcilc7o3/AKZkupcM2BguDoGugpdrhALmoRe20gDC0+0mLBTzBaA3VXxkPn9DXhl+ggsM7jy6SyMRwbC5EaQALnbtlitYhbdaZmloR5fDIsVkt2xPAHoJMG8nuTOEc213BxV/aS23ek6mwCUmZLvRvZvu/ODyHw1jhCRRzmPSI6ANezr8odY++ZTxzv6qHukKFCLF7RlzaNRzKgE8QfQ4yEO2EFPg1wIDAQABAoIBABC0dMICfX5r4HMwreH23YTcqiv0Y6bCWdWOrAzvHP9aRuRQ9Cv/agnbIipZ1gi7su8aRxZ9Os8cWhhfaP2c5PcVmX6acTMxeEvujw3euaJUbIkvLq5XDh+C8lcE+pfHaQJJCqc8YsiXzoPRTiWBSH3L7CdnG57Xr84ly1V6VQBaBPSq+QhjD4r8P1tucszKsflicR4RxauyQjJqsv19xY8poogw+rMX4eZvD4D50KbQewAAF6MOzHMeY+NQdTs65qevmYdULc54xEVrfvKxElcS/bB+1vbVolEKbxnK1d6676xVdHK8wGS/z5x4lRbdkntNgE2CrFZFY+ZuKpVKu2kCgYEAwGgXJXVF+79FcL4P/490QFxonaWT9IH2Jb7RYS6UdejReDhFjcp21HVPO0t+/0Ei82ihCxwckvpkJvvhDtST6IdH/tXNnuAjZzIqwtdfHzvjP2a2jjQeYwf7R4YjLT5ZA+2fOaVhXIR50yVPb+yj7XUnqgoLwhHKd0MBxL4tZeMCgYEAr7BK2tOYccQSgc+I3MslRLqwIAwXN89hV/3OkjwHjaRNbEw6rMIHHpa03+cVvaZLgxHYT/ULWUiIpguAwCD+aKLcoDqxSMGPOQsYHLuxCJPkvLlm/OOlpEHQrQB9ENSBI7nybBtfwvNiY7n9P9lpCczFSH3TRTxt/Q6AzrmEK30CgYEAo8+7bSvUYoqtX1iiHE4Rhr5mX1nahwCjBe3ZK+lRgrWuqbEXHqoy053w0CXtwPq+/AennOLZPRWrcTlfmpXIO9/5nvB++PYRjkm6+FoPZXNCffdAFAAxotTnzjRY/KspdFu6BYVVSESNyAPrBvqtcn0dQPr+mcM14qYM+mmEE0sCgYEAmIxhorpBzt6qFy7lrplxpcjYLytwaZRW+Lk3yX/4KwOz+koCVIkw911ydkvHc+HWBVvUUDD8hqzVgh/QzoKXhLGNEk+EKiFvQ9+fMyvB3ynTXg86HnFoHUTMdbtL3PY3n5bQqQ/nyXXdQ6x1+h/D9a9oybX/YUnEUwtpypYI7l0CgYEAjhsEOG9HHyUt/s3l5uSTo8EI4R3SPNE3d4V02Cm+nrCX40jO+TnkWcLuxdWXP2OUfd10chcIczjH1AtoRWbF/DLFBdYvBtS0N6JEdTD0UCYK/WH169hrXc247ycXGba6gPK2xq7oM3Zcso60+ibB+HEtTsrePTZlVDRNwsLmCnc=';
- /*$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
- $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
- $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';*/
- //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
- $options->alipayPublicKey ='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn/i44o8b1xAA8M026tGsl4gagl8Otx0r4pC69KP3dsaL2i7OS2a3lP9mLpQ/S1awqflc8TWGeLqxffUy/L4aF2zYuq17jeuwxfN0uc+8cxX8QvwhGUuWVt/u1MgdLjij5OOk1dgEy6s0EIhefFpOKX9WGSwOqa9rbstqt7grTJXexEIJ+gBvsQ/Vem32wwZMrzSsb7NNwuXMl+/j2RAf1zhnrvZUKQfdiSYuXtWYnLM2MJS258sMC0+q2ImKwhl5Oibt05xaFpL+gBBkyT3Jr+tkU3pcJXraoyhtXnCD0dNTTdr0xpLZsIEzEwoLgeX4XCa7iF3hQArgmmG3kAUNSQIDAQAB';
- //可设置异步通知接收服务地址(可选)
- $options->notifyUrl = $notifyUrl;
- //可设置AES密钥,调用AES加解密相关接口时需要(可选)
- $options->encryptKey = "";
- return $options;
- }
- public static function getOptions_test($notifyUrl){
- $options = new Config();
- $options->protocol = 'https';
- $options->gatewayHost = 'openapi.alipay.com';
- $options->signType = 'RSA2';
- $options->appId = '2021002142672998';
- // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
- $options->merchantPrivateKey = 'MIIEogIBAAKCAQEA2D4+Ps22cufmzn+mt14TOKNS0xHH+BX/2OpUM8RZh8YjMWqQyY4UlxDJeiegabOk2yRID3N4R2YlL6Ye51+3NxNTf3dCGe9ZllpaZJle0hS6KpRrX3d32HoadzQNQU2MjHN+G/OvoA7WuvfomdnY7OGDsxw++EWOcgueL62uEFAzMMsOxnoUBaf+MIXCW8bTl34dyj/5WiruVyUFVyfqh5RjFBm34UTW0d8OqV8eZfK1hr5ElzVrs3JbS8FCACQHznozJcWRH8GNjYVjOsJk2g30fTx4DmbTx3HWnfzFjrvy7Bp41XUeLmFpgTETRCMEE/Omq0DJCJ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GAB1FUyyZuSS5EQIRWmFktbGCGiAGBxu71yq2Fqmal/ggPGLLWFM3Gy4ISkTjbxshQzCvDxJOyDLl8+96NeTFjRb7CC2yoCgDUNe5/z7YgNlHggx5SKWcw3tqxDc1maMvp6tkNEX/VC6ePidxrEL4fM8jb+VFLXv1B1W4Ekr9fmJw=';
- /*$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
- $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
- $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';*/
- //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
- $options->alipayPublicKey ='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn/i44o8b1xAA8M026tGsl4gagl8Otx0r4pC69KP3dsaL2i7OS2a3lP9mLpQ/S1awqflc8TWGeLqxffUy/L4aF2zYuq17jeuwxfN0uc+8cxX8QvwhGUuWVt/u1MgdLjij5OOk1dgEy6s0EIhefFpOKX9WGSwOqa9rbstqt7grTJXexEIJ+gBvsQ/Vem32wwZMrzSsb7NNwuXMl+/j2RAf1zhnrvZUKQfdiSYuXtWYnLM2MJS258sMC0+q2ImKwhl5Oibt05xaFpL+gBBkyT3Jr+tkU3pcJXraoyhtXnCD0dNTTdr0xpLZsIEzEwoLgeX4XCa7iF3hQArgmmG3kAUNSQIDAQAB';
- //可设置异步通知接收服务地址(可选)
- $options->notifyUrl = $notifyUrl;
- //可设置AES密钥,调用AES加解密相关接口时需要(可选)
- $options->encryptKey = "";
- return $options;
- }
- //保证金支付回调
- public function deposit_notify()
- {
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $pay_no = $result['out_trade_no'];
- // 用户支付成功处理
- $order_info = Db::name('store_deposit_order')->where('pay_no',$pay_no)->where('status',0)->find();
- if(empty($order_info)){
- return false;
- }
- Db::table('store_deposit_order')->where('pay_no',$order_info['pay_no'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
- $wid = Db::table('store_deposit_order')->where('pay_no',$order_info['pay_no'])->value('worker_id');
- //更新是否缴纳保证金
- Db::name('store_worker')->where('id',$wid)->update(array('deposit'=>1));
- //添加运输路线
- $county_arr = explode(',',$order_info['county']);
- foreach ($county_arr as $area){
- $city_id = Db::name('store_area')->where('id',$area)->value('pid');
- $province_id = Db::name('store_area')->where('id',$city_id)->value('pid');
- $area_data = array(
- 'worker_id' => $wid,
- 'start_province_id' => $order_info['start_province'],
- 'start_city_id' => $order_info['start_city'],
- 'start_county_id' => $order_info['start_county'],
- 'end_province_id' => $province_id,
- 'end_city_id' => $city_id,
- 'end_county_id' => $area
- );
- Db::name('store_serve_area')->insert($area_data);
- }
- return true; // 返回处理完成
- } else {
- }
- }
- //自动报价支付回调
- public function offer_notify()
- {
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $pay_no = $result['out_trade_no'];
- // 用户支付成功处理
- $order_info = Db::name('store_offer_order')->where('pay_no',$pay_no)->where('status',0)->find();
- if(empty($order_info)){
- return false;
- }
- Db::table('store_offer_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
- $order_info = Db::table('store_offer_order')->where('pay_no',$pay_no)->find();
- //添加接单人员自动报价信息
- $offer_time = Db::name('store_worker')->where('id',$order_info['worker_id'])->value('offer_time');
- $offer_timestamp = 0;
- if($order_info['type'] == 1){
- $offer_timestamp = strtotime('next month');
- }elseif($order_info['type'] == 2){
- $offer_timestamp = strtotime('+3 month');
- }elseif ($order_info['type'] == 3){
- $offer_timestamp = strtotime('+1years');
- }
- if($offer_time && $offer_time > time()){
- $offer_timestamp = $offer_timestamp + ($offer_time - time());
- }
- Db::name('store_worker')->where('id',$order_info['worker_id'])->update(array('offer_time'=>$offer_timestamp));
- return true; // 返回处理完成
- } else {
- }
- }
- //PC端雇主下单支付回调
- public function order_notify()
- {
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $pay_no = $result['out_trade_no'];
- // 用户支付成功处理
- $order_info = Db::name('store_order')->where('pay_no',$pay_no)->where('status',1)->find();
- if(empty($order_info)){
- return false;
- }
- // 用户支付成功处理
- $order_info = Db::name('store_order')->field('id,worker_id')->where('pay_no',$pay_no)->find();
- Db::startTrans();
- $res = Db::table('store_order')->where('id',$order_info['id'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>2]);
- $error = 0;
- if(!$res){
- $error = 1;
- Db::rollback();
- }
- $pay_obj = new Pay();
- if($order_info['worker_id']) {
- $rebate_res = $pay_obj->serve_rebate($order_info['id']);
- if (!$rebate_res['code']) {
- $error = 2;
- Db::rollback();
- }
- }
- if($error == 0){
- Db::commit();
- }
- return true; // 返回处理完成
- } else {
- }
- }
- //PC端充值余额支付
- public function balance_notify()
- {
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $pay_no = $result['out_trade_no'];
- // 用户支付成功处理
- $order_info = Db::name('store_balance_order')->where('pay_no',$pay_no)->where('status',0)->find();
- if(empty($order_info)){
- return false;
- }
- // 用户支付成功处理
- $order_info = Db::name('store_balance_order')->where('pay_no',$pay_no)->find();
- Db::startTrans();
- $res = Db::table('store_balance_order')->where('user_id',$order_info['user_id'])->where('pay_no',$order_info['pay_no'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
- $error = 0;
- if(!$res){
- $error = 1;
- Db::rollback();
- }
- $balance_data = array(
- 'amount' => $order_info['price_total'],
- 'user_id' => $order_info['user_id'],
- 'order_id' => $order_info['id'],
- 'status' => 1
- );
- $balance_list = Db::name('store_balance_list')->insert($balance_data);
- if(!$balance_list){
- $error = 2;
- Db::rollback();
- }
- $member_balance = Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance',$order_info['price_total']);
- if(!$member_balance){
- $error = 3;
- Db::rollback();
- }
- $member_balance_all = Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance_all',$order_info['price_total']);
- if(!$member_balance_all){
- $error = 4;
- Db::rollback();
- }
- if($error == 0){
- Db::commit();
- }
- return true; // 返回处理完成
- } else {
- }
- }
- //PC雇主端增加费用
- public function expenses_order_notify()
- {
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $pay_no = $result['out_trade_no'];
- // 用户支付成功处理
- $order_info = Db::name('store_expenses_order')->where('pay_no',$pay_no)->where('status',0)->find();
- if(empty($order_info)){
- return false;
- }
- // 用户支付成功处理
- $order_info = Db::name('store_expenses_order')->field('id,order_id,price_total,reason')->where('pay_no',$pay_no)->find();
- // 用户支付成功处理
- Db::startTrans();
- $expenses_order_res = Db::table('store_expenses_order')->where('id',$order_info['id'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
- $error = 0;
- if(!$expenses_order_res){
- $error = 1;
- Db::rollback();
- }
- $pay_obj = new Pay();
- $rebate_res = $pay_obj->add_serve_rebate($order_info['id']);
- if(!$rebate_res){
- $error = 2;
- Db::rollback();
- }
- $store_order_info = Db::name('store_order')->field('price_total,price_amount')->where('id',$order_info['order_id'])->find();
- $store_order_res = Db::name('store_order')->where('id',$order_info['order_id'])->update(['expenses_time'=>date('Y-m-d H:i:s'),'expenses_pay_type'=>1,'expenses_amount'=>$order_info['price_total'],'expenses_reason'=>$order_info['reason'],'price_total'=>$store_order_info['price_total'] + $order_info['price_total'],'price_amount'=>$store_order_info['price_amount'] + $order_info['price_total']]);
- if(!$store_order_res){
- $error = 3;
- Db::rollback();
- }
- if($error == 0){
- Db::commit();
- }else{
- Db::rollback();
- }
- return true; // 返回处理完成
- } else {
- }
- }
- }
|