TestController.php 16 KB

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