OrderController.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use biz\sj\services\MerchantService;
  6. use bizHd\custom\classes\CustomClass;
  7. use bizHd\custom\classes\HdClass;
  8. use bizHd\goods\classes\GoodsClass;
  9. use bizHd\merchant\services\ShopService;
  10. use bizHd\order\classes\OrderClass;
  11. use bizHd\order\classes\OrderItemClass;
  12. use bizHd\order\classes\OrderSendClass;
  13. use bizHd\order\services\OrderService;
  14. use bizHd\product\classes\ProductClass;
  15. use bizHd\purchase\classes\PurchaseClass;
  16. use bizHd\saas\services\RegionService;
  17. use bizHd\shop\classes\ShopClass;
  18. use bizHd\user\services\UserService;
  19. use bizHd\work\classes\WorkClass;
  20. use bizHd\wx\classes\WxOpenClass;
  21. use common\components\dict;
  22. use common\components\dateUtil;
  23. use common\components\noticeUtil;
  24. use common\components\orderSn;
  25. use common\components\payUtil;
  26. use common\services\xhPayToolService;
  27. use Yii;
  28. use common\components\util;
  29. use common\components\stringUtil;
  30. use bizHd\promote\services\CouponService;
  31. use common\components\httpUtil;
  32. use biz\wx\classes\WxMessageClass;
  33. use common\components\lakala\Lakala;
  34. class OrderController extends BaseController
  35. {
  36. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
  37. public function actionDebt()
  38. {
  39. $get = Yii::$app->request->get();
  40. $id = $get['id'] ?? 0;
  41. $info = OrderClass::getById($id, true);
  42. if (empty($info)) {
  43. util::fail('没有找到订单');
  44. }
  45. if ($info->mainId != $this->mainId) {
  46. util::fail('不是你的订单');
  47. }
  48. //4秒内不允许重复提交
  49. $cacheKey = 'ls_set_order_debt_' . $id;
  50. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  51. if (!empty($has)) {
  52. util::fail('请稍等');
  53. }
  54. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  55. if ($info->status != 1) {
  56. util::fail('订单已付款或取消');
  57. }
  58. $payWay = dict::getDict('payWay', 'debtPay');
  59. $connection = Yii::$app->db;
  60. $transaction = $connection->beginTransaction();
  61. try {
  62. $actPrice = $info->actPrice ?? 0;
  63. $info->debtPrice = $actPrice;
  64. $info->remainDebtPrice = $actPrice;
  65. $info->debt = 1;
  66. $info->save();
  67. OrderClass::payAfter($info, $payWay);
  68. $transaction->commit();
  69. util::complete('赊账成功');
  70. } catch (\Exception $exception) {
  71. $transaction->rollBack();
  72. Yii::info("赊账失败原因:" . $exception->getMessage());
  73. util::fail('操作失败');
  74. }
  75. }
  76. //取消订单 ssh 20221231
  77. public function actionCancel()
  78. {
  79. //避免重复提交
  80. $adminId = $this->adminId;
  81. util::checkRepeatCommit($adminId, 8);
  82. $get = Yii::$app->request->get();
  83. $id = $get['id'] ?? 0;
  84. $order = OrderClass::getById($id, true);
  85. OrderClass::valid($order, $this->mainId);
  86. $deadTime = $order->deadline ?? 0;
  87. $current = time();
  88. $diff = bcsub($deadTime, $current);
  89. if ($diff < 60) {
  90. util::fail('60秒后将自动取消');
  91. }
  92. $connection = Yii::$app->db;
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. OrderClass::setExpire($order, true);
  96. $transaction->commit();
  97. util::complete();
  98. } catch (\Exception $exception) {
  99. $transaction->rollBack();
  100. Yii::info("取消原因:" . $exception->getMessage());
  101. util::fail('取消失败');
  102. }
  103. }
  104. //修改订单 ssh 20220926
  105. public function actionUpdate()
  106. {
  107. $post = Yii::$app->request->post();
  108. $id = $post['id'] ?? 0;
  109. $order = OrderClass::getById($id, true);
  110. OrderClass::valid($order, $this->mainId);
  111. unset($post['id']);
  112. if ($order->status == 3) {
  113. util::fail('订单已配送');
  114. }
  115. if ($order->status == 4) {
  116. util::fail('订单已完成');
  117. }
  118. if ($order->status == 5) {
  119. util::fail('订单已取消');
  120. }
  121. if ($order->fromType == 4) {
  122. util::fail('请在美团APP上修改');
  123. }
  124. $address = $post['address'] ?? '';
  125. $floor = $post['floor'] ?? '';
  126. $post['fullAddress'] = $address . $floor;
  127. OrderClass::updateById($id, $post);
  128. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  129. $remark = $post['remark'] ?? '';
  130. $reachDate = $post['reachDate'] ?? '';
  131. $reachPeriod = $post['reachPeriod'] ?? '';
  132. $cardInfo = $post['cardInfo'] ?? '';
  133. $anonymity = $post['anonymity'] ?? 0;
  134. $bookName = $post['bookName'] ?? '';
  135. if (!empty($workList)) {
  136. foreach ($workList as $work) {
  137. $work->remark = $remark;
  138. $work->reachDate = $reachDate;
  139. $work->reachPeriod = $reachPeriod;
  140. $work->cardInfo = $cardInfo;
  141. $work->anonymity = $anonymity;
  142. $work->bookName = $bookName;
  143. $work->save();
  144. }
  145. }
  146. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  147. ShopExtClass::orderUpdateRemind($shopExt, $order);
  148. util::complete();
  149. }
  150. //客户欠款的订单 ssh 2021.2.4
  151. public function actionDebtList()
  152. {
  153. $get = Yii::$app->request->get();
  154. $id = $get['id'] ?? 0;
  155. $info = CustomClass::getById($id, true);
  156. CustomClass::valid($info, $this->shopId);
  157. $where = ['customId' => $id, 'debt' => 1];
  158. $searchTime = $get['searchTime'] ?? '';
  159. if (!empty($searchTime)) {
  160. $startTime = $get['startTime'] ?? '';
  161. $endTime = $get['endTime'] ?? '';
  162. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  163. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  164. }
  165. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice']);
  166. if (!empty($list)) {
  167. foreach ($list as $key => $value) {
  168. $debtPrice = $value['debtPrice'] ?? 0;
  169. $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
  170. $hasPayDebt = 0;
  171. if ($debtPrice > $remainDebtPrice) {
  172. $hasPayDebt = bcsub($debtPrice, $remainDebtPrice, 2);
  173. }
  174. $list[$key]['hasPayAmount'] = floatval($hasPayDebt);
  175. }
  176. }
  177. $result = ['customInfo' => $info, 'list' => $list];
  178. util::success($result);
  179. }
  180. //发货
  181. public function actionSend()
  182. {
  183. $get = Yii::$app->request->get();
  184. $id = isset($get['id']) ? $get['id'] : 0;
  185. $order = OrderClass::getById($id, true);
  186. if (empty($order)) {
  187. util::fail('没有找到订单');
  188. }
  189. OrderClass::valid($order, $this->mainId);
  190. if ($order->status != 2) {
  191. util::fail('订单不是待发货状态');
  192. }
  193. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  194. if (!empty($workList)) {
  195. $unComplete = false;
  196. foreach ($workList as $work) {
  197. if ($work->status != 1) {
  198. $unComplete = true;
  199. }
  200. }
  201. if ($unComplete == true) {
  202. util::fail('还有制作单没有完成');
  203. }
  204. }
  205. $order->status = 4;
  206. $order->save();
  207. util::complete('操作成功');
  208. }
  209. //打印订单 ssh 20220601
  210. public function actionPrintOrder()
  211. {
  212. $get = Yii::$app->request->get();
  213. $id = isset($get['id']) ? $get['id'] : 0;
  214. $order = OrderClass::getById($id, true);
  215. if (empty($order)) {
  216. util::fail('没有找到订单');
  217. }
  218. OrderClass::valid($order, $this->mainId);
  219. OrderClass::onlinePrint($order, true);
  220. util::complete();
  221. }
  222. //微信和支付宝付款码支付复查 ssh 20220422
  223. public function actionCodePayCheck()
  224. {
  225. ini_set('date.timezone', 'Asia/Shanghai');
  226. header("Content-type: text/html; charset=utf-8");
  227. $get = Yii::$app->request->get();
  228. $id = isset($get['id']) ? $get['id'] : 0;
  229. $order = OrderClass::getById($id, true);
  230. OrderClass::valid($order, $this->mainId);
  231. $orderSn = $order->orderSn ?? '';
  232. $totalFee = $order->mainPay ?? 0;
  233. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  234. util::success(['returnStatus' => 'SUCCESS']);
  235. }
  236. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  237. util::complete('订单不是待付款状态');
  238. }
  239. $connection = Yii::$app->db;
  240. $transaction = $connection->beginTransaction();
  241. try {
  242. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  243. $shop = $this->shop;
  244. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  245. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  246. $params = [
  247. 'appid' => 'OP00002119',
  248. 'serial_no' => '018b08cfddbd',
  249. 'merchant_no' => $shop->lklSjNo,
  250. 'term_no' => $shop->lklScanTermNo,
  251. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  252. 'lklCertificatePath' => $lklCertificatePath,
  253. ];
  254. $laResource = new Lakala($params);
  255. $scanParams = ['orderSn' => $orderSn,];
  256. $response = $laResource->query($scanParams);
  257. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  258. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  259. $payWayType = dict::getDict('payWay', 'wxPay');
  260. $account_type = $response['resp_data']['account_type'] ?? '';
  261. if ($account_type == 'WECHAT') {
  262. $payWayType = dict::getDict('payWay', 'wxPay');
  263. }
  264. if ($account_type == 'ALIPAY') {
  265. $payWayType = dict::getDict('payWay', 'alipay');
  266. }
  267. $transactionId = $response['resp_data']['trade_no'] ?? '';
  268. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  269. $order->save();
  270. $attach = '';
  271. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  272. $transaction->commit();
  273. //打印小票和语音播报
  274. $newOrder = OrderClass::getById($id, true);
  275. OrderClass::onlinePrint($newOrder);
  276. ShopExtClass::hdGatheringReport($newOrder);
  277. $shopId = $newOrder->shopId ?? 0;
  278. $shop = ShopClass::getById($shopId, true);
  279. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  280. util::success(['returnStatus' => 'SUCCESS']);
  281. } else {
  282. util::complete('未知状态..');
  283. }
  284. }
  285. util::complete('未知状态..');
  286. } catch (\Exception $e) {
  287. $transaction->rollBack();
  288. util::complete('支付失败');
  289. }
  290. }
  291. //微信和支付宝付款码支付 ssh 2021.4.11
  292. public function actionCodePay()
  293. {
  294. ini_set('date.timezone', 'Asia/Shanghai');
  295. header("Content-type: text/html; charset=utf-8");
  296. $get = Yii::$app->request->get();
  297. $id = isset($get['id']) ? $get['id'] : 0;
  298. $version = $get['version'] ?? 0;
  299. $order = OrderClass::getById($id, true);
  300. OrderClass::valid($order, $this->mainId);
  301. $shop = $this->shop;
  302. $sj = $shop->merchantName;
  303. $shopName = $shop->shopName;
  304. $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
  305. $authCode = (string)$get['authCode'] ?? '';
  306. if ($version > 0) {
  307. if (empty($authCode)) {
  308. $msg = '没有扫到付款码';
  309. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  310. noticeUtil::push($remind . ' 编号005', '15280215347');
  311. util::success(['returnStatus' => 'FAILURE'], $msg);
  312. }
  313. //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
  314. $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
  315. //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
  316. $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
  317. if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
  318. $msg = '付款码错误,请使用微信或支付宝付款码';
  319. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  320. //noticeUtil::push($remind . ' 编号009', '15280215347');
  321. util::success(['returnStatus' => 'FAILURE'], $msg);
  322. }
  323. } else {
  324. if (empty($authCode)) {
  325. util::fail('没有获取到支付码');
  326. }
  327. }
  328. $orderSn = $order->orderSn ?? '';
  329. $lsCodePayErrorKey = 'ls_code_pay_error_' . $id;
  330. $hasFailPay = Yii::$app->redis->executeCommand('GET', [$lsCodePayErrorKey]);
  331. //前面有付失败过,要重新生成单号
  332. if (!empty($hasFailPay)) {
  333. $oldOrderSn = $order->orderSn;
  334. $orderSn = orderSn::getOrderSn();
  335. $order->orderSn = $orderSn;
  336. $order->save();
  337. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  338. }
  339. $subject = '购买花材 ' . $orderSn;
  340. $totalFee = $order->mainPay ?? 0;
  341. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  342. $connection = Yii::$app->db;
  343. $transaction = $connection->beginTransaction();
  344. try {
  345. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  346. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  347. $params = [
  348. 'appid' => 'OP00002119',
  349. 'serial_no' => '018b08cfddbd',
  350. 'merchant_no' => $shop->lklSjNo,
  351. 'term_no' => $shop->lklScanTermNo,
  352. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  353. 'lklCertificatePath' => $lklCertificatePath,
  354. ];
  355. $laResource = new Lakala($params);
  356. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  357. $scanParams = [
  358. 'orderSn' => $orderSn,
  359. 'amount' => $totalFee,
  360. 'capitalType' => $capitalType,
  361. 'notifyUrl' => $notifyUrl,
  362. 'subject' => $subject,
  363. 'authCode' => $authCode,
  364. ];
  365. $response = $laResource->scanPay($scanParams);
  366. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  367. $account_type = $response['resp_data']['account_type'] ?? '';
  368. $payWayType = dict::getDict('payWay', 'wxPay');
  369. if ($account_type == 'WECHAT') {
  370. $payWayType = dict::getDict('payWay', 'wxPay');
  371. }
  372. if ($account_type == 'ALIPAY') {
  373. $payWayType = dict::getDict('payWay', 'alipay');
  374. }
  375. $order->payWay = $payWayType;
  376. $transactionId = $response['resp_data']['trade_no'] ?? '';
  377. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  378. $order->save();
  379. $attach = '';
  380. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  381. $transaction->commit();
  382. //解决重复通知
  383. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  384. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  385. if (empty($has)) {
  386. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  387. $newOrder = OrderClass::getById($id, true);
  388. //打印小票
  389. OrderClass::onlinePrint($newOrder);
  390. //语音播报
  391. ShopExtClass::hdGatheringReport($newOrder);
  392. $shopId = $newOrder->shopId ?? 0;
  393. $shop = ShopClass::getById($shopId, true);
  394. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  395. }
  396. util::success(['returnStatus' => 'SUCCESS']);
  397. } else {
  398. //标记有没付成功的次数,原因有可能是余额不足等
  399. Yii::$app->redis->executeCommand('SETEX', [$lsCodePayErrorKey, 1200, 'hasFail']);
  400. $msg = $response['msg'] ?? '';
  401. $retCode = $response['code'] ?? '';
  402. $fullMsg = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  403. if ($retCode == 'BBS10000' || $retCode == 'BBS11105') {
  404. $shopId = $order->shopId;
  405. ShopExtClass::remindInputPassword($shopId);
  406. }
  407. //noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号008', '15280215347');
  408. util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
  409. }
  410. } catch (\Exception $e) {
  411. $transaction->rollBack();
  412. util::fail('支付失败');
  413. }
  414. }
  415. //开单操作 ssh 20220316
  416. public function actionCreateOrder()
  417. {
  418. $post = Yii::$app->request->post();
  419. $post['sjId'] = $this->sjId;
  420. $post['shopId'] = $this->shopId;
  421. $post['mainId'] = $this->mainId ?? 0;
  422. $now = time();
  423. $orderValidTime = getenv('ORDER_VALID_TIME') == false ? 600 : getenv('ORDER_VALID_TIME');
  424. $expireTime = $now + $orderValidTime;
  425. $post['deadline'] = $expireTime;
  426. $post['staffId'] = $this->shopAdminId ?? 0;
  427. $post['staffName'] = $this->shopAdmin->name ?? '';
  428. $post['flowerNum'] = isset($post['flowerNum']) && $post['flowerNum'] > 0 ? $post['flowerNum'] : 0;
  429. //默认情况开单员工和收款员工是同个人
  430. $staffId = $this->shopAdminId ?? 0;
  431. $staffName = $this->shopAdmin->name ?? '';
  432. if (empty($post['shopAdminId'])) {
  433. $post['shopAdminId'] = $staffId;
  434. $post['shopAdminName'] = $staffName;
  435. }
  436. if (empty($post['getStaffId'])) {
  437. $post['getStaffId'] = $staffId;
  438. $post['getStaffName'] = $this->shopAdmin->name ?? '';
  439. }
  440. $groupId = !empty($post['groupId']) ? $post['groupId'] : 0;
  441. $post['fromType'] = $post['fromType'] ?? 1;
  442. if ($post['fromType'] == dict::getDict('fromType', 'friend')) {
  443. if (empty($post['bookName'])) {
  444. util::fail('请填写订花人姓名');
  445. }
  446. }
  447. $customId = $post['customId'] ?? 0;
  448. $custom = CustomClass::getById($customId, true);
  449. if (empty($custom)) {
  450. util::fail('没有找到客户哦');
  451. }
  452. $hdId = $custom->hdId ?? 0;
  453. $hd = HdClass::getById($hdId, true);
  454. if (empty($hd)) {
  455. util::fail('客户对应的花店信息缺失,编号869');
  456. }
  457. $hdName = $hd->name ?? '';
  458. $post['hdId'] = $hdId;
  459. $post['hdName'] = $hdName;
  460. $post['customId'] = $customId;
  461. $customName = $custom->name ?? '';
  462. $post['customName'] = $customName;
  463. $post['customNamePy'] = stringUtil::py($customName);
  464. if (!empty($post['receiveMobile'])) {
  465. if (!stringUtil::isMobile($post['receiveMobile'])) {
  466. util::fail('请填写正确的收花人手机号');
  467. }
  468. }
  469. if (!empty($post['bookMobile'])) {
  470. if (!stringUtil::isMobile($post['bookMobile'])) {
  471. util::fail('请填写正确的订花人手机号');
  472. }
  473. }
  474. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  475. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  476. //收银台开单默认到店自取
  477. $post['sendType'] = dict::getDict('sendType', 'shopGet');
  478. }
  479. $productJson = $post['product'] ?? '';
  480. $productList = [];
  481. if (!empty($productJson)) {
  482. $productList = json_decode($productJson, true);
  483. }
  484. if (empty($productList) && empty($groupId)) {
  485. //商家手机上开单并生成制作单
  486. if (!empty($post['unitGoodsPrice'])) {
  487. $unitGoodsPrice = $post['unitGoodsPrice'];
  488. if (!is_numeric($unitGoodsPrice)) {
  489. util::fail('请输入正确的单价');
  490. }
  491. $productList = GoodsClass::orderCreateGoods($post);
  492. }
  493. }
  494. if (empty($productList) && empty($groupId)) {
  495. if ($post['lsGoodsPrice'] <= 0) {
  496. $lsGoodsPrice = $post['lsGoodsPrice'];
  497. if (!is_numeric($lsGoodsPrice)) {
  498. util::fail('请输入正确的金额');
  499. }
  500. util::fail('请填写金额或选商品');
  501. }
  502. }
  503. $connection = Yii::$app->db;
  504. $transaction = $connection->beginTransaction();
  505. try {
  506. $post['product'] = $productList;
  507. //阿东开5支老是会出现5扎情况跟踪
  508. ProductClass::adStockCheck($this->shop, $productList);
  509. //3秒内不允许重复开单
  510. $staffId = $this->shopAdminId ?? 0;
  511. $cacheKey = 'hd_create_order_' . $staffId . '_' . $customId;
  512. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  513. if (!empty($has)) {
  514. util::fail('稍等5秒再开单');
  515. }
  516. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 3, 'has']);
  517. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  518. $transaction->commit();
  519. //打印小票和语音播报
  520. $id = $return->id ?? 0;
  521. $order = OrderClass::getById($id, true);
  522. if ($order->fromType == 3 || $order->fromType == 4) {
  523. //除了客服号下单和美团下单,其它情况允许打小票
  524. } else {
  525. //前台打小票
  526. OrderClass::onlinePrint($order);
  527. }
  528. //前台提示收款多少钱
  529. ShopExtClass::hdGatheringReport($order);
  530. //前台提醒出示付款码
  531. if (isset($order->status) && $order->status == 1) {
  532. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  533. ShopExtClass::pleasePayReport($order);
  534. }
  535. }
  536. $shopId = $order->shopId ?? 0;
  537. $shop = ShopClass::getById($shopId, true);
  538. WxMessageClass::gatheringIncomeInform($shop, $order);
  539. //新制作单提示
  540. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  541. ShopExtClass::newWorkRemind($shopExt, $order);
  542. util::success($return);
  543. } catch (\Exception $e) {
  544. $transaction->rollBack();
  545. Yii::error("失败原因:" . $e->getMessage());
  546. util::fail('下单失败');
  547. }
  548. }
  549. //下单要用到的相关信息 ssh 2019.12.6
  550. public function actionOrderRelate()
  551. {
  552. $regionTree = RegionService::tree();
  553. $shop = $this->shop->attributes;
  554. $freight = MerchantExtendService::getFreight($this->sjExtend);
  555. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  556. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  557. util::success($out);
  558. }
  559. //余额支付 ssh 2019.12.6
  560. public function actionBalancePay()
  561. {
  562. $post = Yii::$app->request->post();
  563. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  564. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  565. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  566. $order = OrderService::getByOrderSn($orderSn);
  567. $userId = $this->adminId;
  568. $user = UserService::getUserInfo($userId);
  569. //验证支付密码是否正确
  570. UserService::validPayPassword($payPassword, $user);
  571. //支付前验证订单有效性
  572. OrderService::checkBeforePay($order);
  573. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  574. $totalFee = $order['prePrice'];
  575. $sourceType = 0;
  576. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  577. $actPrice = $discountData['price'];
  578. $callbackParams = [];
  579. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  580. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  581. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  582. }
  583. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  584. public function actionWxPay()
  585. {
  586. ini_set('date.timezone', 'Asia/Shanghai');
  587. $post = Yii::$app->request->post();
  588. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  589. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  590. $order = OrderService::getByOrderSn($orderSn);
  591. $orderId = $order['id'];
  592. //验证优惠券是否还有效
  593. if (!empty($couponId)) {
  594. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  595. }
  596. //支付前验证订单有效性
  597. OrderService::checkBeforePay($order);
  598. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  599. $totalFee = $order['realPrice'];
  600. //小程序使用miniOpenId
  601. if (httpUtil::isMiniProgram()) {
  602. $openId = $this->user['miniOpenId'];
  603. } else {
  604. $openId = $this->user['openId'];
  605. }
  606. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  607. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  608. $wxPayType = 0;
  609. if (httpUtil::isMiniProgram()) {
  610. $wxPayType = 1;
  611. }
  612. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  613. //订单30分钟后过期
  614. $now = time();
  615. $expireTime = $now + 1800;
  616. $wx = Yii::getAlias("@vendor/weixin");
  617. require_once($wx . '/lib/WxPay.Api.php');
  618. require_once($wx . '/example/WxPay.JsApiPay.php');
  619. $input = new \WxPayUnifiedOrder();
  620. $input->SetBody($name);
  621. $input->SetOut_trade_no($orderSn);
  622. $input->SetTotal_fee($totalFee * 100);
  623. $input->SetTime_start(date("YmdHis", $now));
  624. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  625. $input->SetTime_expire(date("YmdHis", $expireTime));
  626. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  627. $input->SetTrade_type("JSAPI");
  628. //花卉宝代为申请的微信支付
  629. $merchantExtend = $this->sjExtend->attributes;
  630. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  631. $input->SetSub_openid($openId);
  632. } else {
  633. $input->SetOpenid($openId);
  634. }
  635. //小程序使用miniAppId
  636. if (httpUtil::isMiniProgram()) {
  637. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  638. }
  639. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  640. $tools = new \JsApiPay();
  641. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  642. $newParams = json_decode($jsApiParameters, true);
  643. //已请求微信不能修改价格
  644. $updateData = [];
  645. $updateData['modPrice'] = 0;
  646. if (empty($order['deadline'])) {
  647. $updateData['deadline'] = $expireTime;
  648. }
  649. OrderService::updateById($orderId, $updateData);
  650. util::success($newParams);
  651. }
  652. //快捷付款订单
  653. public function actionFastPay()
  654. {
  655. ini_set('date.timezone', 'Asia/Shanghai');
  656. $post = Yii::$app->request->post();
  657. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  658. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  659. //验证门店是否有效
  660. $shopInfo = ShopService::getById($shopId);
  661. ShopService::valid($shopInfo, $this->sjId);
  662. $post['shopId'] = $shopId;
  663. //默认门店订单
  664. $store = isset($post['store']) ? $post['store'] : 1;
  665. $post['store'] = $store;
  666. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  667. $sourceType = $this->isWx ? 0 : 1;
  668. if (httpUtil::isMiniProgram()) {
  669. $sourceType = 2;
  670. }
  671. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  672. //兼容旧系统sourceType=3表示朋友圈来源
  673. $fromType = $sourceType == 3 ? 2 : 0;
  674. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  675. $post['userId'] = $this->adminId;
  676. $custom = $this->custom;
  677. $post['bookName'] = $custom['userName'] ?? '';
  678. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  679. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  680. $post['bookMobile'] = $bookMobile;
  681. $prePrice = round($post['prePrice'], 2);
  682. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  683. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  684. $actPrice = $discountData['price'];
  685. $post['discountType'] = $discountData['discountType'];
  686. $post['discountAmount'] = $discountData['discountAmount'];
  687. $post['actPrice'] = $actPrice;
  688. $post['realPrice'] = $actPrice;
  689. $post['payStyle'] = 0;
  690. $post['sjId'] = $this->sjId;
  691. $now = time();
  692. $expireTime = $now + 300;//订单5分钟后过期
  693. $post['createTime'] = date("Y-m-d H:i:s", $now);
  694. $post['deadline'] = $expireTime;
  695. if ($actPrice <= 0) {
  696. util::fail('请填写正确的金额');
  697. }
  698. //微信支付订单提交不能修改价格
  699. $post['modPrice'] = $this->isWx ? 0 : 1;
  700. $post['sourceType'] = $sourceType;
  701. $post['goodsNum'] = 1;
  702. $post['fromType'] = $fromType;
  703. $order = OrderService::addOrder($post);
  704. $orderId = $order['id'];
  705. $orderSn = $order['orderSn'];
  706. $sjId = $this->sjId;
  707. if ($payWay == 0) {
  708. $orderId = $order['id'];
  709. $name = '购买商品';
  710. $totalFee = $actPrice;
  711. $user = UserService::getById($this->adminId);
  712. $openId = isset($user['openId']) ? $user['openId'] : 0;
  713. if (httpUtil::isMiniProgram()) {
  714. //小程序使用miniOpenId
  715. $openId = $user['miniOpenId'];
  716. }
  717. if (empty($openId)) {
  718. util::fail('没有找到客户的openId');
  719. }
  720. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  721. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  722. $wxPayType = 0;
  723. if (httpUtil::isMiniProgram()) {
  724. $wxPayType = 1;
  725. }
  726. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  727. $wx = Yii::getAlias("@vendor/weixin");
  728. require_once($wx . '/lib/WxPay.Api.php');
  729. require_once($wx . '/example/WxPay.JsApiPay.php');
  730. $input = new \WxPayUnifiedOrder();
  731. $input->SetBody($name);
  732. $input->SetOut_trade_no($orderSn);
  733. $input->SetTotal_fee($totalFee * 100);
  734. $input->SetTime_start(date("YmdHis", $now));
  735. $input->SetAttach($attach);
  736. //设置订单有效期5分钟
  737. $input->SetTime_expire(date("YmdHis", $expireTime));
  738. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  739. $input->SetTrade_type("JSAPI");
  740. //花卉宝代为申请的微信支付
  741. $merchantExtend = $this->sjExtend->attributes;
  742. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  743. $input->SetSub_openid($openId);
  744. } else {
  745. $input->SetOpenid($openId);
  746. }
  747. //小程序使用miniAppId
  748. if (httpUtil::isMiniProgram()) {
  749. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  750. }
  751. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  752. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  753. $tools = new \JsApiPay();
  754. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  755. $newParams = json_decode($jsApiParameters, true);
  756. $newParams['orderId'] = $orderId;
  757. util::success($newParams);
  758. } elseif ($payWay == 1) {
  759. $extend = MerchantExtendService::getBySjId($sjId);
  760. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  761. util::fail('支付宝付款即将开通...');
  762. }
  763. $config = [
  764. //应用ID,您的APPID。
  765. 'app_id' => $extend['alipayPId'],
  766. //商户私钥,您的原始格式RSA私钥
  767. 'merchant_private_key' => $extend['alipayKey'],
  768. //异步通知地址
  769. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  770. //同步跳转
  771. 'return_url' => "",
  772. //编码格式
  773. 'charset' => "UTF-8",
  774. //签名方式
  775. 'sign_type' => "RSA2",
  776. //支付宝网关
  777. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  778. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  779. 'alipay_public_key' => $extend['alipayPublicKey'],
  780. ];
  781. Yii::info(json_encode($config) . ' aplipay config');
  782. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  783. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  784. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  785. $totalFee = $order['realPrice'];
  786. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  787. $subject = '购买商品';//订单名称,必填
  788. $total_amount = $totalFee;//付款金额,必填
  789. $body = '';//商品描述,可空
  790. $timeout_express = "1m";//超时时间
  791. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  792. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
  793. $passBackParams = urlencode($passBackParams);
  794. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  795. $payRequestBuilder->setBody($body);
  796. $payRequestBuilder->setSubject($subject);
  797. $payRequestBuilder->setOutTradeNo($out_trade_no);
  798. $payRequestBuilder->setTotalAmount($total_amount);
  799. $payRequestBuilder->setTimeExpress($timeout_express);
  800. //在异步通知时将该参数原样返回
  801. $payRequestBuilder->setPassbackParams($passBackParams);
  802. //同步通知
  803. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  804. //异步通知
  805. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  806. $payResponse = new \AlipayTradeService($config);
  807. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  808. //直接将支付宝的html返回给前端
  809. echo $result;
  810. } elseif ($payWay == 2) {
  811. //余额支付,验证支付密码是否正确
  812. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  813. $user = UserService::getUserInfo($this->adminId);
  814. UserService::validPayPassword($payPassword, $user);
  815. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  816. $callbackParams = [];
  817. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  818. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  819. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  820. } else {
  821. util::fail('无效的支付方式');
  822. }
  823. }
  824. //订单评价
  825. public function actionComment()
  826. {
  827. $post = Yii::$app->request->post();
  828. $id = $post['id'];
  829. $order = OrderService::getById($id);
  830. OrderService::valid($order, $this->mainId);
  831. if ($order['grade'] > 0) {
  832. util::fail('您已经评过了');
  833. }
  834. OrderService::comment($post);
  835. util::complete('提交成功');
  836. }
  837. //订单详情 ssh 2019.12.16
  838. public function actionDetail()
  839. {
  840. $id = Yii::$app->request->get('id', 0);
  841. $detail = OrderClass::getFullInfo($id);
  842. OrderService::valid($detail, $this->mainId);
  843. util::success($detail);
  844. }
  845. public function actionList()
  846. {
  847. $get = Yii::$app->request->get();
  848. $search = isset($get['searchText']) ? $get['searchText'] : '';
  849. $searchType = isset($get['searchType']) && is_numeric($get['searchType']) ? $get['searchType'] : '';
  850. $shopId = $this->shopId ?? 0;
  851. if (empty($shopId)) {
  852. //没有登录不显示数据
  853. util::success(['list' => [], 'moreData' => 0, 'shop' => [], 'totalNum' => 0, 'totalPage' => 0]);
  854. }
  855. $where = [];
  856. $where['shopId'] = $shopId;
  857. if (!empty($get['customId'])) {
  858. $where['customId'] = $get['customId'];
  859. }
  860. if (!empty($get['ids'])) {
  861. $stringIds = $get['ids'];
  862. $newIds = explode(',', $stringIds);
  863. $where['id'] = ['in', $newIds];
  864. }
  865. $status = $get['status'] ?? 0;
  866. if (!empty($status)) {
  867. $where['status'] = $get['status'];
  868. }
  869. $debt = $get['debt'] ?? 2;
  870. if ($debt != 2) {
  871. $where['debt'] = $debt;
  872. }
  873. if (isset($get['shopAdminId']) && !empty($get['shopAdminId'])) {
  874. $where['shopAdminId'] = $get['shopAdminId'];
  875. }
  876. if (!empty($search)) {
  877. if (is_numeric($searchType)) {
  878. if ($searchType == 0) {
  879. $where['actPrice'] = $search;
  880. } elseif ($searchType == 1) {
  881. $where['orderSn'] = $search;
  882. } elseif ($searchType == 2) {
  883. $where['bookMobile'] = $search;
  884. } elseif ($searchType == 3) {
  885. $where['customName'] = ['like', $search];
  886. } else {
  887. $where['actPrice'] = $search;
  888. }
  889. } else {
  890. //兼容旧版本
  891. if (stringUtil::isMobile($search)) {
  892. $where['bookMobile'] = $search;
  893. } else {
  894. $where['orderSn'] = strtoupper($search);
  895. }
  896. }
  897. }
  898. $searchTime = $get['searchTime'] ?? '';
  899. if (!empty($searchTime)) {
  900. $startTime = $get['startTime'] ?? '';
  901. $endTime = $get['endTime'] ?? '';
  902. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  903. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  904. }
  905. $list = OrderService::getOrderList($where);
  906. $list['shop'] = $this->shop->attributes ?? [];
  907. util::success($list);
  908. }
  909. //订单归类 ssh 2019.12.17
  910. public function actionClassify()
  911. {
  912. $post = Yii::$app->request->post();
  913. $id = isset($post['id']) ? $post['id'] : 0;
  914. $order = OrderService::getById($id);
  915. OrderService::valid($order, $this->mainId);
  916. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  917. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  918. OrderService::classify($id, $categoryId, $usageId);
  919. util::complete();
  920. }
  921. //更新配送单 ssh 2019.12.17
  922. public function actionUpdateSheet()
  923. {
  924. $post = Yii::$app->request->post();
  925. $id = isset($post['id']) ? $post['id'] : 0;
  926. unset($post['id']);
  927. $order = OrderService::getById($id);
  928. OrderService::valid($order, $this->mainId);
  929. OrderService::updateSheet($order, $post);
  930. util::complete('提交成功');
  931. }
  932. //商家收款与发货 ssh 2019.12.18
  933. public function actionGathering()
  934. {
  935. $post = Yii::$app->request->post();
  936. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  937. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  938. $userId = isset($post['userId']) ? $post['userId'] : 0;
  939. $userInfo = UserService::getById($userId);
  940. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  941. util::fail('您选择的客户无效');
  942. }
  943. if ($price <= 0) {
  944. util::fail('请输入金额');
  945. }
  946. $post['prePrice'] = $price;
  947. $post['actPrice'] = $price;
  948. $post['payWay'] = $payWay;
  949. $post['sourceType'] = 1;
  950. $post['userId'] = $userId;
  951. $post['goodsNum'] = 1;
  952. $post['orderName'] = '商品';
  953. $shopId = MerchantService::getDefaultShopId($this->sj);
  954. $post['shopId'] = $shopId;
  955. $order = OrderService::addOrder($post);
  956. $id = $order['id'];
  957. $orderSn = $order['orderSn'];
  958. //流水类型列表
  959. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  960. $callbackParams = [];
  961. switch ($payWay) {
  962. case 0:
  963. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  964. break;
  965. case 1:
  966. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  967. break;
  968. case 2:
  969. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  970. break;
  971. default:
  972. util::fail('无效支付方式');
  973. }
  974. util::success($order);
  975. }
  976. //免发货管理 ssh 2020.1.6
  977. public function actionWithoutSend()
  978. {
  979. $id = Yii::$app->request->get('id');
  980. $order = OrderService::getById($id);
  981. OrderService::valid($order, $this->mainId);
  982. //配送流程变更
  983. $currentFlow = OrderSendClass::withoutSend($order);
  984. util::success(['currentFlow' => $currentFlow]);
  985. }
  986. //修改价格 ssh 2020.1.6
  987. public function actionUpdatePrice()
  988. {
  989. $id = Yii::$app->request->get('id');
  990. $price = Yii::$app->request->get('price', 1);
  991. $order = OrderService::getById($id);
  992. OrderService::valid($order, $this->mainId);
  993. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  994. util::fail('已发起支付,不能修改价格');
  995. }
  996. OrderService::updateById($id, ['actPrice' => $price]);
  997. util::complete('修改成功');
  998. }
  999. //配送单 ssh 2020.2.29
  1000. public function actionGetDeliverDetail()
  1001. {
  1002. $id = Yii::$app->request->get('id', 0);
  1003. $order = OrderService::getById($id);
  1004. OrderService::valid($order, $this->mainId);
  1005. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  1006. $reachPeriodId = $order['reachPeriod'];
  1007. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  1008. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  1009. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  1010. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  1011. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  1012. $bookName = '--';
  1013. $bookMobile = '--';
  1014. }
  1015. $data = [
  1016. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  1017. 'orderSn' => $order['orderSn'],
  1018. 'receiveUserName' => $order['receiveUserName'],
  1019. 'receiveMobile' => $order['receiveMobile'],
  1020. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  1021. 'cardInfo' => $order['cardInfo'],
  1022. 'bookMobile' => $bookMobile,
  1023. 'bookName' => $bookName,
  1024. 'remark' => $order['remark'],
  1025. 'sendNum' => $order['sendNum'],
  1026. 'telephone' => 18030142050,
  1027. 'printTime' => '',
  1028. 'img' => '',
  1029. ];
  1030. util::success($data);
  1031. }
  1032. //运费计算 lqh 2021.4.12 暂反回固定
  1033. public function actionFreight()
  1034. {
  1035. util::success(['sedCost' => 10]);
  1036. }
  1037. }