TestController.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\sj\services\MerchantService;
  6. use biz\wx\classes\WxMessageClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\express\services\DadaExpressServices;
  9. use bizGhs\order\classes\OrderClass;
  10. use bizGhs\order\classes\RefundOrderClass;
  11. use bizHd\message\classes\InformAdminClass;
  12. use bizHd\order\services\OrderService;
  13. use bizHd\purchase\classes\PurchaseClass;
  14. use bizHd\purchase\classes\PurchaseClearClass;
  15. use bizHd\wx\classes\WxOpenClass;
  16. use bizGhs\express\services\MiniExpressService;
  17. use common\components\arrayUtil;
  18. use common\components\dict;
  19. use common\components\lakala\Lakala;
  20. use common\components\miniUtil;
  21. use common\components\noticeUtil;
  22. use common\components\orderSn;
  23. use common\components\wxUtil;
  24. use common\components\payUtil;
  25. use Yii;
  26. use common\components\util;
  27. class TestController extends BaseController
  28. {
  29. public $guestAccess = ['debt', 'apply', 'clear', 'ls-trade-query', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund'];
  30. //欠款的查询与跟踪 ssh 20240103
  31. public function actionDebt()
  32. {
  33. $customId = 591;
  34. $custom = CustomClass::getById($customId, true);
  35. if (empty($custom)) {
  36. echo '没有找到客户';
  37. die;
  38. }
  39. $ghsId = $custom->ghsId ?? 0;
  40. $ghs = GhsClass::getById($ghsId, true);
  41. $ghsShopId = $ghs->shopId ?? 0;
  42. $shop = ShopClass::getById($ghsShopId, true);
  43. $mainId = $shop->mainId ?? 0;
  44. $orderList = OrderClass::getAllByCondition(['customId' => $customId, 'debtPrice>' => 0], null, 'id,actPrice,payTime', null);
  45. $arr = [];
  46. if (!empty($orderList)) {
  47. foreach ($orderList as $order) {
  48. $payTime = $order['payTime'] ?? '';
  49. $arr[$payTime] = $order;
  50. }
  51. }
  52. $clearList = PurchaseClearClass::getAllByCondition(['ghsShopId' => $ghsShopId, 'status' => 2], null, 'actPrice,payTime', null);
  53. if (!empty($clearList)) {
  54. foreach ($clearList as $clear) {
  55. $payTime = $clear['payTime'] ?? '';
  56. $arr[$payTime] = $clear;
  57. }
  58. }
  59. $refundList = RefundOrderClass::getAllByCondition(['mainId' => $mainId], null, 'refundPrice,updateTime', null);
  60. if (!empty($refundList)) {
  61. foreach ($refundList as $refund) {
  62. $updateTime = $refund['updateTime'] ?? '';
  63. $arr[$updateTime] = $refund;
  64. }
  65. }
  66. echo "<pre>";
  67. ksort($arr);
  68. print_r($arr);
  69. }
  70. //退款操作 ssh 20231029
  71. public function actionRefund()
  72. {
  73. $shopId = 36524;
  74. $shop = ShopClass::getById($shopId, true);
  75. if (empty($shop)) {
  76. util::fail('没有找到门店');
  77. }
  78. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  79. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  80. $params = [
  81. 'appid' => 'OP00002119',
  82. 'serial_no' => '018b08cfddbd',
  83. 'merchant_no' => $shop->lklSjNo,
  84. 'term_no' => $shop->lklB2BTermNo,
  85. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  86. 'lklCertificatePath' => $lklCertificatePath,
  87. ];
  88. $laResource = new Lakala($params);
  89. $refundReason = '暂无';
  90. $refundOrderSn = orderSn::getCgRefundSn();
  91. $refundPrice = 0.01;
  92. $refundFee = bcmul($refundPrice, 100);
  93. $orderSn = 'KD_CS61235203';
  94. $originTradeNo = '20231030110113230266215266468756';
  95. //$originLogNo = '66215266025626';
  96. $aliParams = [
  97. 'refundSn' => $refundOrderSn,
  98. 'orderSn' => $orderSn,
  99. 'refundAmount' => $refundFee,
  100. 'refundReason' => $refundReason,
  101. 'originTradeNo' => $originTradeNo,
  102. //'originLogNo' => $originLogNo,
  103. ];
  104. $response = $laResource->refund($aliParams);
  105. echo '<pre>';
  106. print_r($response);
  107. }
  108. public function actionApply()
  109. {
  110. $id = 2888;
  111. $shopId = 36524;
  112. $cg = PurchaseClass::getById($id, true);
  113. $shop = ShopClass::getById($shopId, true);
  114. WxMessageClass::hdNewCgOrderInform($shop, $cg);
  115. }
  116. public function actionGet()
  117. {
  118. ini_set('memory_limit', '2045M');
  119. set_time_limit(0);
  120. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  121. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  122. $arr = [
  123. //['name' => '国兰花尚OK', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
  124. //['name' => '花掌柜OK', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
  125. //['name' => '纯彩花艺OK', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
  126. //['name' => '集美天天鲜花OK', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
  127. //['name' => '丰行花行OK', 'merchantNo' => '82260205992007P', 'wx' => [601053759, 601052157], 'zfb' => '2088820725885465'],
  128. //['name' => '独家花行OK', 'merchantNo' => '82239305992006Q', 'wx' => [601049483, 601048223], 'zfb' => '2088820725546555'],
  129. //['name' => '好多花海沧OK', 'merchantNo' => '82239305992006R', 'wx' => [601052177, 601053735], 'zfb' => '2088820725549695'],
  130. //['name' => '美天鲜花OK', 'merchantNo' => '82259505992003F', 'wx' => [601062064, 601138175], 'zfb' => '2088820729400990'],
  131. //['name' => '天天陈江店OK', 'merchantNo' => '82259505992003E', 'wx' => [601060616, 601059382], 'zfb' => '2088820725555368'],
  132. //['name' => '叶上花OK', 'merchantNo' => '82231805992002G', 'wx' => [601062892, 601062589], 'zfb' => '2088820728763546'],
  133. //['name' => '好又多(小明)OK', 'merchantNo' => '82239305992006S', 'wx' => [601135715, 601067347], 'zfb' => '2088820729698012'],
  134. //['name' => '我卖花OK', 'merchantNo' => '82227505992000R', 'wx' => [601177139, 601148755], 'zfb' => '2088820746424032'],
  135. //['name' => '问境OK', 'merchantNo' => '8226900599200KX', 'wx' => [601299388, 601299453], 'zfb' => '2088820787661843'],
  136. //['name' => '昱成OK', 'merchantNo' => '8226900599200KY', 'wx' => [601312993, 601325844], 'zfb' => '2088820788900240'],
  137. //['name' => '杭州斗南', 'merchantNo' => '杭州斗南', 'wx' => [601405963, 601405929], 'zfb' => '2088820793601705'],
  138. //['name' => '杭州斗南(没用)', 'merchantNo' => '8223310599200AD', 'wx' => [601254682, 601250805], 'zfb' => '2088820782666872'],
  139. //['name' => '珑松花卉长安店', 'merchantNo' => '82260205992007U', 'wx' => [602499045, 602497558], 'zfb' => '2088820959620797'],
  140. //['name' => '福州花福(个人)', 'merchantNo' => '82239105992007P', 'wx' => [603301197, 603302321], 'zfb' => '2088920058098261'],
  141. //['name' => '福州花福', 'merchantNo' => '82239105992007N', 'wx' => [602796807, 602774796], 'zfb' => '2088820996010582'],
  142. //['name' => '昆明新宏源', 'merchantNo' => '82239305992007H', 'wx' => [606098318, 606100317], 'zfb' => '2088920878302843'],
  143. //['name' => '昆明纯彩', 'merchantNo' => '82239905992003L', 'wx' => [604923629, 604922175], 'zfb' => '2088920533160795'],
  144. //['name' => '花优田(军兴旺)', 'merchantNo' => '8227310599200GX', 'wx' => [605191281, 605190492], 'zfb' => '2088920588715249'],
  145. ['name' => '广州国恋', 'merchantNo' => '8225810599200Q7', 'wx' => [612321716, 612320978], 'zfb' => '2088330479975012'],
  146. //['name' => '欣研鲜花', 'merchantNo' => '82260305992001Y', 'wx' => [612181234, 612181615], 'zfb' => '2088330365608286'],
  147. //['name' => '村长冷链', 'merchantNo' => '82260205992008G', 'wx' => [612168406, 612168000], 'zfb' => '2088330360870932'],
  148. //['name' => '惠州惠雅鲜花批发', 'merchantNo' => '82259505992003S', 'wx' => [611676975, 611677314], 'zfb' => '2088330136601427'],
  149. //['name' => '杭州斗南鲜花', 'merchantNo' => '8223310599200AR', 'wx' => [608955814, 608955082], 'zfb' => '2088130449323603'],
  150. //['name' => '营口简约花卉', 'merchantNo' => '8227310599200HJ', 'wx' => [608439898, 608440994], 'zfb' => '2088130112725929'],
  151. //['name' => '惠雅鲜花惠州店', 'merchantNo' => '82260205992007Z', 'wx' => [608406948, 608403207], 'zfb' => '2088130098167302'],
  152. //['name' => '云南珑松花卉珠海店', 'merchantNo' => '82258505992002U', 'wx' => [608062727, 608056474], 'zfb' => '2088030873238576'],
  153. //['name' => '买手很忙', 'merchantNo' => '8227310599200GJ', 'wx' => [601597167, 601595526], 'zfb' => '2088820818930267'],
  154. //['name' => '七彩花都', 'merchantNo' => '8227310599200GF', 'wx' => [601176481, 601148503], 'zfb' => '2088820748594478'],
  155. //['name' => '十年', 'merchantNo' => '82252305992001U', 'wx' => [601285154, 601261795], 'zfb' => '2088820782171763'],
  156. //['name' => '都市花季OK', 'merchantNo' => '82239305992006U', 'wx' => [601174342, 601147649], 'zfb' => '2088820748507346'],
  157. //['name' => '花样年华OK', 'merchantNo' => '82260205992007Q', 'wx' => [601134352, 601091710], 'zfb' => '2088820735043444'],
  158. //['name' => '精茂城OK', 'merchantNo' => '8225840599200TF', 'wx' => [601173752, 601143352], 'zfb' => '2088820746800005'],
  159. //['name' => '莱漫OK', 'merchantNo' => '82239305992007A', 'wx' => [601288494, 601288166], 'zfb' => '2088820783686611'],
  160. //['name' => '莱漫(没用)', 'merchantNo' => '82239305992006T', 'wx' => [601134065, 601125595], 'zfb' => '2088820743859918'],
  161. //['name' => '福州我要花OK', 'merchantNo' => '82239105992007J', 'wx' => [601134030, 601128111], 'zfb' => '2088820745276973'],
  162. //['name' => '泉城OK', 'merchantNo' => '82239705992004F', 'wx' => [601273270, 601272854], 'zfb' => '2088820784658561'],
  163. //['name' => '泉城(没用)', 'merchantNo' => '82239705992004E', 'wx' => [601133056, 601133821], 'zfb' => '2088820746111323'],
  164. //['name' => '美丽花行OK', 'merchantNo' => '82239305992006V', 'wx' => [601155249, 601149712], 'zfb' => '2088820747673312'],
  165. //['name' => '三叶OK', 'merchantNo' => '82236805992001Y', 'wx' => [601152233, 601151024], 'zfb' => '2088820747556725'],
  166. //['name' => '花大苪OK', 'merchantNo' => '8227310599200GG', 'wx' => [601174221, 601165136], 'zfb' => '2088820751181377'],
  167. //['name' => '十堰天天鲜花OK', 'merchantNo' => '82252305992001S', 'wx' => [601171131, 601170642], 'zfb' => '2088820750844626'],
  168. //['name' => '珑松花卉OK', 'merchantNo' => '82260205992007S', 'wx' => [601176093, 601174262], 'zfb' => '2088820754742492'],
  169. //['name' => '惠雅鲜花OK', 'merchantNo' => '82260205992007R', 'wx' => [601173390, 601174002], 'zfb' => '2088820753174540'],
  170. //['name' => '锦绣花卉OK', 'merchantNo' => '82252305992001T', 'wx' => [601176719, 601176660], 'zfb' => '2088820754751663'],
  171. //['name' => '祥瑞鲜花同安店OK', 'merchantNo' => '82239305992006W', 'wx' => [601178350, 601177795], 'zfb' => '2088820755715024'],
  172. //['name' => '祥瑞鲜花翔安店OK', 'merchantNo' => '82239305992006X', 'wx' => [601178260, 601178199], 'zfb' => '2088820754481553'],
  173. //['name' => '初见花季OK', 'merchantNo' => '82239305992006Y', 'wx' => [601178998, 601179605], 'zfb' => '2088820757223312'],
  174. //['name' => '荣发鲜花OK', 'merchantNo' => '82242705992000D', 'wx' => [601179681, 601179180], 'zfb' => '2088820756926593'],
  175. //['name' => '花千朵(多多)OK', 'merchantNo' => '82239305992006Z', 'wx' => [601223474, 601208096], 'zfb' => '2088820766783276'],
  176. //['name' => '花悠星OK', 'merchantNo' => '8225810599200NH', 'wx' => [601228194, 601227691], 'zfb' => '2088820774587446'],
  177. //['name' => '花悠星(没用)', 'merchantNo' => '8225810599200NG', 'wx' => [601223630, 601210952], 'zfb' => '2088820767072874'],
  178. //['name' => '源花汇OK', 'merchantNo' => '82222105992004A', 'wx' => [601221944, 601214269], 'zfb' => '2088820770594246'],
  179. //['name' => '源花汇2(没用)', 'merchantNo' => '8227310599200GD', 'wx' => [601136305, 601067016], 'zfb' => '2088820729832744'],
  180. ];
  181. $new = [];
  182. foreach ($arr as $item) {
  183. $wx = $item['wx'];
  184. $zfb = $item['zfb'];
  185. $merchantNo = $item['merchantNo'];
  186. $name = $item['name'] . ' ' . $merchantNo;
  187. $group = [];
  188. foreach ($wx as $oneWx) {
  189. $params = [
  190. 'appid' => 'OP00002119',
  191. 'serial_no' => '018b08cfddbd',
  192. 'merchant_no' => $merchantNo,
  193. 'term_no' => 'C6337694',
  194. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  195. 'lklCertificatePath' => $lklCertificatePath,
  196. ];
  197. $data = [
  198. 'subMerchantId' => $oneWx,
  199. 'tradeMode' => 'WECHAT',
  200. ];
  201. $laResource = new Lakala($params);
  202. $response = $laResource->openStateQuery($data);
  203. $statusName = '出错了';
  204. if ($response['retCode'] == '000000') {
  205. $checkResult = $response['respData']['checkResult'] ?? '';
  206. $statusName = '未认证';
  207. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
  208. $statusName = '已认证';
  209. }
  210. }
  211. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  212. }
  213. $params = [
  214. 'appid' => 'OP00002119',
  215. 'serial_no' => '018b08cfddbd',
  216. 'merchant_no' => $merchantNo,
  217. 'term_no' => 'C6337694',
  218. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  219. 'lklCertificatePath' => $lklCertificatePath,
  220. ];
  221. $data = [
  222. 'subMerchantId' => $zfb,
  223. 'tradeMode' => 'ALIPAY',
  224. ];
  225. $laResource = new Lakala($params);
  226. $response = $laResource->openStateQuery($data);
  227. $statusName = '出错了';
  228. if ($response['retCode'] == '000000') {
  229. $checkResult = $response['respData']['checkResult'] ?? '';
  230. $statusName = '未认证';
  231. if ($checkResult == 'AUTHORIZED') {
  232. $statusName = '已认证';
  233. }
  234. }
  235. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  236. $new[] = ['name' => $name, 'status' => $group];
  237. }
  238. echo '<pre>';
  239. print_r($new);
  240. die;
  241. }
  242. public function actionRefundQuery()
  243. {
  244. $shopId = 520;
  245. $shop = ShopClass::getById($shopId, true);
  246. if (empty($shop)) {
  247. util::stop('没有找到门店');
  248. }
  249. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  250. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  251. $params = [
  252. 'appid' => 'OP00002119',
  253. 'serial_no' => '018b08cfddbd',
  254. 'merchant_no' => $shop->lklSjNo,
  255. 'term_no' => $shop->lklScanTermNo,
  256. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  257. 'lklCertificatePath' => $lklCertificatePath,
  258. ];
  259. $laResource = new Lakala($params);
  260. $orderSn = '20231201110113131266165492618754';
  261. $data = [
  262. 'orderSn' => $orderSn,
  263. ];
  264. $response = $laResource->refundQuery($data);
  265. echo "<pre>";
  266. print_r($response);
  267. }
  268. public function actionBalanceQuery()
  269. {
  270. $shopId = 1212;
  271. $shop = ShopClass::getById($shopId, true);
  272. if (empty($shop)) {
  273. util::stop('没有找到门店');
  274. }
  275. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  276. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  277. $params = [
  278. 'appid' => 'OP00002119',
  279. 'serial_no' => '018b08cfddbd',
  280. 'merchant_no' => $shop->lklSjNo,
  281. 'term_no' => $shop->lklScanTermNo,
  282. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  283. 'lklCertificatePath' => $lklCertificatePath,
  284. ];
  285. $laResource = new Lakala($params);
  286. $response = $laResource->accountBalanceQuery();
  287. echo "<pre>";
  288. print_r($response);
  289. }
  290. //测试环境查线上数据 ssh 20231230
  291. public function actionCsQuery()
  292. {
  293. // $shopId = 1527;
  294. // $shop = ShopClass::getById($shopId, true);
  295. // if (empty($shop)) {
  296. // util::stop('没有找到门店');
  297. // }
  298. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  299. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  300. $params = [
  301. 'appid' => 'OP00002119',
  302. 'serial_no' => '018b08cfddbd',
  303. //'merchant_no' => $shop->lklSjNo,
  304. 'merchant_no' => '82222105992004A',
  305. //'term_no' => $shop->lklScanTermNo,
  306. 'term_no' => 'H3656802',
  307. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  308. 'lklCertificatePath' => $lklCertificatePath,
  309. ];
  310. $laResource = new Lakala($params);
  311. $queryParams = [
  312. //'orderSn' => 'KD26452235',
  313. 'tradeNo' => '20231230110113130266215700775011',
  314. ];
  315. $response = $laResource->query($queryParams, 1);
  316. echo "<pre>";
  317. print_r($response);
  318. }
  319. public function actionQuery()
  320. {
  321. // $shopId = 1527;
  322. // $shop = ShopClass::getById($shopId, true);
  323. // if (empty($shop)) {
  324. // util::stop('没有找到门店');
  325. // }
  326. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  327. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  328. $params = [
  329. 'appid' => 'OP00002119',
  330. 'serial_no' => '018b08cfddbd',
  331. //'merchant_no' => $shop->lklSjNo,
  332. 'merchant_no' => '82222105992004A',
  333. //'term_no' => $shop->lklScanTermNo,
  334. 'term_no' => 'H3656802',
  335. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  336. 'lklCertificatePath' => $lklCertificatePath,
  337. ];
  338. $laResource = new Lakala($params);
  339. $queryParams = [
  340. //'orderSn' => 'KD26452235',
  341. 'tradeNo' => '20231230110113130266215700775011',
  342. ];
  343. $response = $laResource->query($queryParams, 1);
  344. echo "<pre>";
  345. print_r($response);
  346. }
  347. //零售订单查询 ssh 20231031
  348. public function actionLsTradeQuery()
  349. {
  350. $shopId = 1422;
  351. $shop = ShopClass::getById($shopId, true);
  352. if (empty($shop)) {
  353. util::stop('没有找到门店');
  354. }
  355. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  356. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  357. $params = [
  358. 'appid' => 'OP00002119',
  359. 'serial_no' => '018b08cfddbd',
  360. 'merchant_no' => $shop->lklSjNo,
  361. 'term_no' => $shop->lklScanTermNo,
  362. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  363. 'lklCertificatePath' => $lklCertificatePath,
  364. ];
  365. $laResource = new Lakala($params);
  366. $queryParams = [
  367. 'orderSn' => 'KD26461864',
  368. //'tradeNo' => '20231029110113130266215259252887',
  369. ];
  370. $response = $laResource->query($queryParams, 0);
  371. print_r($response);
  372. util::stop();
  373. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  374. $connection = Yii::$app->db;
  375. $transaction = $connection->beginTransaction();
  376. try {
  377. $postData = $response['resp_data'] ?? [];
  378. $orderSn = $postData['out_trade_no'] ?? '';
  379. $total_amount = $postData['total_amount'] ?? 0;
  380. $account_type = $postData['account_type'] ?? '';
  381. if (empty($account_type)) {
  382. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  383. util::end();
  384. }
  385. $totalFee = $total_amount / 100;
  386. $transactionId = $postData['trade_no'] ?? 0;
  387. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  388. $currentPayWay = null;
  389. if ($account_type == 'WECHAT') {
  390. $currentPayWay = dict::getDict('payWay', 'wxPay');
  391. } elseif ($account_type == 'ALIPAY') {
  392. $currentPayWay = dict::getDict('payWay', 'alipay');
  393. } else {
  394. noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
  395. util::end();
  396. }
  397. $attach = '';
  398. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  399. $transaction->commit();
  400. echo 'OK';
  401. } catch (\Exception $e) {
  402. $transaction->rollBack();
  403. Yii::error("失败原因:" . $e->getMessage());
  404. }
  405. }
  406. }
  407. //零售订单查询 ssh 20231031
  408. public function actionClear()
  409. {
  410. $shopId = 10649;
  411. $shop = ShopClass::getById($shopId, true);
  412. if (empty($shop)) {
  413. util::stop('没有找到门店');
  414. }
  415. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  416. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  417. $params = [
  418. 'appid' => 'OP00002119',
  419. 'serial_no' => '018b08cfddbd',
  420. 'merchant_no' => $shop->lklSjNo,
  421. 'term_no' => $shop->lklScanTermNo,
  422. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  423. 'lklCertificatePath' => $lklCertificatePath,
  424. ];
  425. $laResource = new Lakala($params);
  426. $queryParams = [
  427. //'orderSn' => 'KD26461864',
  428. 'tradeNo' => '20231230110113130266215700775011',
  429. ];
  430. $response = $laResource->query($queryParams, 1);
  431. print_r($response);
  432. util::stop();
  433. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  434. $connection = Yii::$app->db;
  435. $transaction = $connection->beginTransaction();
  436. try {
  437. $postData = $response['resp_data'] ?? [];
  438. $orderSn = $postData['out_trade_no'] ?? '';
  439. $total_amount = $postData['total_amount'] ?? 0;
  440. $account_type = $postData['account_type'] ?? '';
  441. if (empty($account_type)) {
  442. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  443. util::end();
  444. }
  445. $totalFee = $total_amount / 100;
  446. $transactionId = $postData['trade_no'] ?? 0;
  447. $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id');
  448. $currentPayWay = null;
  449. if ($account_type == 'WECHAT') {
  450. $currentPayWay = dict::getDict('payWay', 'wxPay');
  451. } elseif ($account_type == 'ALIPAY') {
  452. $currentPayWay = dict::getDict('payWay', 'alipay');
  453. } else {
  454. noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
  455. util::end();
  456. }
  457. $attach = '';
  458. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  459. $transaction->commit();
  460. echo 'OK';
  461. } catch (\Exception $e) {
  462. $transaction->rollBack();
  463. Yii::error("失败原因:" . $e->getMessage());
  464. }
  465. }
  466. }
  467. //交易查询 ssh 20231021
  468. public function actionTradeQuery()
  469. {
  470. $shopId = 520;
  471. $shop = ShopClass::getById($shopId, true);
  472. if (empty($shop)) {
  473. util::stop('没有找到门店');
  474. }
  475. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  476. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  477. $params = [
  478. 'appid' => 'OP00002119',
  479. 'serial_no' => '018b08cfddbd',
  480. 'merchant_no' => $shop->lklSjNo,
  481. 'term_no' => $shop->lklScanTermNo,
  482. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  483. 'lklCertificatePath' => $lklCertificatePath,
  484. ];
  485. $laResource = new Lakala($params);
  486. $queryParams = [
  487. 'orderSn' => 'CG26741062',
  488. //'tradeNo' => '20231029110113130266215259252887',
  489. ];
  490. $response = $laResource->query($queryParams, 0);
  491. print_r($response);
  492. util::stop();
  493. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  494. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  495. $connection = Yii::$app->db;
  496. $transaction = $connection->beginTransaction();
  497. try {
  498. $account_type = $response['resp_data']['account_type'] ?? 0;
  499. if (empty($account_type)) {
  500. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意', '15280215347');
  501. util::end();
  502. }
  503. $currentPayWay = null;
  504. if ($account_type == 'WECHAT') {
  505. $currentPayWay = dict::getDict('payWay', 'wxPay');
  506. } elseif ($account_type == 'ALIPAY') {
  507. $currentPayWay = dict::getDict('payWay', 'alipay');
  508. } else {
  509. noticeUtil::push('支付回调失败了,没有找到支付类型', '15280215347');
  510. util::end();
  511. }
  512. $attach = '';
  513. $total_amount = $response['resp_data']['total_amount'] ?? 0;
  514. $orderSn = $response['resp_data']['out_trade_no'] ?? 0;
  515. $totalFee = $total_amount / 100;
  516. $transactionId = $response['resp_data']['trade_no'] ?? 0;
  517. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  518. $transaction->commit();
  519. echo 'OK';
  520. } catch (\Exception $e) {
  521. $transaction->rollBack();
  522. Yii::error("失败原因:" . $e->getMessage());
  523. }
  524. }
  525. }
  526. public function actionAliRun2()
  527. {
  528. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  529. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  530. $params = [
  531. 'appid' => 'OP00002119',
  532. 'serial_no' => '018b08cfddbd',
  533. 'merchant_no' => '82240505992000N',
  534. 'term_no' => 'C6337694',
  535. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  536. 'lklCertificatePath' => $lklCertificatePath,
  537. ];
  538. $outTradeNo = orderSn::getPurchaseSn();
  539. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  540. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  541. $aliParams = [
  542. 'orderSn' => $outTradeNo,
  543. 'amount' => 0.16,
  544. 'capitalType' => $currentCapitalType,
  545. 'notifyUrl' => $notifyUrl,
  546. ];
  547. $laResource = new Lakala($params);
  548. $response = $laResource->driveAliPay($aliParams);
  549. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  550. echo '<pre>';
  551. echo "下单成功<br/>";
  552. print_r($response);
  553. } else {
  554. echo '<pre>';
  555. echo "下单失败<br/>";
  556. print_r($response);
  557. }
  558. }
  559. public function actionAliRun3()
  560. {
  561. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  562. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  563. $params = [
  564. 'appid' => 'OP00002119',
  565. 'serial_no' => '018b08cfddbd',
  566. 'merchant_no' => '82240505992000N',
  567. 'term_no' => 'C6337694',
  568. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  569. 'lklCertificatePath' => $lklCertificatePath,
  570. ];
  571. $laResource = new Lakala($params);
  572. $outTradeNo = orderSn::getPurchaseSn();
  573. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  574. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  575. $wxParams = [
  576. 'orderSn' => $outTradeNo,
  577. 'amount' => 0.16,
  578. 'capitalType' => $currentCapitalType,
  579. 'notifyUrl' => $notifyUrl,
  580. ];
  581. $response = $laResource->driveWxPay($wxParams);
  582. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  583. echo '<pre>';
  584. echo "下单成功<br/>";
  585. print_r($response);
  586. } else {
  587. echo '<pre>';
  588. echo "下单失败<br/>";
  589. print_r($response);
  590. }
  591. }
  592. //dada 城市code
  593. public function actionDadaCityCode()
  594. {
  595. $res = dada::getCityCode(0);
  596. util::success($res);
  597. }
  598. //理由
  599. public function actionDadaReasons()
  600. {
  601. $res = dada::getCancelReason(0);
  602. util::success($res);
  603. }
  604. //达达 :下单
  605. public function actionDadaAddOrder()
  606. {
  607. $orderSn = 'XSD_CS26316851';
  608. $orderInfo = OrderClass::getByOrderSn($orderSn);
  609. $res = DadaExpressServices::addOrder($orderInfo);
  610. util::success($res);
  611. }
  612. //重发快递
  613. public function actionDadaReAdd()
  614. {
  615. $orderSn = 'XSD_CS26316851';
  616. $orderInfo = OrderClass::getByOrderSn($orderSn);
  617. $res = DadaExpressServices::reAddOrder($orderInfo);
  618. util::success($res);
  619. }
  620. //达达状态查询
  621. public function actionDadaOrderStatus()
  622. {
  623. $orderSn = 'XSD_CS26316851';
  624. $res = DadaExpressServices::statusOrder($orderSn);
  625. util::success($res);
  626. }
  627. //达达取消下单
  628. public function actionDadaCancelOrder()
  629. {
  630. $orderSn = 'XSD_CS26316851';
  631. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  632. util::success($res);
  633. }
  634. //获取已支持的配送公司列表接口
  635. public function actionGetAllDelivery()
  636. {
  637. $data = MiniExpressService::getAllImmeDelivery();
  638. util::success($data);
  639. }
  640. //即时配送
  641. /*
  642. * Array
  643. (
  644. [resultcode] => 0
  645. [resultmsg] => OK
  646. [shop_list] => Array
  647. (
  648. [0] => Array
  649. (
  650. [shopid] => 1588714266
  651. [delivery_id] => SFTC
  652. [audit_result] => 0
  653. [create_time] => 1612172838
  654. [remark] =>
  655. [delivery_name] => 顺丰同城急送
  656. )
  657. )
  658. )
  659. */
  660. public function actionGetBindAccount()
  661. {
  662. $merchant = WxOpenClass::getGhsWxInfo();
  663. $isOpen = 2;
  664. $r = miniUtil::getBindAccount($merchant, $isOpen);
  665. dd($r);
  666. }
  667. //下单 (沙箱)
  668. /**
  669. * Array
  670. * (
  671. * [resultcode] => 0
  672. * [resultmsg] => ok
  673. * [fee] => 10
  674. * [waybill_id] => test_shop_id1612365974_waybillid
  675. * [order_status] => 101
  676. * [dispatch_duration] => 300
  677. * )
  678. */
  679. public function actionCreateWaybill()
  680. {
  681. $merchant = WxOpenClass::getGhsWxInfo();
  682. $isOpen = 2;
  683. $shopId = 'test_shop_id';
  684. $shopOrderId = 'test_shop_id' . time();
  685. $appSecret = 'test_app_secrect';
  686. $data = [
  687. 'shopid' => $shopId,
  688. 'shop_order_id' => $shopOrderId,
  689. 'shop_no' => '1',
  690. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  691. 'delivery_id' => "TEST",
  692. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  693. 'sender' => [
  694. 'name' => 'test',
  695. 'city' => '厦门市',
  696. 'address' => '思明区',
  697. 'address_detail' => '软件园二期',
  698. 'phone' => '19959271111',
  699. 'lng' => 118.134343,
  700. 'lat' => 24.483566,
  701. 'coordinate_type' => 0,
  702. ],
  703. 'receiver' => [
  704. 'name' => 'test',
  705. 'city' => '厦门市',
  706. 'address' => '思明区',
  707. 'address_detail' => '软件园二期',
  708. 'phone' => '19959271111',
  709. 'lng' => 118.134343,
  710. 'lat' => 24.493566,
  711. 'coordinate_type' => 0,
  712. ],
  713. 'cargo' => [
  714. 'goods_value' => 1,
  715. 'goods_weight' => 0.1,
  716. 'cargo_first_class' => '鲜花',
  717. 'cargo_second_class' => '鲜花',
  718. ],
  719. 'order_info' => [
  720. 'order_type' => 0,
  721. ],
  722. 'shop' => [
  723. 'wxa_path' => '/shop',
  724. 'img_url' => 'http://www.baidu.com/test.png',
  725. 'goods_name' => 'test',
  726. 'goods_count' => 1,
  727. ],
  728. ];
  729. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  730. dd($r);
  731. }
  732. //获取运单数据
  733. /**
  734. * Array
  735. * (
  736. * [resultcode] => 0
  737. * [resultmsg] => ok
  738. * [order_status] => 101
  739. * [agent_info] => Array
  740. * (
  741. * )
  742. *
  743. * [waybill_id] => test_shop_id1612365974_waybillid
  744. * [rider_name] =>
  745. * [rider_phone] =>
  746. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  747. * )
  748. */
  749. public function actionGetOrder()
  750. {
  751. $shopId = 'test_shop_id';
  752. $shopOrderId = 'test_shop_id1612365974';
  753. $appSecret = 'test_app_secrect';
  754. $merchant = WxOpenClass::getGhsWxInfo();
  755. $isOpen = 2;
  756. $data = [
  757. 'shopid' => $shopId,
  758. 'shop_order_id' => $shopOrderId,
  759. 'shop_no' => '1',
  760. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  761. ];
  762. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  763. dd($r);
  764. }
  765. //沙盒 更新快递状态
  766. public function actionMockUpdateOrder()
  767. {
  768. $merchant = WxOpenClass::getGhsWxInfo();
  769. $isOpen = 2;
  770. /**
  771. * {
  772. * "shopid": "test_shop_id",
  773. * "shop_order_id": "xxxxxxxxxxx",
  774. * "waybill_id": "xxxxxxxxxxxxx",
  775. * "action_time": 12345678,
  776. * "order_status": 101,
  777. * "action_msg": "",
  778. * }
  779. */
  780. $shopId = 'test_shop_id';
  781. $shopOrderId = 'test_shop_id1612365974';
  782. $data = [
  783. 'shop_order_id' => $shopOrderId,
  784. "shopid" => $shopId,
  785. "action_time" => time(),
  786. "order_status" => 302,
  787. 'action_msg' => '状态变更',
  788. ];
  789. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  790. dd($r);
  791. }
  792. public function actionTest()
  793. {
  794. }
  795. //新增订单
  796. public function actionAddOrder()
  797. {
  798. $dada = Yii::getAlias("@vendor/dada/");
  799. require_once $dada . 'api/addOrderApi.php';
  800. require_once $dada . 'client/dadaRequestClient.php';
  801. require_once $dada . 'client/dadaResponse.php';
  802. require_once $dada . 'config/config.php';
  803. require_once $dada . 'model/orderModel.php';
  804. // isOnline 判断是否是测试环境,会有不同的域名等
  805. $isOnline = false;
  806. $sourceId = 1000000;
  807. // 初始化一个config
  808. $config = new \Config($sourceId, $isOnline);
  809. $orderModel = new \OrderModel();
  810. $orderModel->setShopNo('11047059');
  811. $orderModel->setOriginId('2018091100000002');
  812. $orderModel->setCityCode('021');
  813. $orderModel->setCargoPrice(10);
  814. $orderModel->setIsPrepay(0);
  815. $orderModel->setReceiverName('测试达达');
  816. $orderModel->setReceiverAddress('上海市崇明岛');
  817. $orderModel->setReceiverLat(31.63);
  818. $orderModel->setReceiverLng(121.41);
  819. $orderModel->setReceiverPhone('18588888888');
  820. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  821. // api主要有2个参数,一个是url, 一个是业务参数
  822. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  823. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  824. $resp = $dada_client->makeRequest();
  825. echo json_encode($resp);
  826. }
  827. //订单详情查询
  828. public function actionOrderQuery()
  829. {
  830. $dada = Yii::getAlias("@vendor/dada/");
  831. require_once $dada . 'api/OrderQueryApi.php';
  832. require_once $dada . 'client/dadaRequestClient.php';
  833. require_once $dada . 'client/dadaResponse.php';
  834. require_once $dada . 'config/config.php';
  835. require_once $dada . 'model/orderModel.php';
  836. // isOnline 判断是否是测试环境,会有不同的域名等
  837. $isOnline = false;
  838. $sourceId = 1000000;
  839. // 初始化一个config
  840. $config = new \Config($sourceId, $isOnline);
  841. $orderModel = new \OrderModel();
  842. $orderModel->setOrderId('2018091100000002');
  843. // api主要有2个参数,一个是url, 一个是业务参数
  844. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  845. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  846. $resp = $dada_client->makeRequest();
  847. echo json_encode($resp);
  848. }
  849. public function actionFocus()
  850. {
  851. $name = '花卉宝';
  852. if (getenv('YII_ENV') == 'dev') {
  853. $name = '花美灵';
  854. }
  855. $merchant = MerchantService::getByCondition(['name' => $name]);
  856. $list = wxUtil::getSubscribeUserList($merchant);
  857. dd($list);
  858. }
  859. //宝贝售出提醒 ssh 2020.1.30
  860. public function actionInform()
  861. {
  862. $merchant = MerchantService::getMerchantById(12362);
  863. $order = OrderService::getById(214810);
  864. InformAdminClass::sendComplete($order);
  865. }
  866. public function actionNotice()
  867. {
  868. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  869. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  870. echo '<pre>';
  871. print_r($data);
  872. $msg = serialize($data);
  873. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  874. }
  875. }