TestController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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', 'get'];
  20. public function actionGet()
  21. {
  22. ini_set('memory_limit', '2045M');
  23. set_time_limit(0);
  24. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  25. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  26. //还差 花悠星 花千朵 十年 杭州斗南 昱成 问境
  27. $arr = [
  28. //['name' => '国兰花尚', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  29. //['name' => '花掌柜', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
  30. //['name' => '纯彩花艺', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
  31. //['name' => '集美天天鲜花', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
  32. ['name' => '丰行花行', 'merchantNo' => '82260205992007P', 'wx' => [601053759, 601052157], 'zfb' => '2088820725885465'],
  33. ['name' => '独家花行', 'merchantNo' => '82239305992006Q', 'wx' => [601049483, 601048223], 'zfb' => '2088820725546555'],
  34. ['name' => '好多花海沧', 'merchantNo' => '82239305992006R', 'wx' => [601052177, 601053735], 'zfb' => '2088820725549695'],
  35. ['name' => '美天鲜花', 'merchantNo' => '82259505992003F', 'wx' => [601062064, 601138175], 'zfb' => '2088820729400990'],
  36. ['name' => '天天陈江店', 'merchantNo' => '82259505992003E', 'wx' => [601060616, 601059382], 'zfb' => '2088820725555368'],
  37. //['name' => '叶上花', 'merchantNo' => '82231805992002G', 'wx' => [601062892, 601062589], 'zfb' => '2088820728763546'],
  38. ['name' => '源花汇', 'merchantNo' => '8227310599200GD', 'wx' => [601136305, 601067016], 'zfb' => '2088820729832744'],
  39. ['name' => '好又多(小明)', 'merchantNo' => '82239305992006S', 'wx' => [601135715, 601067347], 'zfb' => '2088820729698012'],
  40. ['name' => '我卖花', 'merchantNo' => '82227505992000R', 'wx' => [601177139, 601148755], 'zfb' => '2088820746424032'],
  41. ['name' => '七彩花都', 'merchantNo' => '8227310599200GF', 'wx' => [601176481, 601148503], 'zfb' => '2088820748594478'],
  42. //['name' => '都市花季', 'merchantNo' => '82239305992006U', 'wx' => [601174342, 601147649], 'zfb' => '2088820748507346'],
  43. //['name' => '花样年华', 'merchantNo' => '82260205992007Q', 'wx' => [601134352, 601091710], 'zfb' => '2088820735043444'],
  44. //['name' => '精茂城', 'merchantNo' => '8225840599200TF', 'wx' => [601173752, 601143352], 'zfb' => '2088820746800005'],
  45. ['name' => '莱漫', 'merchantNo' => '82239305992006T', 'wx' => [601134065, 601125595], 'zfb' => '2088820743859918'],
  46. //['name' => '福州我要花', 'merchantNo' => '82239105992007J', 'wx' => [601134030, 601128111], 'zfb' => '2088820745276973'],
  47. ['name' => '泉城', 'merchantNo' => '82239705992004E', 'wx' => [601133056, 601133821], 'zfb' => '2088820746111323'],
  48. ['name' => '美丽花行', 'merchantNo' => '82239305992006V', 'wx' => [601155249, 601149712], 'zfb' => '2088820747673312'],
  49. ['name' => '三叶', 'merchantNo' => '82236805992001Y', 'wx' => [601152233, 601151024], 'zfb' => '2088820747556725'],
  50. //['name' => '花大苪', 'merchantNo' => '8227310599200GG', 'wx' => [601174221, 601165136], 'zfb' => '2088820751181377'],
  51. ['name' => '十堰天天鲜花', 'merchantNo' => '82252305992001S', 'wx' => [601171131, 601170642], 'zfb' => '2088820750844626'],
  52. ['name' => '珑松花卉', 'merchantNo' => '82260205992007S', 'wx' => [601176093, 601174262], 'zfb' => '2088820754742492'],
  53. //['name' => '惠雅鲜花', 'merchantNo' => '82260205992007R', 'wx' => [601173390, 601174002], 'zfb' => '2088820753174540'],
  54. ['name' => '锦绣花卉', 'merchantNo' => '82252305992001T', 'wx' => [601176719, 601176660], 'zfb' => '2088820754751663'],
  55. ['name' => '祥瑞鲜花同安店', 'merchantNo' => '82239305992006W', 'wx' => [601178350, 601177795], 'zfb' => '2088820755715024'],
  56. ['name' => '祥瑞鲜花翔安店', 'merchantNo' => '82239305992006X', 'wx' => [601178260, 601178199], 'zfb' => '2088820754481553'],
  57. ['name' => '初见花季', 'merchantNo' => '82239305992006Y', 'wx' => [601178998, 601179605], 'zfb' => '2088820757223312'],
  58. ['name' => '荣发鲜花', 'merchantNo' => '82242705992000D', 'wx' => [601179681, 601179180], 'zfb' => '2088820756926593'],
  59. ];
  60. $new = [];
  61. foreach ($arr as $item) {
  62. $wx = $item['wx'];
  63. $zfb = $item['zfb'];
  64. $merchantNo = $item['merchantNo'];
  65. $name = $item['name'] . ' ' . $merchantNo;
  66. $group = [];
  67. foreach ($wx as $oneWx) {
  68. $params = [
  69. 'appid' => 'OP00002119',
  70. 'serial_no' => '018b08cfddbd',
  71. 'merchant_no' => $merchantNo,
  72. 'term_no' => 'C6337694',
  73. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  74. 'lklCertificatePath' => $lklCertificatePath,
  75. ];
  76. $data = [
  77. 'subMerchantId' => $oneWx,
  78. 'tradeMode' => 'WECHAT',
  79. ];
  80. $laResource = new Lakala($params);
  81. $response = $laResource->openStateQuery($data);
  82. $statusName = '出错了';
  83. if ($response['retCode'] == '000000') {
  84. $checkResult = $response['respData']['checkResult'] ?? '';
  85. $statusName = '未确认';
  86. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
  87. $statusName = '已确认';
  88. }
  89. }
  90. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  91. }
  92. $params = [
  93. 'appid' => 'OP00002119',
  94. 'serial_no' => '018b08cfddbd',
  95. 'merchant_no' => $merchantNo,
  96. 'term_no' => 'C6337694',
  97. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  98. 'lklCertificatePath' => $lklCertificatePath,
  99. ];
  100. $data = [
  101. 'subMerchantId' => $zfb,
  102. 'tradeMode' => 'ALIPAY',
  103. ];
  104. $laResource = new Lakala($params);
  105. $response = $laResource->openStateQuery($data);
  106. $statusName = '出错了';
  107. if ($response['retCode'] == '000000') {
  108. $checkResult = $response['respData']['checkResult'] ?? '';
  109. $statusName = '未确认';
  110. if ($checkResult == 'AUTHORIZED') {
  111. $statusName = '已确认';
  112. }
  113. }
  114. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  115. $new[] = ['name' => $name, 'status' => $group];
  116. }
  117. echo '<pre>';
  118. print_r($new);
  119. die;
  120. }
  121. public function actionAliRun2()
  122. {
  123. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  124. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  125. $params = [
  126. 'appid' => 'OP00002119',
  127. 'serial_no' => '018b08cfddbd',
  128. 'merchant_no' => '82240505992000N',
  129. 'term_no' => 'C6337694',
  130. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  131. 'lklCertificatePath' => $lklCertificatePath,
  132. ];
  133. $outTradeNo = orderSn::getPurchaseSn();
  134. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  135. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  136. $aliParams = [
  137. 'orderSn' => $outTradeNo,
  138. 'amount' => 0.16,
  139. 'capitalType' => $currentCapitalType,
  140. 'notifyUrl' => $notifyUrl,
  141. ];
  142. $laResource = new Lakala($params);
  143. $response = $laResource->driveAliPay($aliParams);
  144. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  145. echo '<pre>';
  146. echo "下单成功<br/>";
  147. print_r($response);
  148. } else {
  149. echo '<pre>';
  150. echo "下单失败<br/>";
  151. print_r($response);
  152. }
  153. }
  154. public function actionAliRun3()
  155. {
  156. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  157. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  158. $params = [
  159. 'appid' => 'OP00002119',
  160. 'serial_no' => '018b08cfddbd',
  161. 'merchant_no' => '82240505992000N',
  162. 'term_no' => 'C6337694',
  163. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  164. 'lklCertificatePath' => $lklCertificatePath,
  165. ];
  166. $laResource = new Lakala($params);
  167. $outTradeNo = orderSn::getPurchaseSn();
  168. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  169. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  170. $wxParams = [
  171. 'orderSn' => $outTradeNo,
  172. 'amount' => 0.16,
  173. 'capitalType' => $currentCapitalType,
  174. 'notifyUrl' => $notifyUrl,
  175. ];
  176. $response = $laResource->driveWxPay($wxParams);
  177. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  178. echo '<pre>';
  179. echo "下单成功<br/>";
  180. print_r($response);
  181. } else {
  182. echo '<pre>';
  183. echo "下单失败<br/>";
  184. print_r($response);
  185. }
  186. }
  187. //dada 城市code
  188. public function actionDadaCityCode()
  189. {
  190. $res = dada::getCityCode(0);
  191. util::success($res);
  192. }
  193. //理由
  194. public function actionDadaReasons()
  195. {
  196. $res = dada::getCancelReason(0);
  197. util::success($res);
  198. }
  199. //达达 :下单
  200. public function actionDadaAddOrder()
  201. {
  202. $orderSn = 'XSD_CS26316851';
  203. $orderInfo = OrderClass::getByOrderSn($orderSn);
  204. $res = DadaExpressServices::addOrder($orderInfo);
  205. util::success($res);
  206. }
  207. //重发快递
  208. public function actionDadaReAdd()
  209. {
  210. $orderSn = 'XSD_CS26316851';
  211. $orderInfo = OrderClass::getByOrderSn($orderSn);
  212. $res = DadaExpressServices::reAddOrder($orderInfo);
  213. util::success($res);
  214. }
  215. //达达状态查询
  216. public function actionDadaOrderStatus()
  217. {
  218. $orderSn = 'XSD_CS26316851';
  219. $res = DadaExpressServices::statusOrder($orderSn);
  220. util::success($res);
  221. }
  222. //达达取消下单
  223. public function actionDadaCancelOrder()
  224. {
  225. $orderSn = 'XSD_CS26316851';
  226. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  227. util::success($res);
  228. }
  229. //获取已支持的配送公司列表接口
  230. public function actionGetAllDelivery()
  231. {
  232. $data = MiniExpressService::getAllImmeDelivery();
  233. util::success($data);
  234. }
  235. //即时配送
  236. /*
  237. * Array
  238. (
  239. [resultcode] => 0
  240. [resultmsg] => OK
  241. [shop_list] => Array
  242. (
  243. [0] => Array
  244. (
  245. [shopid] => 1588714266
  246. [delivery_id] => SFTC
  247. [audit_result] => 0
  248. [create_time] => 1612172838
  249. [remark] =>
  250. [delivery_name] => 顺丰同城急送
  251. )
  252. )
  253. )
  254. */
  255. public function actionGetBindAccount()
  256. {
  257. $merchant = WxOpenClass::getGhsWxInfo();
  258. $isOpen = 2;
  259. $r = miniUtil::getBindAccount($merchant, $isOpen);
  260. dd($r);
  261. }
  262. //下单 (沙箱)
  263. /**
  264. * Array
  265. * (
  266. * [resultcode] => 0
  267. * [resultmsg] => ok
  268. * [fee] => 10
  269. * [waybill_id] => test_shop_id1612365974_waybillid
  270. * [order_status] => 101
  271. * [dispatch_duration] => 300
  272. * )
  273. */
  274. public function actionCreateWaybill()
  275. {
  276. $merchant = WxOpenClass::getGhsWxInfo();
  277. $isOpen = 2;
  278. $shopId = 'test_shop_id';
  279. $shopOrderId = 'test_shop_id' . time();
  280. $appSecret = 'test_app_secrect';
  281. $data = [
  282. 'shopid' => $shopId,
  283. 'shop_order_id' => $shopOrderId,
  284. 'shop_no' => '1',
  285. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  286. 'delivery_id' => "TEST",
  287. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  288. 'sender' => [
  289. 'name' => 'test',
  290. 'city' => '厦门市',
  291. 'address' => '思明区',
  292. 'address_detail' => '软件园二期',
  293. 'phone' => '19959271111',
  294. 'lng' => 118.134343,
  295. 'lat' => 24.483566,
  296. 'coordinate_type' => 0,
  297. ],
  298. 'receiver' => [
  299. 'name' => 'test',
  300. 'city' => '厦门市',
  301. 'address' => '思明区',
  302. 'address_detail' => '软件园二期',
  303. 'phone' => '19959271111',
  304. 'lng' => 118.134343,
  305. 'lat' => 24.493566,
  306. 'coordinate_type' => 0,
  307. ],
  308. 'cargo' => [
  309. 'goods_value' => 1,
  310. 'goods_weight' => 0.1,
  311. 'cargo_first_class' => '鲜花',
  312. 'cargo_second_class' => '鲜花',
  313. ],
  314. 'order_info' => [
  315. 'order_type' => 0,
  316. ],
  317. 'shop' => [
  318. 'wxa_path' => '/shop',
  319. 'img_url' => 'http://www.baidu.com/test.png',
  320. 'goods_name' => 'test',
  321. 'goods_count' => 1,
  322. ],
  323. ];
  324. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  325. dd($r);
  326. }
  327. //获取运单数据
  328. /**
  329. * Array
  330. * (
  331. * [resultcode] => 0
  332. * [resultmsg] => ok
  333. * [order_status] => 101
  334. * [agent_info] => Array
  335. * (
  336. * )
  337. *
  338. * [waybill_id] => test_shop_id1612365974_waybillid
  339. * [rider_name] =>
  340. * [rider_phone] =>
  341. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  342. * )
  343. */
  344. public function actionGetOrder()
  345. {
  346. $shopId = 'test_shop_id';
  347. $shopOrderId = 'test_shop_id1612365974';
  348. $appSecret = 'test_app_secrect';
  349. $merchant = WxOpenClass::getGhsWxInfo();
  350. $isOpen = 2;
  351. $data = [
  352. 'shopid' => $shopId,
  353. 'shop_order_id' => $shopOrderId,
  354. 'shop_no' => '1',
  355. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  356. ];
  357. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  358. dd($r);
  359. }
  360. //沙盒 更新快递状态
  361. public function actionMockUpdateOrder()
  362. {
  363. $merchant = WxOpenClass::getGhsWxInfo();
  364. $isOpen = 2;
  365. /**
  366. * {
  367. * "shopid": "test_shop_id",
  368. * "shop_order_id": "xxxxxxxxxxx",
  369. * "waybill_id": "xxxxxxxxxxxxx",
  370. * "action_time": 12345678,
  371. * "order_status": 101,
  372. * "action_msg": "",
  373. * }
  374. */
  375. $shopId = 'test_shop_id';
  376. $shopOrderId = 'test_shop_id1612365974';
  377. $data = [
  378. 'shop_order_id' => $shopOrderId,
  379. "shopid" => $shopId,
  380. "action_time" => time(),
  381. "order_status" => 302,
  382. 'action_msg' => '状态变更',
  383. ];
  384. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  385. dd($r);
  386. }
  387. public function actionTest()
  388. {
  389. }
  390. //新增订单
  391. public function actionAddOrder()
  392. {
  393. $dada = Yii::getAlias("@vendor/dada/");
  394. require_once $dada . 'api/addOrderApi.php';
  395. require_once $dada . 'client/dadaRequestClient.php';
  396. require_once $dada . 'client/dadaResponse.php';
  397. require_once $dada . 'config/config.php';
  398. require_once $dada . 'model/orderModel.php';
  399. // isOnline 判断是否是测试环境,会有不同的域名等
  400. $isOnline = false;
  401. $sourceId = 1000000;
  402. // 初始化一个config
  403. $config = new \Config($sourceId, $isOnline);
  404. $orderModel = new \OrderModel();
  405. $orderModel->setShopNo('11047059');
  406. $orderModel->setOriginId('2018091100000002');
  407. $orderModel->setCityCode('021');
  408. $orderModel->setCargoPrice(10);
  409. $orderModel->setIsPrepay(0);
  410. $orderModel->setReceiverName('测试达达');
  411. $orderModel->setReceiverAddress('上海市崇明岛');
  412. $orderModel->setReceiverLat(31.63);
  413. $orderModel->setReceiverLng(121.41);
  414. $orderModel->setReceiverPhone('18588888888');
  415. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  416. // api主要有2个参数,一个是url, 一个是业务参数
  417. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  418. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  419. $resp = $dada_client->makeRequest();
  420. echo json_encode($resp);
  421. }
  422. //订单详情查询
  423. public function actionOrderQuery()
  424. {
  425. $dada = Yii::getAlias("@vendor/dada/");
  426. require_once $dada . 'api/OrderQueryApi.php';
  427. require_once $dada . 'client/dadaRequestClient.php';
  428. require_once $dada . 'client/dadaResponse.php';
  429. require_once $dada . 'config/config.php';
  430. require_once $dada . 'model/orderModel.php';
  431. // isOnline 判断是否是测试环境,会有不同的域名等
  432. $isOnline = false;
  433. $sourceId = 1000000;
  434. // 初始化一个config
  435. $config = new \Config($sourceId, $isOnline);
  436. $orderModel = new \OrderModel();
  437. $orderModel->setOrderId('2018091100000002');
  438. // api主要有2个参数,一个是url, 一个是业务参数
  439. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  440. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  441. $resp = $dada_client->makeRequest();
  442. echo json_encode($resp);
  443. }
  444. public function actionFocus()
  445. {
  446. $name = '花卉宝';
  447. if (getenv('YII_ENV') == 'dev') {
  448. $name = '花美灵';
  449. }
  450. $merchant = MerchantService::getByCondition(['name' => $name]);
  451. $list = wxUtil::getSubscribeUserList($merchant);
  452. dd($list);
  453. }
  454. //宝贝售出提醒 ssh 2020.1.30
  455. public function actionInform()
  456. {
  457. $merchant = MerchantService::getMerchantById(12362);
  458. $order = OrderService::getById(214810);
  459. InformAdminClass::sendComplete($order);
  460. }
  461. public function actionNotice()
  462. {
  463. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  464. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  465. echo '<pre>';
  466. print_r($data);
  467. $msg = serialize($data);
  468. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  469. }
  470. }