TestController.php 13 KB

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