OrderController.php 47 KB

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