OrderController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. namespace client\controllers;
  3. use biz\goods\services\CategoryService;
  4. use biz\goods\services\GoodsCategoryService;
  5. use biz\goods\services\GoodsService;
  6. use biz\merchant\services\MerchantExtendService;
  7. use biz\merchant\services\MerchantService;
  8. use biz\merchant\services\ShopService;
  9. use biz\order\services\OrderGoodsService;
  10. use biz\order\services\OrderService;
  11. use biz\promote\services\CouponService;
  12. use biz\saas\services\RegionService;
  13. use biz\user\services\UserAssetService;
  14. use biz\user\services\UserService;
  15. use common\components\configDict;
  16. use common\components\httpUtil;
  17. use common\components\stringUtil;
  18. use common\services\xhPayToolService;
  19. use Yii;
  20. use yii\web\Controller;
  21. use common\components\util;
  22. class OrderController extends BaseController
  23. {
  24. public $withoutLogin = ['order-relate', 'fast-pay'];
  25. //商城下单操作 shish 2019.12.3
  26. public function actionCreateOrder()
  27. {
  28. $post = Yii::$app->request->post();
  29. $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
  30. $goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
  31. $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
  32. if (empty($goodsId)) {
  33. util::fail('请选择商品');
  34. }
  35. $goodsInfo = GoodsService::getGoodsInfo($goodsId);
  36. if (empty($goodsInfo)) {
  37. util::fail('没有找到商品');
  38. }
  39. //确认是否要配送的商品
  40. $needSend = isset($goodsInfo['needSend']) && $goodsInfo['needSend'] == 1 ? 1 : 0;
  41. $post['userId'] = $this->userId;
  42. $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
  43. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  44. $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : '';
  45. $post['bookMobile'] = $bookMobile;
  46. $post['payWay'] = $this->isWx == true ? 0 : 1;
  47. $defaultShopId = MerchantService::getDefaultShopId($this->merchant);
  48. if (empty($defaultShopId)) {
  49. util::fail('没有找到门店');
  50. }
  51. $shopInfo = ShopService::getById($defaultShopId);
  52. //计算运费
  53. $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
  54. $sendCost = 0;
  55. if ($needSend == 1) {
  56. $lat = $post['receiveLat'];//收货人纬度
  57. $lng = $post['receiveLong'];//收货人经度
  58. $jsStatDistance = $post['sendDistance'];
  59. $sendCost = ShopService::getSendCost($lat, $lng, $jsStatDistance, $shopInfo);
  60. }
  61. $post['sendCost'] = $sendCost;
  62. $post['merchantId'] = $this->merchantId;
  63. $post['shopId'] = $defaultShopId;
  64. //计算总金额
  65. $unitPrice = $goodsInfo['price'];
  66. $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
  67. if (!empty($goodsStyleId)) {
  68. if (empty($goodsStyleList)) {
  69. util::fail('商品款式没有找到');
  70. }
  71. $styleIdList = array_keys($goodsStyleList);
  72. if (in_array($goodsId, $styleIdList) == false) {
  73. util::fail('商品款式没有找到!');
  74. }
  75. $unitPrice = $goodsStyleList['price'];
  76. }
  77. $goodsPrice = $unitPrice * $goodsNum;
  78. $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
  79. $showPrice = $prePrice;
  80. //非门店订单
  81. $store = 0;
  82. $post['store'] = $store;
  83. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  84. $sourceType = $this->isWx ? 0 : 1;
  85. if (httpUtil::isMiniProgram()) {
  86. $sourceType = 2;
  87. }
  88. $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
  89. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->userId]);
  90. $actPrice = $discountData['price'];
  91. $post['discountType'] = $discountData['discountType'];
  92. $post['discountAmount'] = $discountData['discountAmount'];
  93. $now = time();
  94. $expireTime = $now + 1800;//订单30分钟后过期
  95. $post['deadline'] = $expireTime;
  96. $post['prePrice'] = $prePrice;
  97. $post['actPrice'] = $actPrice;
  98. $order = OrderService::addOrder($post);
  99. $orderId = $order['id'];
  100. $orderSn = $order['orderSn'];
  101. $data = [
  102. 'orderId' => $orderId,
  103. 'goodsId' => $goodsId,
  104. 'userId' => $this->userId,
  105. 'merchantId' => $this->merchantId,
  106. 'title' => $goodsInfo['goodsName'],
  107. 'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
  108. 'unitPrice' => $unitPrice,
  109. 'num' => $goodsNum,
  110. 'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
  111. 'goodsStyleId' => $goodsStyleId,
  112. 'createTime' => date("Y-m-d H:i:s"),
  113. ];
  114. OrderGoodsService::add($data);//创建订单商品列表
  115. util::success(['orderSn' => $orderSn, 'totalPrice' => $showPrice, 'couponId' => $couponId]);
  116. }
  117. //下单要用到的相关信息 shish 2019.12.6
  118. public function actionOrderRelate()
  119. {
  120. $regionTree = RegionService::tree();
  121. $shop = ShopService::getDefaultShop($this->merchant);
  122. $freight = MerchantExtendService::getFreight($this->merchantExtend);
  123. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  124. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->merchant];
  125. util::success($out);
  126. }
  127. //余额支付 shish 2019.12.6
  128. public function actionBalancePay()
  129. {
  130. $post = Yii::$app->request->post();
  131. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  132. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  133. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  134. $order = OrderService::getByOrderSn($orderSn);
  135. $userId = $this->userId;
  136. $user = UserService::getUserInfo($userId, false);
  137. //验证支付密码是否正确
  138. UserService::validPayPassword($payPassword, $user);
  139. //验证订单有效性
  140. OrderService::check($order, $this->userId);
  141. $typeList = configDict::getConfig('capitalType');
  142. $capitalType = $typeList['xhOrder']['id'];
  143. $totalFee = $order['actPrice'];
  144. xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
  145. util::success(['discountAmount' => 9.9, 'discountType' => 0]);
  146. }
  147. //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
  148. public function actionWxPay()
  149. {
  150. ini_set('date.timezone', 'Asia/Shanghai');
  151. $post = Yii::$app->request->post();
  152. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  153. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  154. $order = OrderService::getByOrderSn($orderSn);
  155. $orderId = $order['id'];
  156. //验证订单有效性
  157. OrderService::check($order, $this->userId);
  158. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  159. $totalFee = $order['actPrice'];
  160. //小程序使用miniOpenId
  161. if (httpUtil::isMiniProgram()) {
  162. $openId = $this->user['miniOpenId'];
  163. } else {
  164. $openId = $this->user['openId'];
  165. }
  166. $typeList = configDict::getConfig('capitalType');
  167. $capitalType = $typeList['xhOrder']['id'];
  168. //将流水类型、代金劵传过去
  169. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType;
  170. //订单30分钟后过期
  171. $now = time();
  172. $expireTime = $now + 1800;
  173. $wx = Yii::getAlias("@vendor/weixin");
  174. require_once($wx . '/lib/WxPay.Api.php');
  175. require_once($wx . '/example/WxPay.JsApiPay.php');
  176. $input = new \WxPayUnifiedOrder();
  177. $input->SetBody($name);
  178. $input->SetOut_trade_no($orderSn);
  179. $input->SetTotal_fee($totalFee * 100);
  180. $input->SetTime_start(date("YmdHis", $now));
  181. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  182. $input->SetTime_expire(date("YmdHis", $expireTime));
  183. $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
  184. $input->SetTrade_type("JSAPI");
  185. //花卉宝代为申请的微信支付
  186. $merchantExtend = $this->merchantExtend;
  187. if ($merchantExtend['wxPayApply'] == 1) {
  188. $input->SetSub_openid($openId);
  189. } else {
  190. $input->SetOpenid($openId);
  191. }
  192. //小程序使用miniAppId
  193. if (httpUtil::isMiniProgram()) {
  194. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  195. }
  196. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  197. $tools = new \JsApiPay();
  198. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  199. $newParams = json_decode($jsApiParameters, true);
  200. //已请求微信不能修改价格
  201. $updateData = [];
  202. $updateData['modPrice'] = 0;
  203. if (empty($order['deadline'])) {
  204. $updateData['deadline'] = $expireTime;
  205. }
  206. OrderService::updateById($orderId, $updateData);
  207. util::success($newParams);
  208. }
  209. //快捷付款订单
  210. public function actionFastPay()
  211. {
  212. ini_set('date.timezone', 'Asia/Shanghai');
  213. $post = Yii::$app->request->post();
  214. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  215. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->merchant);
  216. //验证门店是否有效
  217. $shopInfo = ShopService::getById($shopId);
  218. ShopService::valid($shopInfo, $this->merchantId);
  219. //默认门店订单
  220. $store = isset($post['store']) ? $post['store'] : 1;
  221. $post['store'] = $store;
  222. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  223. $sourceType = $this->isWx ? 0 : 1;
  224. if (httpUtil::isMiniProgram()) {
  225. $sourceType = 2;
  226. }
  227. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  228. $post['userId'] = $this->userId;
  229. $user = $this->user;
  230. $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
  231. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  232. $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : '';
  233. $post['bookMobile'] = $bookMobile;
  234. $prePrice = round($post['prePrice'], 2);
  235. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  236. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->userId]);
  237. $actPrice = $discountData['price'];
  238. $post['discountType'] = $discountData['discountType'];
  239. $post['discountAmount'] = $discountData['discountAmount'];
  240. $post['actPrice'] = $actPrice;
  241. $post['payStyle'] = 0;
  242. $post['merchantId'] = $this->merchantId;
  243. $now = time();
  244. $expireTime = $now + 300;//订单5分钟后过期
  245. $post['createTime'] = date("Y-m-d H:i:s", $now);
  246. $post['deadline'] = $expireTime;
  247. if ($actPrice <= 0) {
  248. util::fail('请填写正确的金额');
  249. }
  250. //微信支付订单提交不能修改价格
  251. $post['modPrice'] = $this->isWx ? 0 : 1;
  252. $post['sourceType'] = $sourceType;
  253. $order = OrderService::addOrder($post);
  254. $orderId = $order['id'];
  255. $orderSn = $order['orderSn'];
  256. $merchantId = $this->merchantId;
  257. if ($payWay == 0) {
  258. $orderId = $order['id'];
  259. $name = '购买商品';
  260. $totalFee = $actPrice;
  261. $user = UserService::getById($this->userId);
  262. $openId = isset($user['openId']) ? $user['openId'] : 0;
  263. if (httpUtil::isMiniProgram()) {
  264. //小程序使用miniOpenId
  265. $openId = $user['miniOpenId'];
  266. }
  267. if (empty($openId)) {
  268. util::fail('没有找到客户的openId');
  269. }
  270. $typeList = configDict::getConfig('capitalType');
  271. $capitalType = $typeList['xhOrder']['id'];
  272. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
  273. $wx = Yii::getAlias("@vendor/weixin");
  274. require_once($wx . '/lib/WxPay.Api.php');
  275. require_once($wx . '/example/WxPay.JsApiPay.php');
  276. $input = new \WxPayUnifiedOrder();
  277. $input->SetBody($name);
  278. $input->SetOut_trade_no($orderSn);
  279. $input->SetTotal_fee($totalFee * 100);
  280. $input->SetTime_start(date("YmdHis", $now));
  281. $input->SetAttach($attach);
  282. $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
  283. $input->SetNotify_url(Yii::$app->params['mHost'] . '/notice/wx-callback/');
  284. $input->SetTrade_type("JSAPI");
  285. //花卉宝代为申请的微信支付
  286. $merchantExtend = $this->merchantExtend;
  287. if ($merchantExtend['wxPayApply'] == 1) {
  288. $input->SetSub_openid($openId);
  289. } else {
  290. $input->SetOpenid($openId);
  291. }
  292. //小程序使用miniAppId
  293. if (httpUtil::isMiniProgram()) {
  294. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  295. }
  296. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  297. $tools = new \JsApiPay();
  298. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  299. $newParams = json_decode($jsApiParameters, true);
  300. $newParams['orderId'] = $orderId;
  301. util::success($newParams);
  302. } elseif ($payWay == 1) {
  303. if ($merchantId == 12358) {
  304. $config = array(
  305. //应用ID,您的APPID。
  306. 'app_id' => "2019041663930158",
  307. //商户私钥,您的原始格式RSA私钥
  308. 'merchant_private_key' => "MIIEpAIBAAKCAQEA0NGNBMu5BkHU+ztmGhGdsJC1n2ZbXn4uoaYNni2eriPHJHG8vCWL1vv3W+gxX3twnmdQ57s3hFWfd5PIwMm+8QIwiPucckbmTEm2rC2g4j+UnUiXzICJWjlzlCWiBftrsctKKwjsZTPiuDJzUKmYRD4DYWy1+4Uh6k6x98qbALuiFFrh7esvsaSepZfQ+zBLzMVfrtPABkwEtOAzUL4hz4YW+EFfqyj3mu4LP4M+zBWSKRs0iCzJILG/7JA4OEkDJ89gGZ6LiaITUgffV2tg/IS81aNBfutb3tICBr1PLlKYCV0ois54kqmmP7anNrn/KRFI/k6iLd82e1HEoHhvDwIDAQABAoIBAQCr+PgPTAv8CDl0Ek4bCAj7AaJiPTTgVEDpJc0vSNjXB2YZMIZD2RQaoHXtvgLzZMCx49pwjfHBzZZAL3h0tXHIIIqCNd15C8TcbRTBJe7KhZxKEB/b7ruvj4MNLhUKoi3mRcq2OGofSqTcF8h6VMGu6fd0w8f39YOh6N+Od9BBv8aL7CtBwQQihzatBdr2CyjH50TmlVWfEz2YKoZBGRuMy7EzLZgmR5IzEJC36tOBAg5DORNkEMAuzvnmBQznZCtzMZHW5Ytlh/3kbCUMsrWL6ioox/mel4DoQNnQ1kZ60f7Gny3I+0HiJ+vxVBZ3Nyd8FCVbAlq6avkB3ZGoCx0xAoGBAP/Mhf8X81mLK80TQsSWYPmnjnYkOZ7vIpNc/b6/N+BKAAjWB+0wXJ73nhuzB8cuJBz6TK8RE2uUuiUbiVP1jkrQ2EoCWadndKE1fcLFSSOYlN9rxfINcLicdNAFYu0m8He5cqPpW+06sD8HGOlWeBOyPvitXBjBeOB9dPWBpVkpAoGBAND7kruod1T4ErtOavYv4ErlyN0O6PpQR3MBlnzXnJfKLdaMvc/JaqjZtk14Nl9RnBDzN6d93LHxariyuTHw9mdGAPOpxcUEsUdOw56eRIzhyY8lz0c+lvE32r2NypuzK/2BGP5xR+spe7D4esuhLQhUYjByTWbgLQD+7724QrV3AoGAYuO2ib/AnEVpUYa4sTdRljJoqNOoUwEv5Lh2gF98QoFZMhFMTy37IJmpzhuQTjhQTcOWEbgQQe7lZ6MVnBe6QsIqW7I85rLgK9J6I+oRNGmwZA9OHx2DDlut7R2n+Pas0BwpbaSxnSyrJjKgNtTu5u5p2clraUaibGcT6DWOrsECgYEAspjM5aMrmGoJWBnEP3Da9ic6afD8Gi/RX+/TdA2vvekDE4BkFtfDV1n3+mzpyrwr7DBvN6zQlyICWqYirxOHAOtKlPJaGe3Qs2gUtdH8M4oifzuI0RIkXTGmtqgepsGQrq1NduXI2KgzFSLFjpDHs36qC00j6O9chqVYrYJzQDECgYBQyIWx3BBEUgWCbLTT8QeUdf+EnZSLZzIIQFn88zImhqkTSMbpBmcZpI4oOlWiM8i4XOaEzu+EDFIRAchIbVlDgBV1OprAN5BAez03oyh1JkCDYrsEj7FMqWSmbxiY2uubPshMLEGdPU+I46oJTO6FzMyG6hnQrK+/ne0zH8A5LA==",
  309. //异步通知地址
  310. 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
  311. //同步跳转
  312. 'return_url' => "",
  313. //编码格式
  314. 'charset' => "UTF-8",
  315. //签名方式
  316. 'sign_type' => "RSA2",
  317. //支付宝网关
  318. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  319. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  320. 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkFYqNkoWJIx37fGcUBbnZJ+APf14YHO1cBdp9RFSasxj9gm+pwbtK3J6uRuPygK0K/OCgvtuFJ6mZT3tNUEgSZMjnre5Z7IzQnzIBUYFPUEO85s+/RDr5HnAqgOIbu9GL8GWrU6g6uj+QmW591vXckmsbujPx0S3IP+TMOQZWA0JVvDu+T9yGfv3pacKUgdNvYnas/si3278TL4DeIVjZ4OmbbEPmEhD/OhSVlTSWEOdqLuV4DvEpmrGa8XoyfFEtgV9qSVb454Qwu5Nw/ATc9+ssMbN6ROXzOQbAAfqAe6riNUtKEHGVaCynfUAYNyR6yvJb8+VkMR02nBEDC9QHQIDAQAB",
  321. );
  322. } else {
  323. $config = array(
  324. //应用ID,您的APPID。
  325. 'app_id' => "2017041906821571",
  326. //商户私钥,您的原始格式RSA私钥
  327. 'merchant_private_key' => "MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFXBrmdKjAcRJ8Q7ZHUmzIqAV+IMV+RD4J5mZHeJgdAECgYEA8J+Hp1M6eYbT4CPLXa//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA4NRPxmXvIjjmLb1Ft1qwHuyv3vvWhi50foGZXNEnBcfP/OkfyBDDpOEu34GZBMXK9ykHBs1l93OEFGXh7AwW0Lp5lARahBEfBZgPjq5yPO8TOJZrb5hVcuvoDdGjxpRh93XDnQDhWS/1IvUcBLcIsTcnVvfrkX4NLxF/W0CgYEAxamG+gD4rBQBwMImsRN+/2MV7M//iEUG+0qPeXeI/7rv9wUP3etMlwl48qSKNxj37xxN2ksa/Acxu/VZhu6XqKO3VUX+IWFQdaNGh2F13iLozIDLQOtKw3WfcjOq0xpZ5pwXq0RI8iSw+IUhyD8EHNZW2qU8CiRBhyt6hsywqQECgYBa8+06FAachI/XqWfF/UvcDdJ5AkS9/L8SvmmdsSkItjSIkfLHAqdxkbwl6Vu6kUOX/PJIFZjuAWTZFl4xBFNgFYj01uZHnnT6cnIp6HteD2CAqTSFAMqgfFWoL6zoaYAmJBnxO4oZPTYI+ilnQcts5VLFaChx0GCvS2BZgy2W0QKBgQDjP2VtRq4aVSLUq2z1KIDI7GJBbOM5KSW1OEj4sfEdViozPh3Ar/FQWiij1oCZF+iJdKkonHoDbDd+Q0ykcpQ+5Gv07iiT8wJYFR/0j8g2kfql7bVQhGSBeBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==",
  328. //异步通知地址
  329. 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
  330. //同步跳转
  331. 'return_url' => "",
  332. //编码格式
  333. 'charset' => "UTF-8",
  334. //签名方式
  335. 'sign_type' => "RSA2",
  336. //支付宝网关
  337. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  338. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  339. 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB",
  340. );
  341. }
  342. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  343. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  344. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  345. $totalFee = $order['actPrice'];
  346. $out_trade_no = $orderId;//商户订单号,商户网站订单系统中唯一订单号,必填
  347. $subject = '购买商品';//订单名称,必填
  348. $total_amount = $totalFee;//付款金额,必填
  349. $body = '';//商品描述,可空
  350. $timeout_express = "1m";//超时时间
  351. $typeList = configDict::getConfig('capitalType');
  352. $capitalType = $typeList['xhOrder']['id'];
  353. $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
  354. $passbackParams = urlencode($passbackParams);
  355. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  356. $payRequestBuilder->setBody($body);
  357. $payRequestBuilder->setSubject($subject);
  358. $payRequestBuilder->setOutTradeNo($out_trade_no);
  359. $payRequestBuilder->setTotalAmount($total_amount);
  360. $payRequestBuilder->setTimeExpress($timeout_express);
  361. //在异步通知时将该参数原样返回
  362. $payRequestBuilder->setPassbackParams($passbackParams);
  363. //同步通知
  364. $returnUrl = Yii::$app->params['frontUrl'] . "/notice/pay-alipay-sync";
  365. //异步通知
  366. $notifyUrl = Yii::$app->params['frontUrl'] . "/notice/alipay-async";
  367. $payResponse = new \AlipayTradeService($config);
  368. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  369. //直接将支付宝的html返回给前端
  370. echo $result;
  371. } elseif ($payWay == 2) {
  372. //验证支付密码是否正确
  373. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  374. $user = UserService::getUserInfo($this->userId, false);
  375. UserService::validPayPassword($payPassword, $user);
  376. $typeList = configDict::getConfig('capitalType');
  377. $capitalType = $typeList['xhOrder']['id'];
  378. $totalFee = $order['actPrice'];
  379. xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
  380. util::success(['discountAmount' => 9.9, 'discountType' => 0]);
  381. } else {
  382. util::fail('无效的支付方式');
  383. }
  384. }
  385. //订单列表 shish 2019.12.12
  386. public function actionList()
  387. {
  388. $where = ['userId' => $this->userId];
  389. $list = OrderService::getOrderList($where);
  390. util::success($list);
  391. }
  392. //订单评价
  393. public function actionComment()
  394. {
  395. $post = Yii::$app->request->post();
  396. $id = $post['id'];
  397. $order = OrderService::getById($id);
  398. if ($this->userId != $order['userId']) {
  399. util::fail('您没有权限操作');
  400. }
  401. OrderService::comment($post);
  402. util::complete('提交成功');
  403. }
  404. //订单详情 shish 2019.12.16
  405. public function actionDetail()
  406. {
  407. $id = Yii::$app->request->get('id', 0);
  408. $orderSn = Yii::$app->request->get('orderSn', '');
  409. $detail = [];
  410. if (!empty($id)) {
  411. $detail = OrderService::getOrderById($id);
  412. }
  413. if (!empty($orderSn)) {
  414. $detail = OrderService::getOrderBySn($orderSn);
  415. }
  416. OrderService::valid($detail, $this->merchantId);
  417. util::success($detail);
  418. }
  419. }