OrderController.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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\OrderForwardClass;
  12. use bizHd\order\classes\OrderItemClass;
  13. use bizHd\order\classes\OrderSendClass;
  14. use bizHd\order\services\OrderService;
  15. use bizHd\product\classes\ProductClass;
  16. use bizHd\purchase\classes\PurchaseClass;
  17. use bizHd\saas\services\RegionService;
  18. use bizHd\shop\classes\MainClass;
  19. use bizHd\shop\classes\ShopClass;
  20. use bizHd\user\services\UserService;
  21. use bizHd\work\classes\WorkClass;
  22. use bizHd\wx\classes\WxOpenClass;
  23. use common\components\dict;
  24. use common\components\dateUtil;
  25. use common\components\noticeUtil;
  26. use common\components\orderSn;
  27. use common\components\payUtil;
  28. use common\services\xhPayToolService;
  29. use Yii;
  30. use common\components\util;
  31. use common\components\stringUtil;
  32. use bizHd\promote\services\CouponService;
  33. use common\components\httpUtil;
  34. use biz\wx\classes\WxMessageClass;
  35. use common\components\lakala\Lakala;
  36. class OrderController extends BaseController
  37. {
  38. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
  39. public function actionDebt()
  40. {
  41. $get = Yii::$app->request->get();
  42. $id = $get['id'] ?? 0;
  43. $info = OrderClass::getById($id, true);
  44. if (empty($info)) {
  45. util::fail('没有找到订单');
  46. }
  47. if ($info->mainId != $this->mainId) {
  48. util::fail('不是你的订单');
  49. }
  50. //4秒内不允许重复提交
  51. util::checkRepeatCommit($id, 4);
  52. if ($info->status != 1) {
  53. util::fail('订单已付款或取消');
  54. }
  55. $payWay = dict::getDict('payWay', 'debtPay');
  56. $connection = Yii::$app->db;
  57. $transaction = $connection->beginTransaction();
  58. try {
  59. $actPrice = $info->actPrice ?? 0;
  60. $info->debtPrice = $actPrice;
  61. $info->remainDebtPrice = $actPrice;
  62. $info->debt = 1;
  63. $info->save();
  64. OrderClass::payAfter($info, $payWay);
  65. $transaction->commit();
  66. util::complete('赊账成功');
  67. } catch (\Exception $exception) {
  68. $transaction->rollBack();
  69. Yii::info("赊账失败原因:" . $exception->getMessage());
  70. util::fail('操作失败');
  71. }
  72. }
  73. //取消订单 ssh 20221231
  74. public function actionCancel()
  75. {
  76. //避免重复提交
  77. $adminId = $this->adminId;
  78. util::checkRepeatCommit($adminId, 8);
  79. $get = Yii::$app->request->get();
  80. $id = $get['id'] ?? 0;
  81. $order = OrderClass::getById($id, true);
  82. OrderClass::valid($order, $this->mainId);
  83. $deadTime = $order->deadline ?? 0;
  84. $current = time();
  85. $diff = bcsub($deadTime, $current);
  86. if ($diff < 60) {
  87. util::fail('60秒后将自动取消');
  88. }
  89. $connection = Yii::$app->db;
  90. $transaction = $connection->beginTransaction();
  91. try {
  92. OrderClass::setExpire($order, true);
  93. $transaction->commit();
  94. util::complete();
  95. } catch (\Exception $exception) {
  96. $transaction->rollBack();
  97. Yii::info("取消原因:" . $exception->getMessage());
  98. util::fail('取消失败');
  99. }
  100. }
  101. //修改订单 ssh 20220926
  102. public function actionUpdate()
  103. {
  104. $post = Yii::$app->request->post();
  105. $id = $post['id'] ?? 0;
  106. $order = OrderClass::getById($id, true);
  107. OrderClass::valid($order, $this->mainId);
  108. unset($post['id']);
  109. if ($order->status == 3) {
  110. util::fail('订单已配送');
  111. }
  112. if ($order->status == 4) {
  113. util::fail('订单已完成');
  114. }
  115. if ($order->status == 5) {
  116. util::fail('订单已取消');
  117. }
  118. if ($order->fromType == 4) {
  119. util::fail('请在美团APP上修改');
  120. }
  121. $address = $post['address'] ?? '';
  122. $floor = $post['floor'] ?? '';
  123. $post['fullAddress'] = $address . $floor;
  124. OrderClass::updateById($id, $post);
  125. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  126. $remark = $post['remark'] ?? '';
  127. $reachDate = $post['reachDate'] ?? '';
  128. $reachPeriod = $post['reachPeriod'] ?? '';
  129. $cardInfo = $post['cardInfo'] ?? '';
  130. $anonymity = $post['anonymity'] ?? 0;
  131. $bookName = $post['bookName'] ?? '';
  132. if (!empty($workList)) {
  133. foreach ($workList as $work) {
  134. $work->remark = $remark;
  135. $work->reachDate = $reachDate;
  136. $work->reachPeriod = $reachPeriod;
  137. $work->cardInfo = $cardInfo;
  138. $work->anonymity = $anonymity;
  139. $work->bookName = $bookName;
  140. $work->save();
  141. }
  142. }
  143. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  144. ShopExtClass::orderUpdateRemind($shopExt, $order);
  145. util::complete();
  146. }
  147. //客户欠款的订单 ssh 2021.2.4
  148. public function actionDebtList()
  149. {
  150. $get = Yii::$app->request->get();
  151. $id = $get['id'] ?? 0;
  152. $info = CustomClass::getById($id, true);
  153. CustomClass::valid($info, $this->shopId);
  154. $where = ['customId' => $id, 'debt' => 1];
  155. $searchTime = $get['searchTime'] ?? '';
  156. if (!empty($searchTime)) {
  157. $startTime = $get['startTime'] ?? '';
  158. $endTime = $get['endTime'] ?? '';
  159. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  160. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  161. }
  162. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice']);
  163. if (!empty($list)) {
  164. foreach ($list as $key => $value) {
  165. $debtPrice = $value['debtPrice'] ?? 0;
  166. $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
  167. $hasPayDebt = 0;
  168. if ($debtPrice > $remainDebtPrice) {
  169. $hasPayDebt = bcsub($debtPrice, $remainDebtPrice, 2);
  170. }
  171. $list[$key]['hasPayDebt'] = floatval($hasPayDebt);
  172. }
  173. }
  174. $result = ['customInfo' => $info, 'list' => $list];
  175. util::success($result);
  176. }
  177. //发货
  178. public function actionSend()
  179. {
  180. $get = Yii::$app->request->get();
  181. $id = isset($get['id']) ? $get['id'] : 0;
  182. $order = OrderClass::getById($id, true);
  183. if (empty($order)) {
  184. util::fail('没有找到订单');
  185. }
  186. OrderClass::valid($order, $this->mainId);
  187. if ($order->status != 2) {
  188. util::fail('订单不是待发货状态');
  189. }
  190. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  191. if (!empty($workList)) {
  192. $unComplete = false;
  193. foreach ($workList as $work) {
  194. if ($work->status != 1) {
  195. $unComplete = true;
  196. }
  197. }
  198. if ($unComplete == true) {
  199. util::fail('还有制作单没有完成');
  200. }
  201. }
  202. $order->status = 4;
  203. $order->save();
  204. util::complete('操作成功');
  205. }
  206. //打印订单 ssh 20220601
  207. public function actionPrintOrder()
  208. {
  209. $get = Yii::$app->request->get();
  210. $id = isset($get['id']) ? $get['id'] : 0;
  211. $order = OrderClass::getById($id, true);
  212. if (empty($order)) {
  213. util::fail('没有找到订单');
  214. }
  215. if ($order->forward == 1) {
  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. $customName = $custom->name ?? '';
  472. $post['customName'] = $customName;
  473. $post['customNamePy'] = stringUtil::py($customName);
  474. if (!empty($post['receiveMobile'])) {
  475. if (!stringUtil::isMobile($post['receiveMobile'])) {
  476. util::fail('请填写正确的收花人手机号');
  477. }
  478. }
  479. if (!empty($post['bookMobile'])) {
  480. if (!stringUtil::isMobile($post['bookMobile'])) {
  481. util::fail('请填写正确的订花人手机号');
  482. }
  483. }
  484. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  485. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  486. //收银台开单默认到店自取
  487. $post['sendType'] = dict::getDict('sendType', 'shopGet');
  488. }
  489. $forward = $post['forward'] ?? 0;
  490. if ($forward == 1) {
  491. if ($hasPay != 1) {
  492. util::fail('售后付款单只能走线下转账');
  493. }
  494. } else {
  495. //如果不是售后付款单,并且选的不是余额支付,余额又够付当前订单,则自动切到余额支付
  496. $balance = $custom->balance ?? 0;
  497. $modifyPrice = $post['modifyPrice'] ?? 0;
  498. if ($hasPay != 4 && $balance > $modifyPrice) {
  499. $post['hasPay'] = 4;
  500. $hasPay = 4;
  501. }
  502. }
  503. $productJson = $post['product'] ?? '';
  504. $productList = [];
  505. if (!empty($productJson)) {
  506. $productList = json_decode($productJson, true);
  507. }
  508. if (empty($productList) && empty($groupId)) {
  509. //商家手机上开单并生成制作单
  510. if (!empty($post['unitGoodsPrice'])) {
  511. $unitGoodsPrice = $post['unitGoodsPrice'];
  512. if (!is_numeric($unitGoodsPrice)) {
  513. util::fail('请输入正确的单价');
  514. }
  515. $productList = GoodsClass::orderCreateGoods($post);
  516. }
  517. }
  518. if (empty($productList) && empty($groupId)) {
  519. if ($post['lsGoodsPrice'] <= 0) {
  520. $lsGoodsPrice = $post['lsGoodsPrice'];
  521. if (!is_numeric($lsGoodsPrice)) {
  522. util::fail('请输入正确的金额');
  523. }
  524. util::fail('请填写金额或选商品');
  525. }
  526. }
  527. $connection = Yii::$app->db;
  528. $transaction = $connection->beginTransaction();
  529. try {
  530. $post['product'] = $productList;
  531. //阿东开5支老是会出现5扎情况跟踪
  532. ProductClass::adStockCheck($this->shop, $productList);
  533. //3秒内不允许重复开单
  534. $staffId = $this->shopAdminId ?? 0;
  535. $cacheKey = 'hd_create_order_' . $staffId . '_' . $customId;
  536. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  537. if (!empty($has)) {
  538. util::fail('稍等5秒再开单');
  539. }
  540. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 3, 'has']);
  541. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  542. $return = OrderService::createHdOrder($post, $custom, $hasPay);
  543. $shop = $this->shop;
  544. $staff = $this->shopAdmin;
  545. //售后开付款单,库存要变化,关系要建立,多处需要同步修改 sh_pay_change ssh
  546. OrderClass::shPayChange($return, $shop, $staff);
  547. $transaction->commit();
  548. //打印小票和语音播报
  549. $id = $return->id ?? 0;
  550. $order = OrderClass::getById($id, true);
  551. if ($order->fromType == 3 || $order->fromType == 4) {
  552. //除了客服号下单和美团下单,其它情况允许打小票
  553. } else {
  554. //前台打小票
  555. OrderClass::onlinePrint($order);
  556. }
  557. //前台提示收款多少钱
  558. ShopExtClass::hdGatheringReport($order);
  559. //前台提醒出示付款码
  560. if (isset($order->status) && $order->status == 1) {
  561. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  562. ShopExtClass::pleasePayReport($order);
  563. }
  564. }
  565. $shopId = $order->shopId ?? 0;
  566. $shop = ShopClass::getById($shopId, true);
  567. WxMessageClass::gatheringIncomeInform($shop, $order);
  568. //新制作单提示
  569. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  570. ShopExtClass::newWorkRemind($shopExt, $order);
  571. util::success($return);
  572. } catch (\Exception $e) {
  573. $transaction->rollBack();
  574. Yii::error("失败原因:" . $e->getMessage());
  575. util::fail('下单失败');
  576. }
  577. }
  578. //下单要用到的相关信息 ssh 2019.12.6
  579. public function actionOrderRelate()
  580. {
  581. $regionTree = RegionService::tree();
  582. $shop = $this->shop->attributes;
  583. $freight = MerchantExtendService::getFreight($this->sjExtend);
  584. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  585. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  586. util::success($out);
  587. }
  588. //余额支付 ssh 2019.12.6
  589. public function actionBalancePay()
  590. {
  591. $post = Yii::$app->request->post();
  592. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  593. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  594. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  595. $order = OrderService::getByOrderSn($orderSn);
  596. $userId = $this->adminId;
  597. $user = UserService::getUserInfo($userId);
  598. //验证支付密码是否正确
  599. UserService::validPayPassword($payPassword, $user);
  600. //支付前验证订单有效性
  601. OrderService::checkBeforePay($order);
  602. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  603. $totalFee = $order['prePrice'];
  604. $sourceType = 0;
  605. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  606. $actPrice = $discountData['price'];
  607. $callbackParams = [];
  608. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  609. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  610. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  611. }
  612. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  613. public function actionWxPay()
  614. {
  615. ini_set('date.timezone', 'Asia/Shanghai');
  616. $post = Yii::$app->request->post();
  617. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  618. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  619. $order = OrderService::getByOrderSn($orderSn);
  620. $orderId = $order['id'];
  621. //验证优惠券是否还有效
  622. if (!empty($couponId)) {
  623. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  624. }
  625. //支付前验证订单有效性
  626. OrderService::checkBeforePay($order);
  627. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  628. $totalFee = $order['realPrice'];
  629. //小程序使用miniOpenId
  630. if (httpUtil::isMiniProgram()) {
  631. $openId = $this->user['miniOpenId'];
  632. } else {
  633. $openId = $this->user['openId'];
  634. }
  635. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  636. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  637. $wxPayType = 0;
  638. if (httpUtil::isMiniProgram()) {
  639. $wxPayType = 1;
  640. }
  641. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  642. //订单30分钟后过期
  643. $now = time();
  644. $expireTime = $now + 1800;
  645. $wx = Yii::getAlias("@vendor/weixin");
  646. require_once($wx . '/lib/WxPay.Api.php');
  647. require_once($wx . '/example/WxPay.JsApiPay.php');
  648. $input = new \WxPayUnifiedOrder();
  649. $input->SetBody($name);
  650. $input->SetOut_trade_no($orderSn);
  651. $input->SetTotal_fee($totalFee * 100);
  652. $input->SetTime_start(date("YmdHis", $now));
  653. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  654. $input->SetTime_expire(date("YmdHis", $expireTime));
  655. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  656. $input->SetTrade_type("JSAPI");
  657. //花卉宝代为申请的微信支付
  658. $merchantExtend = $this->sjExtend->attributes;
  659. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  660. $input->SetSub_openid($openId);
  661. } else {
  662. $input->SetOpenid($openId);
  663. }
  664. //小程序使用miniAppId
  665. if (httpUtil::isMiniProgram()) {
  666. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  667. }
  668. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  669. $tools = new \JsApiPay();
  670. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  671. $newParams = json_decode($jsApiParameters, true);
  672. //已请求微信不能修改价格
  673. $updateData = [];
  674. $updateData['modPrice'] = 0;
  675. if (empty($order['deadline'])) {
  676. $updateData['deadline'] = $expireTime;
  677. }
  678. OrderService::updateById($orderId, $updateData);
  679. util::success($newParams);
  680. }
  681. //快捷付款订单
  682. public function actionFastPay()
  683. {
  684. ini_set('date.timezone', 'Asia/Shanghai');
  685. $post = Yii::$app->request->post();
  686. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  687. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  688. //验证门店是否有效
  689. $shopInfo = ShopService::getById($shopId);
  690. ShopService::valid($shopInfo, $this->sjId);
  691. $post['shopId'] = $shopId;
  692. //默认门店订单
  693. $store = isset($post['store']) ? $post['store'] : 1;
  694. $post['store'] = $store;
  695. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  696. $sourceType = $this->isWx ? 0 : 1;
  697. if (httpUtil::isMiniProgram()) {
  698. $sourceType = 2;
  699. }
  700. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  701. //兼容旧系统sourceType=3表示朋友圈来源
  702. $fromType = $sourceType == 3 ? 2 : 0;
  703. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  704. $post['userId'] = $this->adminId;
  705. $custom = $this->custom;
  706. $post['bookName'] = $custom['userName'] ?? '';
  707. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  708. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  709. $post['bookMobile'] = $bookMobile;
  710. $prePrice = round($post['prePrice'], 2);
  711. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  712. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  713. $actPrice = $discountData['price'];
  714. $post['discountType'] = $discountData['discountType'];
  715. $post['discountAmount'] = $discountData['discountAmount'];
  716. $post['actPrice'] = $actPrice;
  717. $post['realPrice'] = $actPrice;
  718. $post['payStyle'] = 0;
  719. $post['sjId'] = $this->sjId;
  720. $now = time();
  721. $expireTime = $now + 300;//订单5分钟后过期
  722. $post['createTime'] = date("Y-m-d H:i:s", $now);
  723. $post['deadline'] = $expireTime;
  724. if ($actPrice <= 0) {
  725. util::fail('请填写正确的金额');
  726. }
  727. //微信支付订单提交不能修改价格
  728. $post['modPrice'] = $this->isWx ? 0 : 1;
  729. $post['sourceType'] = $sourceType;
  730. $post['goodsNum'] = 1;
  731. $post['fromType'] = $fromType;
  732. $order = OrderService::addOrder($post);
  733. $orderId = $order['id'];
  734. $orderSn = $order['orderSn'];
  735. $sjId = $this->sjId;
  736. if ($payWay == 0) {
  737. $orderId = $order['id'];
  738. $name = '购买商品';
  739. $totalFee = $actPrice;
  740. $user = UserService::getById($this->adminId);
  741. $openId = isset($user['openId']) ? $user['openId'] : 0;
  742. if (httpUtil::isMiniProgram()) {
  743. //小程序使用miniOpenId
  744. $openId = $user['miniOpenId'];
  745. }
  746. if (empty($openId)) {
  747. util::fail('没有找到客户的openId');
  748. }
  749. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  750. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  751. $wxPayType = 0;
  752. if (httpUtil::isMiniProgram()) {
  753. $wxPayType = 1;
  754. }
  755. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  756. $wx = Yii::getAlias("@vendor/weixin");
  757. require_once($wx . '/lib/WxPay.Api.php');
  758. require_once($wx . '/example/WxPay.JsApiPay.php');
  759. $input = new \WxPayUnifiedOrder();
  760. $input->SetBody($name);
  761. $input->SetOut_trade_no($orderSn);
  762. $input->SetTotal_fee($totalFee * 100);
  763. $input->SetTime_start(date("YmdHis", $now));
  764. $input->SetAttach($attach);
  765. //设置订单有效期5分钟
  766. $input->SetTime_expire(date("YmdHis", $expireTime));
  767. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  768. $input->SetTrade_type("JSAPI");
  769. //花卉宝代为申请的微信支付
  770. $merchantExtend = $this->sjExtend->attributes;
  771. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  772. $input->SetSub_openid($openId);
  773. } else {
  774. $input->SetOpenid($openId);
  775. }
  776. //小程序使用miniAppId
  777. if (httpUtil::isMiniProgram()) {
  778. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  779. }
  780. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  781. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  782. $tools = new \JsApiPay();
  783. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  784. $newParams = json_decode($jsApiParameters, true);
  785. $newParams['orderId'] = $orderId;
  786. util::success($newParams);
  787. } elseif ($payWay == 1) {
  788. $extend = MerchantExtendService::getBySjId($sjId);
  789. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  790. util::fail('支付宝付款即将开通...');
  791. }
  792. $config = [
  793. //应用ID,您的APPID。
  794. 'app_id' => $extend['alipayPId'],
  795. //商户私钥,您的原始格式RSA私钥
  796. 'merchant_private_key' => $extend['alipayKey'],
  797. //异步通知地址
  798. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  799. //同步跳转
  800. 'return_url' => "",
  801. //编码格式
  802. 'charset' => "UTF-8",
  803. //签名方式
  804. 'sign_type' => "RSA2",
  805. //支付宝网关
  806. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  807. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  808. 'alipay_public_key' => $extend['alipayPublicKey'],
  809. ];
  810. Yii::info(json_encode($config) . ' aplipay config');
  811. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  812. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  813. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  814. $totalFee = $order['realPrice'];
  815. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  816. $subject = '购买商品';//订单名称,必填
  817. $total_amount = $totalFee;//付款金额,必填
  818. $body = '';//商品描述,可空
  819. $timeout_express = "1m";//超时时间
  820. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  821. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
  822. $passBackParams = urlencode($passBackParams);
  823. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  824. $payRequestBuilder->setBody($body);
  825. $payRequestBuilder->setSubject($subject);
  826. $payRequestBuilder->setOutTradeNo($out_trade_no);
  827. $payRequestBuilder->setTotalAmount($total_amount);
  828. $payRequestBuilder->setTimeExpress($timeout_express);
  829. //在异步通知时将该参数原样返回
  830. $payRequestBuilder->setPassbackParams($passBackParams);
  831. //同步通知
  832. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  833. //异步通知
  834. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  835. $payResponse = new \AlipayTradeService($config);
  836. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  837. //直接将支付宝的html返回给前端
  838. echo $result;
  839. } elseif ($payWay == 2) {
  840. //余额支付,验证支付密码是否正确
  841. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  842. $user = UserService::getUserInfo($this->adminId);
  843. UserService::validPayPassword($payPassword, $user);
  844. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  845. $callbackParams = [];
  846. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  847. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  848. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  849. } else {
  850. util::fail('无效的支付方式');
  851. }
  852. }
  853. //订单评价
  854. public function actionComment()
  855. {
  856. $post = Yii::$app->request->post();
  857. $id = $post['id'];
  858. $order = OrderService::getById($id);
  859. OrderService::valid($order, $this->mainId);
  860. if ($order['grade'] > 0) {
  861. util::fail('您已经评过了');
  862. }
  863. OrderService::comment($post);
  864. util::complete('提交成功');
  865. }
  866. //订单详情 ssh 2019.12.16
  867. public function actionDetail()
  868. {
  869. $id = Yii::$app->request->get('id', 0);
  870. $detail = OrderClass::getFullInfo($id);
  871. OrderService::valid($detail, $this->mainId);
  872. $forwardMap = [];
  873. if ($detail['forward'] == 1) {
  874. //当前单如果已经是售后付款单,则取出其对应的原单
  875. $map = OrderForwardClass::getByCondition(['shOrderId' => $id], true);
  876. if (!empty($map)) {
  877. $originOrderId = $map->orderId ?? 0;
  878. $forwardMap['orderId'] = $originOrderId;
  879. }
  880. }
  881. $detail['forwardMap'] = $forwardMap;
  882. $shOrderMap = [];
  883. if ($detail['hasForward'] == 1) {
  884. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  885. }
  886. $detail['shOrderMap'] = $shOrderMap;
  887. $main = $this->main;
  888. //是否走售后付款单模式判断 ssh
  889. $ret = OrderClass::ifShPay($detail, $main, 0);
  890. $shAddPay = $ret['shAddPay'];
  891. $shAddPayReason = $ret['shAddPayReason'];
  892. $detail['shAddPay'] = $shAddPay;
  893. $detail['shAddPayReason'] = $shAddPayReason;
  894. util::success($detail);
  895. }
  896. public function actionList()
  897. {
  898. $get = Yii::$app->request->get();
  899. $search = isset($get['searchText']) ? $get['searchText'] : '';
  900. $searchType = isset($get['searchType']) && is_numeric($get['searchType']) ? $get['searchType'] : '';
  901. $shopId = $this->shopId ?? 0;
  902. if (empty($shopId)) {
  903. //没有登录不显示数据
  904. util::success(['list' => [], 'moreData' => 0, 'shop' => [], 'totalNum' => 0, 'totalPage' => 0]);
  905. }
  906. $where = [];
  907. $where['shopId'] = $shopId;
  908. if (!empty($get['customId'])) {
  909. $where['customId'] = $get['customId'];
  910. }
  911. if (!empty($get['ids'])) {
  912. $stringIds = $get['ids'];
  913. $newIds = explode(',', $stringIds);
  914. $where['id'] = ['in', $newIds];
  915. }
  916. $status = $get['status'] ?? 0;
  917. if (!empty($status)) {
  918. $where['status'] = $get['status'];
  919. }
  920. $debt = $get['debt'] ?? 2;
  921. if ($debt != 2) {
  922. $where['debt'] = $debt;
  923. }
  924. if (isset($get['shopAdminId']) && !empty($get['shopAdminId'])) {
  925. $where['shopAdminId'] = $get['shopAdminId'];
  926. }
  927. if (!empty($search)) {
  928. if (is_numeric($searchType)) {
  929. if ($searchType == 0) {
  930. $where['actPrice'] = $search;
  931. } elseif ($searchType == 1) {
  932. $where['orderSn'] = $search;
  933. } elseif ($searchType == 2) {
  934. $where['bookMobile'] = $search;
  935. } elseif ($searchType == 3) {
  936. $where['customName'] = ['like', $search];
  937. } else {
  938. $where['actPrice'] = $search;
  939. }
  940. } else {
  941. //兼容旧版本
  942. if (stringUtil::isMobile($search)) {
  943. $where['bookMobile'] = $search;
  944. } else {
  945. $where['orderSn'] = strtoupper($search);
  946. }
  947. }
  948. }
  949. $searchTime = $get['searchTime'] ?? '';
  950. if (!empty($searchTime)) {
  951. $startTime = $get['startTime'] ?? '';
  952. $endTime = $get['endTime'] ?? '';
  953. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  954. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  955. }
  956. $list = OrderService::getOrderList($where);
  957. $list['shop'] = $this->shop->attributes ?? [];
  958. util::success($list);
  959. }
  960. //订单归类 ssh 2019.12.17
  961. public function actionClassify()
  962. {
  963. $post = Yii::$app->request->post();
  964. $id = isset($post['id']) ? $post['id'] : 0;
  965. $order = OrderService::getById($id);
  966. OrderService::valid($order, $this->mainId);
  967. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  968. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  969. OrderService::classify($id, $categoryId, $usageId);
  970. util::complete();
  971. }
  972. //更新配送单 ssh 2019.12.17
  973. public function actionUpdateSheet()
  974. {
  975. $post = Yii::$app->request->post();
  976. $id = isset($post['id']) ? $post['id'] : 0;
  977. unset($post['id']);
  978. $order = OrderService::getById($id);
  979. OrderService::valid($order, $this->mainId);
  980. OrderService::updateSheet($order, $post);
  981. util::complete('提交成功');
  982. }
  983. //商家收款与发货 ssh 2019.12.18
  984. public function actionGathering()
  985. {
  986. $post = Yii::$app->request->post();
  987. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  988. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  989. $userId = isset($post['userId']) ? $post['userId'] : 0;
  990. $userInfo = UserService::getById($userId);
  991. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  992. util::fail('您选择的客户无效');
  993. }
  994. if ($price <= 0) {
  995. util::fail('请输入金额');
  996. }
  997. $post['prePrice'] = $price;
  998. $post['actPrice'] = $price;
  999. $post['payWay'] = $payWay;
  1000. $post['sourceType'] = 1;
  1001. $post['userId'] = $userId;
  1002. $post['goodsNum'] = 1;
  1003. $post['orderName'] = '商品';
  1004. $shopId = MerchantService::getDefaultShopId($this->sj);
  1005. $post['shopId'] = $shopId;
  1006. $order = OrderService::addOrder($post);
  1007. $id = $order['id'];
  1008. $orderSn = $order['orderSn'];
  1009. //流水类型列表
  1010. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1011. $callbackParams = [];
  1012. switch ($payWay) {
  1013. case 0:
  1014. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  1015. break;
  1016. case 1:
  1017. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  1018. break;
  1019. case 2:
  1020. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  1021. break;
  1022. default:
  1023. util::fail('无效支付方式');
  1024. }
  1025. util::success($order);
  1026. }
  1027. //免发货管理 ssh 2020.1.6
  1028. public function actionWithoutSend()
  1029. {
  1030. $id = Yii::$app->request->get('id');
  1031. $order = OrderService::getById($id);
  1032. OrderService::valid($order, $this->mainId);
  1033. //配送流程变更
  1034. $currentFlow = OrderSendClass::withoutSend($order);
  1035. util::success(['currentFlow' => $currentFlow]);
  1036. }
  1037. //修改价格 ssh 2020.1.6
  1038. public function actionUpdatePrice()
  1039. {
  1040. $id = Yii::$app->request->get('id');
  1041. $price = Yii::$app->request->get('price', 1);
  1042. $order = OrderService::getById($id);
  1043. OrderService::valid($order, $this->mainId);
  1044. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  1045. util::fail('已发起支付,不能修改价格');
  1046. }
  1047. OrderService::updateById($id, ['actPrice' => $price]);
  1048. util::complete('修改成功');
  1049. }
  1050. //配送单 ssh 2020.2.29
  1051. public function actionGetDeliverDetail()
  1052. {
  1053. $id = Yii::$app->request->get('id', 0);
  1054. $order = OrderService::getById($id);
  1055. OrderService::valid($order, $this->mainId);
  1056. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  1057. $reachPeriodId = $order['reachPeriod'];
  1058. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  1059. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  1060. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  1061. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  1062. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  1063. $bookName = '--';
  1064. $bookMobile = '--';
  1065. }
  1066. $data = [
  1067. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  1068. 'orderSn' => $order['orderSn'],
  1069. 'receiveUserName' => $order['receiveUserName'],
  1070. 'receiveMobile' => $order['receiveMobile'],
  1071. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  1072. 'cardInfo' => $order['cardInfo'],
  1073. 'bookMobile' => $bookMobile,
  1074. 'bookName' => $bookName,
  1075. 'remark' => $order['remark'],
  1076. 'sendNum' => $order['sendNum'],
  1077. 'telephone' => 18030142050,
  1078. 'printTime' => '',
  1079. 'img' => '',
  1080. ];
  1081. util::success($data);
  1082. }
  1083. //运费计算 lqh 2021.4.12 暂反回固定
  1084. public function actionFreight()
  1085. {
  1086. util::success(['sedCost' => 10]);
  1087. }
  1088. }