OrderController.php 47 KB

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