TestController.php 39 KB

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