OrderController.php 20 KB

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