OrderController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. namespace hd\controllers;
  3. use biz\sj\services\MerchantAssetService;
  4. use biz\sj\services\MerchantExtendService;
  5. use biz\sj\services\MerchantService;
  6. use bizHd\merchant\services\ShopService;
  7. use bizHd\order\classes\OrderClass;
  8. use bizHd\order\classes\OrderSendClass;
  9. use bizHd\order\services\OrderService;
  10. use bizHd\saas\services\RegionService;
  11. use bizHd\user\services\UserService;
  12. use bizGhs\order\classes\OrderItemClass;
  13. use common\components\dict;
  14. use common\components\dateUtil;
  15. use common\services\xhPayToolService;
  16. use Yii;
  17. use common\components\util;
  18. use common\components\stringUtil;
  19. use bizHd\goods\services\GoodsService;
  20. use bizHd\merchant\services\ExpressService;
  21. use bizHd\order\services\OrderGoodsService;
  22. use bizHd\promote\services\CouponService;
  23. use common\components\httpUtil;
  24. class OrderController extends BaseController
  25. {
  26. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
  27. //商城下单操作 ssh 2019.12.3
  28. public function actionCreateOrder()
  29. {
  30. $post = Yii::$app->request->post();
  31. $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
  32. $orderType = $post['orderType'] ?? 1;
  33. $defaultShopId = MerchantService::getDefaultShopId($this->sj);
  34. if (empty($defaultShopId)) {
  35. util::fail('没有找到门店');
  36. }
  37. $post['merchantId'] = $this->sjId;
  38. $post['shopId'] = $defaultShopId;
  39. $post['payWay'] = $this->isWx == true ? 0 : 1;
  40. $now = time();
  41. $expireTime = $now + 1800;//订单30分钟后过期
  42. $post['deadline'] = $expireTime;
  43. $post['fromType'] = 1;//商城
  44. $customId = $post['customId'] ?? 0;
  45. if (!empty($customId)) {
  46. $customId = $this->customId;
  47. }
  48. $post['customId'] = $customId;
  49. //非门店订单
  50. $store = 0;
  51. $post['store'] = $store;
  52. $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
  53. //$orderType = 1 成品订单
  54. if ($orderType == 1) {
  55. $goodsInfo = $post['goodsInfo'] ?? '';
  56. $goodsInfoArr = json_decode($goodsInfo, true);
  57. if (empty($goodsInfoArr)) {
  58. util::fail('请选择商品');
  59. }
  60. //总的商品金额
  61. $totalGoodsPrice = 0;
  62. $orderGoods = [];
  63. foreach ($goodsInfoArr as $key => $currentGoods) {
  64. $currentGoodsId = $currentGoods['goodsId'];
  65. $currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
  66. if (empty($currentGoodsInfo)) {
  67. util::fail('没有找到商品');
  68. }
  69. $goodsStyleId = $currentGoods['goodsStyleId'];
  70. $goodsNum = $currentGoods['goodsNum'];
  71. //计算总金额
  72. $unitPrice = $currentGoodsInfo['price'];
  73. $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
  74. if (!empty($goodsStyleId)) {
  75. if (empty($goodsStyleList)) {
  76. util::fail('商品款式没有找到');
  77. }
  78. $styleIdList = array_keys($goodsStyleList);
  79. if (in_array($goodsStyleId, $styleIdList) == false) {
  80. util::fail('商品款式没有找到!');
  81. }
  82. $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
  83. }
  84. $goodsPrice = $unitPrice * $goodsNum;
  85. $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
  86. $orderGoods[] = [
  87. 'goodsId' => $currentGoodsId,
  88. 'userId' => $this->adminId,
  89. 'merchantId' => $this->sjId,
  90. 'title' => $currentGoodsInfo['goodsName'],
  91. 'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
  92. 'unitPrice' => $unitPrice,
  93. 'num' => $goodsNum,
  94. 'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
  95. 'goodsStyleId' => $goodsStyleId,
  96. 'createTime' => date("Y-m-d H:i:s"),
  97. ];
  98. }
  99. $user = $this->custom;
  100. $post['bookName'] = isset($user['name']) ? $user['name'] : '';
  101. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  102. $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
  103. $post['bookMobile'] = $bookMobile;
  104. //计算运费
  105. $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
  106. $sendCost = 0;
  107. //按距离计算运费并且客户要求送的
  108. //运费计算方式
  109. $freightType = 0;
  110. if ($freightType == 0 && $needSend == 1) {
  111. //$lat = $post['latitude']??'';//收货人纬度
  112. //$lng = $post['longitude']??'';//收货人经度
  113. //$respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
  114. //$sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
  115. }
  116. //$post['sendCost'] = $sendCost;
  117. $prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
  118. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  119. $sourceType = $this->isWx ? 0 : 1;
  120. if (httpUtil::isMiniProgram()) {
  121. $sourceType = 2;
  122. }
  123. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  124. $actPrice = $discountData['price'];
  125. $post['discountType'] = $discountData['discountType'];
  126. $post['discountAmount'] = $discountData['discountAmount'];
  127. $post['prePrice'] = $prePrice;
  128. $post['actPrice'] = $actPrice;
  129. $order = OrderClass::addOrder($post);
  130. $orderId = $order['id'];
  131. $orderSn = $order['orderSn'];
  132. foreach ($orderGoods as $key => $val) {
  133. $val['orderId'] = $orderId;
  134. $val['orderSn'] = $orderSn;
  135. OrderGoodsService::add($val);//创建订单商品列表
  136. }
  137. } else {
  138. //$orderType = 2 花材订单 组合开单
  139. $productData = $post['product'] ?? '';
  140. $product = json_decode($productData, true);
  141. if (empty($product)) {
  142. util::fail('请选择花材');
  143. }
  144. $actPrice = 0;
  145. $orderProduct = [];
  146. foreach ($product as $key => $val) {
  147. $productId = $val['productId'];
  148. $bigNum = $val['bigNum'];
  149. $smallNum = $val['smallNum'];
  150. $actPrice += 2;
  151. $orderProduct[] = [
  152. 'productId' => $productId,
  153. 'bigNum' => $bigNum,
  154. 'smallNum' => $smallNum,
  155. ];
  156. }
  157. $post['prePrice'] = $actPrice;
  158. $post['actPrice'] = $actPrice;
  159. $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
  160. $order = OrderClass::addOrder($post);
  161. $orderId = $order['id'];
  162. $orderSn = $order['orderSn'];
  163. foreach ($orderProduct as $key => $val) {
  164. $val['orderSn'] = $orderSn;
  165. OrderItemClass::add($val);
  166. }
  167. }
  168. util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
  169. }
  170. //下单要用到的相关信息 ssh 2019.12.6
  171. public function actionOrderRelate()
  172. {
  173. $regionTree = RegionService::tree();
  174. $shop = ShopService::getDefaultShop($this->sj);
  175. $freight = MerchantExtendService::getFreight($this->sjExtend);
  176. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  177. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
  178. util::success($out);
  179. }
  180. //余额支付 ssh 2019.12.6
  181. public function actionBalancePay()
  182. {
  183. $post = Yii::$app->request->post();
  184. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  185. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  186. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  187. //验证优惠券是否还有效
  188. if (!empty($couponId)) {
  189. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  190. }
  191. $order = OrderService::getByOrderSn($orderSn);
  192. $userId = $this->adminId;
  193. $user = UserService::getUserInfo($userId, false);
  194. //验证支付密码是否正确
  195. UserService::validPayPassword($payPassword, $user);
  196. //支付前验证订单有效性
  197. OrderService::checkBeforePay($order, $this->adminId);
  198. $capitalType = dict::getDict('capitalType','xhOrder','id');
  199. $totalFee = $order['prePrice'];
  200. $sourceType = 0;
  201. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  202. $actPrice = $discountData['price'];
  203. $callbackParams = [];
  204. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  205. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  206. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  207. }
  208. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  209. public function actionWxPay()
  210. {
  211. ini_set('date.timezone', 'Asia/Shanghai');
  212. $post = Yii::$app->request->post();
  213. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  214. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  215. $order = OrderService::getByOrderSn($orderSn);
  216. $orderId = $order['id'];
  217. //验证优惠券是否还有效
  218. if (!empty($couponId)) {
  219. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  220. }
  221. //支付前验证订单有效性
  222. OrderService::checkBeforePay($order, $this->adminId);
  223. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  224. $totalFee = $order['actPrice'];
  225. //小程序使用miniOpenId
  226. if (httpUtil::isMiniProgram()) {
  227. $openId = $this->user['miniOpenId'];
  228. } else {
  229. $openId = $this->user['openId'];
  230. }
  231. $capitalType = dict::getDict('capitalType','xhOrder','id');
  232. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  233. $wxPayType = 0;
  234. if (httpUtil::isMiniProgram()) {
  235. $wxPayType = 1;
  236. }
  237. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  238. //订单30分钟后过期
  239. $now = time();
  240. $expireTime = $now + 1800;
  241. $wx = Yii::getAlias("@vendor/weixin");
  242. require_once($wx . '/lib/WxPay.Api.php');
  243. require_once($wx . '/example/WxPay.JsApiPay.php');
  244. $input = new \WxPayUnifiedOrder();
  245. $input->SetBody($name);
  246. $input->SetOut_trade_no($orderSn);
  247. $input->SetTotal_fee($totalFee * 100);
  248. $input->SetTime_start(date("YmdHis", $now));
  249. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  250. $input->SetTime_expire(date("YmdHis", $expireTime));
  251. $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
  252. $input->SetTrade_type("JSAPI");
  253. //花卉宝代为申请的微信支付
  254. $merchantExtend = $this->sjExtend;
  255. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  256. $input->SetSub_openid($openId);
  257. } else {
  258. $input->SetOpenid($openId);
  259. }
  260. //小程序使用miniAppId
  261. if (httpUtil::isMiniProgram()) {
  262. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  263. }
  264. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  265. $tools = new \JsApiPay();
  266. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  267. $newParams = json_decode($jsApiParameters, true);
  268. //已请求微信不能修改价格
  269. $updateData = [];
  270. $updateData['modPrice'] = 0;
  271. if (empty($order['deadline'])) {
  272. $updateData['deadline'] = $expireTime;
  273. }
  274. OrderService::updateById($orderId, $updateData);
  275. util::success($newParams);
  276. }
  277. //快捷付款订单
  278. public function actionFastPay()
  279. {
  280. ini_set('date.timezone', 'Asia/Shanghai');
  281. $post = Yii::$app->request->post();
  282. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  283. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  284. //验证门店是否有效
  285. $shopInfo = ShopService::getById($shopId);
  286. ShopService::valid($shopInfo, $this->sjId);
  287. $post['shopId'] = $shopId;
  288. //默认门店订单
  289. $store = isset($post['store']) ? $post['store'] : 1;
  290. $post['store'] = $store;
  291. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  292. $sourceType = $this->isWx ? 0 : 1;
  293. if (httpUtil::isMiniProgram()) {
  294. $sourceType = 2;
  295. }
  296. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  297. //兼容旧系统sourceType=3表示朋友圈来源
  298. $fromType = $sourceType == 3 ? 2 : 0;
  299. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  300. $post['userId'] = $this->adminId;
  301. $custom = $this->custom;
  302. $post['bookName'] = $custom['userName'] ?? '';
  303. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  304. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  305. $post['bookMobile'] = $bookMobile;
  306. $prePrice = round($post['prePrice'], 2);
  307. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  308. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  309. $actPrice = $discountData['price'];
  310. $post['discountType'] = $discountData['discountType'];
  311. $post['discountAmount'] = $discountData['discountAmount'];
  312. $post['actPrice'] = $actPrice;
  313. $post['payStyle'] = 0;
  314. $post['merchantId'] = $this->sjId;
  315. $now = time();
  316. $expireTime = $now + 300;//订单5分钟后过期
  317. $post['createTime'] = date("Y-m-d H:i:s", $now);
  318. $post['deadline'] = $expireTime;
  319. if ($actPrice <= 0) {
  320. util::fail('请填写正确的金额');
  321. }
  322. //微信支付订单提交不能修改价格
  323. $post['modPrice'] = $this->isWx ? 0 : 1;
  324. $post['sourceType'] = $sourceType;
  325. $post['goodsNum'] = 1;
  326. $post['fromType'] = $fromType;
  327. $order = OrderService::addOrder($post);
  328. $orderId = $order['id'];
  329. $orderSn = $order['orderSn'];
  330. $merchantId = $this->sjId;
  331. if ($payWay == 0) {
  332. $orderId = $order['id'];
  333. $name = '购买商品';
  334. $totalFee = $actPrice;
  335. $user = UserService::getById($this->adminId);
  336. $openId = isset($user['openId']) ? $user['openId'] : 0;
  337. if (httpUtil::isMiniProgram()) {
  338. //小程序使用miniOpenId
  339. $openId = $user['miniOpenId'];
  340. }
  341. if (empty($openId)) {
  342. util::fail('没有找到客户的openId');
  343. }
  344. $capitalType = dict::getDict('capitalType','xhOrder','id');
  345. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  346. $wxPayType = 0;
  347. if (httpUtil::isMiniProgram()) {
  348. $wxPayType = 1;
  349. }
  350. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  351. $wx = Yii::getAlias("@vendor/weixin");
  352. require_once($wx . '/lib/WxPay.Api.php');
  353. require_once($wx . '/example/WxPay.JsApiPay.php');
  354. $input = new \WxPayUnifiedOrder();
  355. $input->SetBody($name);
  356. $input->SetOut_trade_no($orderSn);
  357. $input->SetTotal_fee($totalFee * 100);
  358. $input->SetTime_start(date("YmdHis", $now));
  359. $input->SetAttach($attach);
  360. //设置订单有效期5分钟
  361. $input->SetTime_expire(date("YmdHis", $expireTime));
  362. $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
  363. $input->SetTrade_type("JSAPI");
  364. //花卉宝代为申请的微信支付
  365. $merchantExtend = $this->sjExtend;
  366. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  367. $input->SetSub_openid($openId);
  368. } else {
  369. $input->SetOpenid($openId);
  370. }
  371. //小程序使用miniAppId
  372. if (httpUtil::isMiniProgram()) {
  373. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  374. }
  375. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  376. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  377. $tools = new \JsApiPay();
  378. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  379. $newParams = json_decode($jsApiParameters, true);
  380. $newParams['orderId'] = $orderId;
  381. util::success($newParams);
  382. } elseif ($payWay == 1) {
  383. $extend = MerchantExtendService::getByMerchantId($merchantId);
  384. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  385. util::fail('支付宝付款即将开通...');
  386. }
  387. $config = [
  388. //应用ID,您的APPID。
  389. 'app_id' => $extend['alipayPId'],
  390. //商户私钥,您的原始格式RSA私钥
  391. 'merchant_private_key' => $extend['alipayKey'],
  392. //异步通知地址
  393. 'notify_url' => Yii::$app->params['mallHost'] . "/notice/ali-callback",
  394. //同步跳转
  395. 'return_url' => "",
  396. //编码格式
  397. 'charset' => "UTF-8",
  398. //签名方式
  399. 'sign_type' => "RSA2",
  400. //支付宝网关
  401. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  402. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  403. 'alipay_public_key' => $extend['alipayPublicKey'],
  404. ];
  405. Yii::info(json_encode($config) . ' aplipay config');
  406. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  407. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  408. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  409. $totalFee = $order['actPrice'];
  410. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  411. $subject = '购买商品';//订单名称,必填
  412. $total_amount = $totalFee;//付款金额,必填
  413. $body = '';//商品描述,可空
  414. $timeout_express = "1m";//超时时间
  415. $capitalType = dict::getDict('capitalType','xhOrder','id');
  416. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
  417. $passBackParams = urlencode($passBackParams);
  418. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  419. $payRequestBuilder->setBody($body);
  420. $payRequestBuilder->setSubject($subject);
  421. $payRequestBuilder->setOutTradeNo($out_trade_no);
  422. $payRequestBuilder->setTotalAmount($total_amount);
  423. $payRequestBuilder->setTimeExpress($timeout_express);
  424. //在异步通知时将该参数原样返回
  425. $payRequestBuilder->setPassbackParams($passBackParams);
  426. //同步通知
  427. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  428. //异步通知
  429. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  430. $payResponse = new \AlipayTradeService($config);
  431. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  432. //直接将支付宝的html返回给前端
  433. echo $result;
  434. } elseif ($payWay == 2) {
  435. //余额支付,验证支付密码是否正确
  436. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  437. $user = UserService::getUserInfo($this->adminId, false);
  438. UserService::validPayPassword($payPassword, $user);
  439. $capitalType = dict::getDict('capitalType','xhOrder','id');
  440. $callbackParams = [];
  441. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  442. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  443. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  444. } else {
  445. util::fail('无效的支付方式');
  446. }
  447. }
  448. //订单评价
  449. public function actionComment()
  450. {
  451. $post = Yii::$app->request->post();
  452. $id = $post['id'];
  453. $order = OrderService::getById($id);
  454. OrderService::valid($order, $this->shopId);
  455. if ($order['grade'] > 0) {
  456. util::fail('您已经评过了');
  457. }
  458. OrderService::comment($post);
  459. util::complete('提交成功');
  460. }
  461. //订单详情 ssh 2019.12.16
  462. public function actionDetail()
  463. {
  464. $id = Yii::$app->request->get('id', 0);
  465. $orderSn = Yii::$app->request->get('orderSn', '');
  466. $detail = [];
  467. if (!empty($id)) {
  468. $detail = OrderService::getOrderById($id);
  469. }
  470. if (!empty($orderSn)) {
  471. $detail = OrderService::getOrderBySn($orderSn);
  472. }
  473. OrderService::valid($detail, $this->shopId);
  474. util::success($detail);
  475. }
  476. public function actionList()
  477. {
  478. $get = Yii::$app->request->get();
  479. $search = isset($get['search']) ? $get['search'] : '';
  480. $where = [];
  481. $where['shopId'] = $this->shopId;
  482. if (!empty($get['status'])) {
  483. $where['status'] = $get['status'];
  484. }
  485. if (!empty($search)) {
  486. if (stringUtil::isMobile($search)) {
  487. $where['receiveMobile'] = $search;
  488. } else {
  489. $where['id'] = $search;
  490. }
  491. }
  492. $searchTime = $get['searchTime'] ?? '';
  493. if (!empty($searchTime)) {
  494. $startTime = $get['startTime'] ?? '';
  495. $endTime = $get['endTime'] ?? '';
  496. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  497. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  498. }
  499. $list = OrderService::getOrderList($where);
  500. $list['asset'] = MerchantAssetService::getByMerchantId($this->sjId);
  501. util::success($list);
  502. }
  503. //订单归类 ssh 2019.12.17
  504. public function actionClassify()
  505. {
  506. $post = Yii::$app->request->post();
  507. $id = isset($post['id']) ? $post['id'] : 0;
  508. $order = OrderService::getById($id);
  509. OrderService::valid($order, $this->shopId);
  510. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  511. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  512. OrderService::classify($id, $categoryId, $usageId);
  513. util::complete();
  514. }
  515. //更新配送单 ssh 2019.12.17
  516. public function actionUpdateSheet()
  517. {
  518. $post = Yii::$app->request->post();
  519. $id = isset($post['id']) ? $post['id'] : 0;
  520. unset($post['id']);
  521. $order = OrderService::getById($id);
  522. OrderService::valid($order, $this->shopId);
  523. OrderService::updateSheet($order, $post);
  524. util::complete('提交成功');
  525. }
  526. //商家收款与发货 ssh 2019.12.18
  527. public function actionGathering()
  528. {
  529. $post = Yii::$app->request->post();
  530. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  531. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  532. $userId = isset($post['userId']) ? $post['userId'] : 0;
  533. $userInfo = UserService::getById($userId);
  534. if (empty($userInfo) || $userInfo['merchantId'] != $this->sjId) {
  535. util::fail('您选择的客户无效');
  536. }
  537. if ($price <= 0) {
  538. util::fail('请输入金额');
  539. }
  540. $post['prePrice'] = $price;
  541. $post['actPrice'] = $price;
  542. $post['payWay'] = $payWay;
  543. $post['sourceType'] = 1;
  544. $post['userId'] = $userId;
  545. $post['goodsNum'] = 1;
  546. $post['orderName'] = '商品';
  547. $shopId = MerchantService::getDefaultShopId($this->sj);
  548. $post['shopId'] = $shopId;
  549. $order = OrderService::addOrder($post);
  550. $id = $order['id'];
  551. $orderSn = $order['orderSn'];
  552. //流水类型列表
  553. $capitalType = dict::getDict('capitalType','xhOrder','id');
  554. $callbackParams = [];
  555. switch ($payWay) {
  556. case 0:
  557. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  558. break;
  559. case 1:
  560. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  561. break;
  562. case 2:
  563. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  564. break;
  565. default:
  566. util::fail('无效支付方式');
  567. }
  568. util::success($order);
  569. }
  570. //免发货管理 ssh 2020.1.6
  571. public function actionWithoutSend()
  572. {
  573. $id = Yii::$app->request->get('id');
  574. $order = OrderService::getById($id);
  575. OrderService::valid($order, $this->shopId);
  576. //配送流程变更
  577. $currentFlow = OrderSendClass::withoutSend($order);
  578. util::success(['currentFlow' => $currentFlow]);
  579. }
  580. //修改价格 ssh 2020.1.6
  581. public function actionUpdatePrice()
  582. {
  583. $id = Yii::$app->request->get('id');
  584. $price = Yii::$app->request->get('price', 1);
  585. $order = OrderService::getById($id);
  586. OrderService::valid($order, $this->shopId);
  587. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  588. util::fail('已发起支付,不能修改价格');
  589. }
  590. OrderService::updateById($id, ['actPrice' => $price]);
  591. util::complete('修改成功');
  592. }
  593. //配送单 ssh 2020.2.29
  594. public function actionGetDeliverDetail()
  595. {
  596. $id = Yii::$app->request->get('id', 0);
  597. $order = OrderService::getById($id);
  598. OrderService::valid($order, $this->shopId);
  599. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  600. $reachPeriodId = $order['reachPeriod'];
  601. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  602. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  603. $shopId = $order['shopId'];
  604. $telephone = '';
  605. if (!empty($shopId)) {
  606. $shop = ShopService::getById($shopId);
  607. }
  608. $telephone = isset($shop['telephone']) ? $shop['telephone'] : '';
  609. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  610. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  611. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  612. $bookName = '--';
  613. $bookMobile = '--';
  614. }
  615. $data = [
  616. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  617. 'orderSn' => $order['orderSn'],
  618. 'receiveUserName' => $order['receiveUserName'],
  619. 'receiveMobile' => $order['receiveMobile'],
  620. 'fullAddress' => $order['address'] . $order['floor'] . "(" . $order['fullAddress'] . ")",
  621. 'cardInfo' => $order['cardInfo'],
  622. 'bookMobile' => $bookMobile,
  623. 'bookName' => $bookName,
  624. 'remark' => $order['remark'],
  625. 'sendNum' => $order['sendNum'],
  626. 'telephone' => 13600903070,
  627. 'printTime' => '',
  628. 'img' => '',
  629. ];
  630. util::success($data);
  631. }
  632. //运费计算 linqh 2021.4.12 暂反回固定
  633. public function actionFreight()
  634. {
  635. util::success(['sedCost' => 10]);
  636. }
  637. }