TestController.php 13 KB

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