TestController.php 41 KB

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