TestController.php 12 KB

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