TestController.php 20 KB

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