OrderController.php 46 KB

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