OrderController.php 48 KB

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