TestController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantService;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\message\classes\InformAdminClass;
  7. use bizHd\order\services\OrderService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizGhs\express\services\MiniExpressService;
  10. use common\components\dict;
  11. use common\components\lakala\Lakala;
  12. use common\components\miniUtil;
  13. use common\components\orderSn;
  14. use common\components\wxUtil;
  15. use Yii;
  16. use common\components\util;
  17. class TestController extends BaseController
  18. {
  19. public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
  20. public function actionAliRun()
  21. {
  22. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  23. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  24. $arr = [
  25. ['name' => '国兰花尚', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  26. ['name' => '国兰花尚', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304']
  27. ];
  28. $new = [];
  29. foreach ($arr as $item) {
  30. $wx = $item['wx'];
  31. $zfb = $item['zfb'];
  32. $name = $item['name'];
  33. $merchantNo = $item['merchantNo'];
  34. $group = [];
  35. foreach ($wx as $oneWx) {
  36. $params = [
  37. 'appid' => 'OP00002119',
  38. 'serial_no' => '018b08cfddbd',
  39. 'merchant_no' => $merchantNo,
  40. 'term_no' => 'C6337694',
  41. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  42. 'lklCertificatePath' => $lklCertificatePath,
  43. ];
  44. $data = [
  45. 'subMerchantId' => $oneWx,
  46. 'tradeMode' => 'WECHAT',
  47. ];
  48. $laResource = new Lakala($params);
  49. $response = $laResource->openStateQuery($data);
  50. $statusName = '出错了';
  51. if ($response['retCode'] == '000000') {
  52. $checkResult = $response['respData']['checkResult'] ?? '';
  53. $statusName = '未确认';
  54. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED ') {
  55. $statusName = '已确认';
  56. }
  57. }
  58. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  59. }
  60. $params = [
  61. 'appid' => 'OP00002119',
  62. 'serial_no' => '018b08cfddbd',
  63. 'merchant_no' => $merchantNo,
  64. 'term_no' => 'C6337694',
  65. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  66. 'lklCertificatePath' => $lklCertificatePath,
  67. ];
  68. $data = [
  69. 'subMerchantId' => $zfb,
  70. 'tradeMode' => 'ALIPAY',
  71. ];
  72. $laResource = new Lakala($params);
  73. $response = $laResource->openStateQuery($data);
  74. $statusName = '出错了';
  75. if ($response['retCode'] == '000000') {
  76. $checkResult = $response['respData']['checkResult'] ?? '';
  77. $statusName = '未确认';
  78. if ($checkResult == 'AUTHORIZED ') {
  79. $statusName = '已确认';
  80. }
  81. }
  82. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  83. $new[] = ['name' => $name, 'status' => $group];
  84. }
  85. print_r($new);
  86. }
  87. public function actionAliRun2()
  88. {
  89. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  90. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  91. $params = [
  92. 'appid' => 'OP00002119',
  93. 'serial_no' => '018b08cfddbd',
  94. 'merchant_no' => '82240505992000N',
  95. 'term_no' => 'C6337694',
  96. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  97. 'lklCertificatePath' => $lklCertificatePath,
  98. ];
  99. $outTradeNo = orderSn::getPurchaseSn();
  100. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  101. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  102. $aliParams = [
  103. 'orderSn' => $outTradeNo,
  104. 'amount' => 0.16,
  105. 'capitalType' => $currentCapitalType,
  106. 'notifyUrl' => $notifyUrl,
  107. ];
  108. $laResource = new Lakala($params);
  109. $response = $laResource->driveAliPay($aliParams);
  110. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  111. echo '<pre>';
  112. echo "下单成功<br/>";
  113. print_r($response);
  114. } else {
  115. echo '<pre>';
  116. echo "下单失败<br/>";
  117. print_r($response);
  118. }
  119. }
  120. public function actionAliRun3()
  121. {
  122. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  123. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  124. $params = [
  125. 'appid' => 'OP00002119',
  126. 'serial_no' => '018b08cfddbd',
  127. 'merchant_no' => '82240505992000N',
  128. 'term_no' => 'C6337694',
  129. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  130. 'lklCertificatePath' => $lklCertificatePath,
  131. ];
  132. $laResource = new Lakala($params);
  133. $outTradeNo = orderSn::getPurchaseSn();
  134. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  135. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  136. $wxParams = [
  137. 'orderSn' => $outTradeNo,
  138. 'amount' => 0.16,
  139. 'capitalType' => $currentCapitalType,
  140. 'notifyUrl' => $notifyUrl,
  141. ];
  142. $response = $laResource->driveWxPay($wxParams);
  143. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  144. echo '<pre>';
  145. echo "下单成功<br/>";
  146. print_r($response);
  147. } else {
  148. echo '<pre>';
  149. echo "下单失败<br/>";
  150. print_r($response);
  151. }
  152. }
  153. //dada 城市code
  154. public function actionDadaCityCode()
  155. {
  156. $res = dada::getCityCode(0);
  157. util::success($res);
  158. }
  159. //理由
  160. public function actionDadaReasons()
  161. {
  162. $res = dada::getCancelReason(0);
  163. util::success($res);
  164. }
  165. //达达 :下单
  166. public function actionDadaAddOrder()
  167. {
  168. $orderSn = 'XSD_CS26316851';
  169. $orderInfo = OrderClass::getByOrderSn($orderSn);
  170. $res = DadaExpressServices::addOrder($orderInfo);
  171. util::success($res);
  172. }
  173. //重发快递
  174. public function actionDadaReAdd()
  175. {
  176. $orderSn = 'XSD_CS26316851';
  177. $orderInfo = OrderClass::getByOrderSn($orderSn);
  178. $res = DadaExpressServices::reAddOrder($orderInfo);
  179. util::success($res);
  180. }
  181. //达达状态查询
  182. public function actionDadaOrderStatus()
  183. {
  184. $orderSn = 'XSD_CS26316851';
  185. $res = DadaExpressServices::statusOrder($orderSn);
  186. util::success($res);
  187. }
  188. //达达取消下单
  189. public function actionDadaCancelOrder()
  190. {
  191. $orderSn = 'XSD_CS26316851';
  192. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  193. util::success($res);
  194. }
  195. //获取已支持的配送公司列表接口
  196. public function actionGetAllDelivery()
  197. {
  198. $data = MiniExpressService::getAllImmeDelivery();
  199. util::success($data);
  200. }
  201. //即时配送
  202. /*
  203. * Array
  204. (
  205. [resultcode] => 0
  206. [resultmsg] => OK
  207. [shop_list] => Array
  208. (
  209. [0] => Array
  210. (
  211. [shopid] => 1588714266
  212. [delivery_id] => SFTC
  213. [audit_result] => 0
  214. [create_time] => 1612172838
  215. [remark] =>
  216. [delivery_name] => 顺丰同城急送
  217. )
  218. )
  219. )
  220. */
  221. public function actionGetBindAccount()
  222. {
  223. $merchant = WxOpenClass::getGhsWxInfo();
  224. $isOpen = 2;
  225. $r = miniUtil::getBindAccount($merchant, $isOpen);
  226. dd($r);
  227. }
  228. //下单 (沙箱)
  229. /**
  230. * Array
  231. * (
  232. * [resultcode] => 0
  233. * [resultmsg] => ok
  234. * [fee] => 10
  235. * [waybill_id] => test_shop_id1612365974_waybillid
  236. * [order_status] => 101
  237. * [dispatch_duration] => 300
  238. * )
  239. */
  240. public function actionCreateWaybill()
  241. {
  242. $merchant = WxOpenClass::getGhsWxInfo();
  243. $isOpen = 2;
  244. $shopId = 'test_shop_id';
  245. $shopOrderId = 'test_shop_id' . time();
  246. $appSecret = 'test_app_secrect';
  247. $data = [
  248. 'shopid' => $shopId,
  249. 'shop_order_id' => $shopOrderId,
  250. 'shop_no' => '1',
  251. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  252. 'delivery_id' => "TEST",
  253. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  254. 'sender' => [
  255. 'name' => 'test',
  256. 'city' => '厦门市',
  257. 'address' => '思明区',
  258. 'address_detail' => '软件园二期',
  259. 'phone' => '19959271111',
  260. 'lng' => 118.134343,
  261. 'lat' => 24.483566,
  262. 'coordinate_type' => 0,
  263. ],
  264. 'receiver' => [
  265. 'name' => 'test',
  266. 'city' => '厦门市',
  267. 'address' => '思明区',
  268. 'address_detail' => '软件园二期',
  269. 'phone' => '19959271111',
  270. 'lng' => 118.134343,
  271. 'lat' => 24.493566,
  272. 'coordinate_type' => 0,
  273. ],
  274. 'cargo' => [
  275. 'goods_value' => 1,
  276. 'goods_weight' => 0.1,
  277. 'cargo_first_class' => '鲜花',
  278. 'cargo_second_class' => '鲜花',
  279. ],
  280. 'order_info' => [
  281. 'order_type' => 0,
  282. ],
  283. 'shop' => [
  284. 'wxa_path' => '/shop',
  285. 'img_url' => 'http://www.baidu.com/test.png',
  286. 'goods_name' => 'test',
  287. 'goods_count' => 1,
  288. ],
  289. ];
  290. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  291. dd($r);
  292. }
  293. //获取运单数据
  294. /**
  295. * Array
  296. * (
  297. * [resultcode] => 0
  298. * [resultmsg] => ok
  299. * [order_status] => 101
  300. * [agent_info] => Array
  301. * (
  302. * )
  303. *
  304. * [waybill_id] => test_shop_id1612365974_waybillid
  305. * [rider_name] =>
  306. * [rider_phone] =>
  307. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  308. * )
  309. */
  310. public function actionGetOrder()
  311. {
  312. $shopId = 'test_shop_id';
  313. $shopOrderId = 'test_shop_id1612365974';
  314. $appSecret = 'test_app_secrect';
  315. $merchant = WxOpenClass::getGhsWxInfo();
  316. $isOpen = 2;
  317. $data = [
  318. 'shopid' => $shopId,
  319. 'shop_order_id' => $shopOrderId,
  320. 'shop_no' => '1',
  321. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  322. ];
  323. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  324. dd($r);
  325. }
  326. //沙盒 更新快递状态
  327. public function actionMockUpdateOrder()
  328. {
  329. $merchant = WxOpenClass::getGhsWxInfo();
  330. $isOpen = 2;
  331. /**
  332. * {
  333. * "shopid": "test_shop_id",
  334. * "shop_order_id": "xxxxxxxxxxx",
  335. * "waybill_id": "xxxxxxxxxxxxx",
  336. * "action_time": 12345678,
  337. * "order_status": 101,
  338. * "action_msg": "",
  339. * }
  340. */
  341. $shopId = 'test_shop_id';
  342. $shopOrderId = 'test_shop_id1612365974';
  343. $data = [
  344. 'shop_order_id' => $shopOrderId,
  345. "shopid" => $shopId,
  346. "action_time" => time(),
  347. "order_status" => 302,
  348. 'action_msg' => '状态变更',
  349. ];
  350. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  351. dd($r);
  352. }
  353. public function actionTest()
  354. {
  355. }
  356. //新增订单
  357. public function actionAddOrder()
  358. {
  359. $dada = Yii::getAlias("@vendor/dada/");
  360. require_once $dada . 'api/addOrderApi.php';
  361. require_once $dada . 'client/dadaRequestClient.php';
  362. require_once $dada . 'client/dadaResponse.php';
  363. require_once $dada . 'config/config.php';
  364. require_once $dada . 'model/orderModel.php';
  365. // isOnline 判断是否是测试环境,会有不同的域名等
  366. $isOnline = false;
  367. $sourceId = 1000000;
  368. // 初始化一个config
  369. $config = new \Config($sourceId, $isOnline);
  370. $orderModel = new \OrderModel();
  371. $orderModel->setShopNo('11047059');
  372. $orderModel->setOriginId('2018091100000002');
  373. $orderModel->setCityCode('021');
  374. $orderModel->setCargoPrice(10);
  375. $orderModel->setIsPrepay(0);
  376. $orderModel->setReceiverName('测试达达');
  377. $orderModel->setReceiverAddress('上海市崇明岛');
  378. $orderModel->setReceiverLat(31.63);
  379. $orderModel->setReceiverLng(121.41);
  380. $orderModel->setReceiverPhone('18588888888');
  381. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  382. // api主要有2个参数,一个是url, 一个是业务参数
  383. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  384. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  385. $resp = $dada_client->makeRequest();
  386. echo json_encode($resp);
  387. }
  388. //订单详情查询
  389. public function actionOrderQuery()
  390. {
  391. $dada = Yii::getAlias("@vendor/dada/");
  392. require_once $dada . 'api/OrderQueryApi.php';
  393. require_once $dada . 'client/dadaRequestClient.php';
  394. require_once $dada . 'client/dadaResponse.php';
  395. require_once $dada . 'config/config.php';
  396. require_once $dada . 'model/orderModel.php';
  397. // isOnline 判断是否是测试环境,会有不同的域名等
  398. $isOnline = false;
  399. $sourceId = 1000000;
  400. // 初始化一个config
  401. $config = new \Config($sourceId, $isOnline);
  402. $orderModel = new \OrderModel();
  403. $orderModel->setOrderId('2018091100000002');
  404. // api主要有2个参数,一个是url, 一个是业务参数
  405. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  406. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  407. $resp = $dada_client->makeRequest();
  408. echo json_encode($resp);
  409. }
  410. public function actionFocus()
  411. {
  412. $name = '花卉宝';
  413. if (getenv('YII_ENV') == 'dev') {
  414. $name = '花美灵';
  415. }
  416. $merchant = MerchantService::getByCondition(['name' => $name]);
  417. $list = wxUtil::getSubscribeUserList($merchant);
  418. dd($list);
  419. }
  420. //宝贝售出提醒 ssh 2020.1.30
  421. public function actionInform()
  422. {
  423. $merchant = MerchantService::getMerchantById(12362);
  424. $order = OrderService::getById(214810);
  425. InformAdminClass::sendComplete($order);
  426. }
  427. public function actionNotice()
  428. {
  429. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  430. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  431. echo '<pre>';
  432. print_r($data);
  433. $msg = serialize($data);
  434. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  435. }
  436. }