OrderController.php 47 KB

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