TestController.php 10.0 KB

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