OrderController.php 46 KB

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