Card.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. namespace app\admin\controller\index;
  3. use app\admin\controller\BaseController;
  4. use app\admin\server\index\CardServer;
  5. use support\Request;
  6. use support\Db;
  7. use app\admin\model\User;
  8. use app\admin\server\sms\VerificationCodeServer;
  9. use app\admin\server\payment\UnionOrder;
  10. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  11. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  12. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  13. /**
  14. * 储值卡接口
  15. * Class Users
  16. * @package app\api\controller\user
  17. */
  18. class Card extends BaseController
  19. {
  20. /**
  21. * Notes:获取会员账户
  22. * @return \support\Response
  23. * User: yym
  24. * Date: 2022/7/26
  25. */
  26. public function getCardList()
  27. {
  28. $mobile = $this->request->get('mobile');
  29. $core_member_id = "";
  30. /*
  31. $core_member_id = DB::table('user')->where('user_account',$mobile)->value('core_member_id');
  32. if(empty($core_member_id)){
  33. throw new \Exception('会员未绑定核心库');
  34. }
  35. */
  36. $result = CardServer::getCardList($core_member_id,$mobile);
  37. return $result;
  38. }
  39. /**
  40. * Notes:会员绑定卡
  41. * @return \support\Response
  42. * User: ycp
  43. * Date: 2023/5/4
  44. */
  45. public function userBindCard()
  46. {
  47. $mobile = $this->request->post('mobile');
  48. $core_member_id = DB::table('user')->where('user_account',$mobile)->value('core_member_id');
  49. if(empty($core_member_id)){
  50. throw new \Exception('会员未绑定核心库');
  51. }
  52. $cardno = $this->request->post('cardno');
  53. $cardpswd = $this->request->post('cardpswd');
  54. $cardmonies = $this->request->post('cardmonies',0);
  55. $cardadded = $this->request->post('cardadded',0);
  56. $card_oct = substr($cardno, 15, 3);
  57. /* 八进制转十进制 */
  58. $card_dec = octdec((int)$card_oct);
  59. /* verifycode */
  60. $verifycode = md5($cardno . $cardpswd . $card_dec . ".YXJ");
  61. $result4 = CardServer::memberBindCard($cardno,$verifycode,$cardpswd,$cardmonies,$cardadded,$core_member_id);
  62. $result = json_decode($result4,true);
  63. if($result['errorcode'] == 313)
  64. {
  65. throw new \Exception("不能绑定同类型的卡");
  66. }
  67. if($result['errorcode'] == 312)
  68. {
  69. throw new \Exception("卡不存在或已被使用");
  70. }
  71. return json_success($result, '绑定成功');
  72. }
  73. /**
  74. * Notes:会员账户出入帐
  75. * @return \support\Response
  76. * User: yym
  77. * Date: 2022/7/26
  78. */
  79. public function memberAccountPay()
  80. {
  81. $mobile = $this->request->post('mobile');
  82. $core_member_id = DB::table('user')->where('user_account',$mobile)->value('core_member_id');
  83. if(empty($core_member_id)){
  84. throw new \Exception('会员未绑定核心库');
  85. }
  86. $cardno = $this->request->post('cardno');
  87. $orderno = $this->request->post('orderno');
  88. $io = $this->request->post('io');
  89. $expenses = $this->request->post('expenses');
  90. $added = $this->request->post('added',0);
  91. $detail = $this->request->post('detail','');
  92. $result = CardServer::memberAccountPay($core_member_id,$cardno,$orderno,$io,$expenses,$added,$detail);
  93. return $result;
  94. }
  95. /**
  96. * Notes:卡品种列表
  97. * @return \support\Response
  98. * User: ycp
  99. * Date: 2023/8/7
  100. */
  101. public function cardMainCategoryList()
  102. {
  103. $result = CardServer::cardMainCategoryList();
  104. return $result;
  105. }
  106. /**
  107. * Notes:添加卡品种
  108. * @return \support\Response
  109. * User: ycp
  110. * Date: 2023/8/7
  111. */
  112. public function cardMainCategoryAdd()
  113. {
  114. $card_main_category_name = $this->request->get('card_main_category_name');
  115. $result = CardServer::cardMainCategoryAdd($card_main_category_name);
  116. return $result;
  117. }
  118. /**
  119. * Notes:删除卡品种
  120. * @return \support\Response
  121. * User: ycp
  122. * Date: 2023/8/7
  123. */
  124. public function cardMainCategoryDel()
  125. {
  126. $card_main_category_name = $this->request->get('card_main_category_name');
  127. $result = CardServer::cardMainCategoryDel($card_main_category_name);
  128. return $result;
  129. }
  130. /**
  131. * Notes:编辑卡品种
  132. * @return \support\Response
  133. * User: ycp
  134. * Date: 2023/8/7
  135. */
  136. public function cardMainCategoryUpd()
  137. {
  138. $card_main_category_name = $this->request->get('card_main_category_name');
  139. $card_main_category_configs = $this->request->get('card_main_category_configs','&');
  140. $card_main_category_addtimes = $this->request->get('card_main_category_addtimes',1);
  141. $result = CardServer::cardMainCategoryUpd($card_main_category_name,$card_main_category_configs,$card_main_category_addtimes);
  142. //var_dump(http_build_query($result));
  143. return $result;
  144. }
  145. /**
  146. * Notes:卡品种列表
  147. * @return \support\Response
  148. * User: ycp
  149. * Date: 2023/8/7
  150. */
  151. public function cardMainList()
  152. {
  153. $card_main_category = $this->request->get('card_main_category');
  154. $result = CardServer::cardMainList($card_main_category);
  155. return $result;
  156. }
  157. /**
  158. * Notes:储值卡-卡分类-创建[C]
  159. * @return \support\Response
  160. * User: ycp
  161. * Date: 2023/8/7
  162. */
  163. public function cardMainAdd()
  164. {
  165. $card_main_status = $this->request->get('card_main_category_configs','ACTIVED');
  166. $card_main_name = $this->request->get('card_main_name');
  167. $card_main_category = $this->request->get('card_main_category');
  168. $card_main_validday = $this->request->get('card_main_validday',0);
  169. $card_main_configs = $this->request->get('card_main_configs','&');
  170. $result = CardServer::cardMainAdd($card_main_status,$card_main_name,$card_main_category,$card_main_validday,$card_main_configs);
  171. return $result;
  172. }
  173. /**
  174. * Notes:编辑卡分类
  175. * @return \support\Response
  176. * User: ycp
  177. * Date: 2023/8/7
  178. */
  179. public function cardMainUpd()
  180. {
  181. $card_main_id = $this->request->get('card_main_id');
  182. $card_main_status = $this->request->get('card_main_status','ACTIVED');
  183. $card_main_name = $this->request->get('card_main_name');
  184. $card_main_category = $this->request->get('card_main_category');
  185. $card_main_validday = $this->request->get('card_main_validday',1);
  186. $card_main_configs = $this->request->get('card_main_configs',1);
  187. $result = CardServer::cardMainUpd($card_main_id,$card_main_status,$card_main_name,$card_main_category,$card_main_validday,$card_main_configs);
  188. return $result;
  189. }
  190. /**
  191. * Notes:删除卡品种
  192. * @return \support\Response
  193. * User: ycp
  194. * Date: 2023/8/7
  195. */
  196. public function cardMainDel()
  197. {
  198. $card_main_id = $this->request->get('card_main_id');
  199. $result = CardServer::cardMainDel($card_main_id);
  200. return $result;
  201. }
  202. /**
  203. * Notes:储值卡-卡台账-创建[批量]
  204. * @return \support\Response
  205. * User: ycp
  206. * Date: 2023/8/7
  207. */
  208. public function cardListAddBatch()
  209. {
  210. $url = "http://core.wanyuewellness.cn/api.php";
  211. $params['func'] = "functions.funcCardListAddBatch";
  212. $params['card_city'] = $this->request->get('card_city','370100');
  213. $params['card_main_id'] = $this->request->get('card_main_id');
  214. $params['card_status'] = $this->request->get('card_status','ACTIVED');
  215. $params['card_batchcode'] = $this->request->get('card_batchcode');
  216. $params['card_def_monies'] = $this->request->get('card_def_monies',0);
  217. $params['card_num'] = $this->request->get('card_num');
  218. $result = curlPost($url,$params);
  219. return $result;
  220. }
  221. /**
  222. * Notes:储值卡-卡台账-创建
  223. * @return \support\Response
  224. * User: ycp
  225. * Date: 2023/8/7
  226. */
  227. public function cardListAdd()
  228. {
  229. $url = "http://core.wanyuewellness.cn/api.php";
  230. $params['func'] = "functions.funcCardListAdd";
  231. $params['card_no'] = $this->request->get('card_no');
  232. $params['card_no_chip'] = $this->request->get('card_no_chip');
  233. $params['join_card_main_id'] = $this->request->get('join_card_main_id');
  234. $params['card_status'] = $this->request->get('card_status','INIT');
  235. $params['card_pswd'] = $this->request->get('card_pswd','123456');
  236. $params['card_def_monies'] = $this->request->get('card_def_monies',0);
  237. $params['card_qrcode'] = $this->request->get('card_qrcode');
  238. $params['card_batchcode'] = $this->request->get('card_batchcode');
  239. $params['card_extend'] = $this->request->get('card_extend');
  240. $params['card_addtimes'] = time();
  241. $result = curlPost($url,$params);
  242. return $result;
  243. }
  244. /**
  245. * Notes:储值卡-卡台账-编辑
  246. * @return \support\Response
  247. * User: ycp
  248. * Date: 2023/8/7
  249. */
  250. public function cardListUpd()
  251. {
  252. $url = "http://core.wanyuewellness.cn/api.php";
  253. $data['card_no'] = $this->request->get('card_no');
  254. $data['card_no_chip'] = $this->request->get('card_no_chip');
  255. $data['join_card_main_id'] = $this->request->get('join_card_main_id');
  256. $data['card_status'] = $this->request->get('card_status','INIT');
  257. $data['card_pswd'] = $this->request->get('card_pswd','123456');
  258. $data['card_def_monies'] = $this->request->get('card_def_monies',0);
  259. $data['card_qrcode'] = $this->request->get('card_qrcode');
  260. $data['card_batchcode'] = $this->request->get('card_batchcode');
  261. $data['card_extend'] = $this->request->get('card_extend');
  262. $data['card_addtimes'] = time();
  263. $params['func'] = "functions.funcCardListUpd";
  264. $params['where'] = $this->request->get('where');
  265. $params['card_no'] = $this->request->get('card_no');
  266. $params['data'] = $data;
  267. $result = curlPost($url,json_encode($params));
  268. return $result;
  269. }
  270. /**
  271. * Notes:储值卡-卡台账-创建
  272. * @return \support\Response
  273. * User: ycp
  274. * Date: 2023/8/7
  275. */
  276. public function cardListDel()
  277. {
  278. $url = "http://core.wanyuewellness.cn/api.php";
  279. $params['func'] = "functions.funcCardListDel";
  280. $params['card_no'] = $this->request->get('card_no');
  281. $params['where'] = $this->request->get('where');
  282. $result = curlPost($url,$params);
  283. return $result;
  284. }
  285. /**
  286. * Notes:储值卡-卡台账-读取[R]
  287. * @return \support\Response
  288. * User: ycp
  289. * Date: 2023/8/7
  290. */
  291. public function cardListList()
  292. {
  293. $url = "http://core.wanyuewellness.cn/api.php";
  294. $params['func'] = "functions.funcCardListList";
  295. if($this->request->get('card_no') != ''){
  296. $params['card_no'] = $this->request->get('card_no');
  297. }
  298. if($this->request->get('join_card_main_id') != ''){
  299. $params['join_card_main_id'] = $this->request->get('join_card_main_id');
  300. }
  301. if($this->request->get('card_main_category') != ''){
  302. $params['card_main_category'] = $this->request->get('card_main_category');
  303. }
  304. if($this->request->get('pageno')){
  305. $params['pageno'] = $this->request->get('pageno');
  306. }else{
  307. $params['pageno'] = 1;
  308. }
  309. $result = curlPost($url,$params);
  310. return $result;
  311. }
  312. /**
  313. * Notes:储值卡-卡动作-创建[U]
  314. * @return \support\Response
  315. * User: ycp
  316. * Date: 2023/8/7
  317. */
  318. public function cardActionAdd()
  319. {
  320. $url = "http://core.wanyuewellness.cn/api.php";
  321. $params['func'] = "functions.funcCardActionAdd";
  322. $params['card_action_status'] = $this->request->get('card_action_status');
  323. $params['card_action_category'] = $this->request->get('card_action_category');
  324. $params['card_action_name'] = $this->request->get('card_action_name');
  325. $params['card_action_code'] = $this->request->get('card_action_code');
  326. $params['join_action_card_main_id'] = $this->request->get('join_action_card_main_id');
  327. $params['card_action_user_name'] = $this->request->get('card_action_user_name');
  328. $params['card_action_apply_user_name'] = $this->request->get('card_action_apply_user_name');
  329. $params['card_action_apply_orgi_name'] = $this->request->get('card_action_apply_orgi_name');
  330. $params['card_action_apply_count'] = $this->request->get('card_action_apply_count');
  331. $params['card_action_apply_content'] = $this->request->get('card_action_apply_content');
  332. $params['card_action_apply_extend'] = $this->request->get('card_action_apply_extend');
  333. $params['cardcard_action_result_no'] = $this->request->get('card_action_result');
  334. $params['card_action_result_count'] = $this->request->get('card_action_result_count');
  335. $result = curlPost($url,$params);
  336. return $result;
  337. }
  338. /**
  339. * Notes:储值卡-卡动作-创建[U]
  340. * @return \support\Response
  341. * User: ycp
  342. * Date: 2023/8/7
  343. */
  344. public function cardActionUpd()
  345. {
  346. $url = "http://core.wanyuewellness.cn/api.php";
  347. $data['card_action_status'] = $this->request->get('card_action_status');
  348. $data['card_action_category'] = $this->request->get('card_action_category');
  349. $data['card_action_name'] = $this->request->get('card_action_name');
  350. $data['card_action_code'] = $this->request->get('card_action_code');
  351. $data['join_action_card_main_id'] = $this->request->get('join_action_card_main_id');
  352. $data['card_action_user_name'] = $this->request->get('card_action_user_name');
  353. $data['card_action_apply_user_name'] = $this->request->get('card_action_apply_user_name');
  354. $data['card_action_apply_orgi_name'] = $this->request->get('card_action_apply_orgi_name');
  355. $data['card_action_apply_count'] = $this->request->get('card_action_apply_count');
  356. $data['card_action_apply_content'] = $this->request->get('card_action_apply_content');
  357. $data['card_action_apply_extend'] = $this->request->get('card_action_apply_extend');
  358. $data['cardcard_action_result_no'] = $this->request->get('card_action_result');
  359. $data['card_action_result_count'] = $this->request->get('card_action_result_count');
  360. $params['func'] = "functions.funcCardActionUpd";
  361. $params['card_action_id'] = $this->request->get('card_action_id');
  362. $params['data'] = $data;
  363. $result = curlPost($url,json_encode($params));
  364. return $result;
  365. }
  366. /**
  367. * Notes:储值卡-卡动作-读取[R]
  368. * @return \support\Response
  369. * User: ycp
  370. * Date: 2023/8/7
  371. */
  372. public function cardActionList()
  373. {
  374. $url = "http://core.wanyuewellness.cn/api.php";
  375. $params['func'] = "functions.funcCardActionList";
  376. $params['card_action_id'] = $this->request->get('card_action_id');
  377. $result = curlPost($url,$params);
  378. return $result;
  379. }
  380. /**
  381. * Notes:储值卡-卡动作-删除[D]
  382. * @return \support\Response
  383. * User: ycp
  384. * Date: 2023/8/7
  385. */
  386. public function cardActionDel()
  387. {
  388. $url = "http://core.wanyuewellness.cn/api.php";
  389. $params['func'] = "functions.funcCardActionDel";
  390. $params['card_action_id'] = $this->request->get('card_action_id');
  391. $result = curlPost($url,$params);
  392. return $result;
  393. }
  394. /**
  395. * Notes:储值卡-卡动作-执行[X]
  396. * @return \support\Response
  397. * User: ycp
  398. * Date: 2023/8/7
  399. */
  400. public function cardActionExecute()
  401. {
  402. $url = "http://core.wanyuewellness.cn/api.php";
  403. $params['func'] = "functions.funcCardActionExecute";
  404. $params['card_action_id'] = $this->request->get('card_action_id');
  405. $params['card_action_card_no'] = $this->request->get('card_action_card_no','');
  406. $params['card_action_api'] = $this->request->get('card_action_api','{"type":"", "process":""}');
  407. $result = curlPost($url,$params);
  408. return $result;
  409. }
  410. /**
  411. * Notes:储值卡-卡动作明细-创建[C]
  412. * @return \support\Response
  413. * User: ycp
  414. * Date: 2023/8/7
  415. */
  416. public function cardActionDetailAdd()
  417. {
  418. $url = "http://core.wanyuewellness.cn/api.php";
  419. $params['func'] = "functions.funcCardActionDetailAdd";
  420. $params['join_card_action_id'] = $this->request->get('join_card_action_id');
  421. $params['card_action_card_no'] = $this->request->get('card_action_card_no');
  422. $result = curlPost($url,$params);
  423. return $result;
  424. }
  425. /**
  426. * Notes:储值卡-卡动作明细-编辑[C]
  427. * @return \support\Response
  428. * User: ycp
  429. * Date: 2023/8/7
  430. */
  431. public function cardActionDetailUpd()
  432. {
  433. $url = "http://core.wanyuewellness.cn/api.php";
  434. $data['join_card_action_id'] = $this->request->get('join_card_action_id');
  435. $data['card_action_card_no'] = $this->request->get('card_action_card_no');
  436. $params['func'] = "functions.funcCardActionDetailUpd";
  437. $params['card_action_detail_id'] = $this->request->get('card_action_detail_id');
  438. $params['data'] = $data;
  439. $result = curlPost($url,json_encode($params));
  440. return $result;
  441. }
  442. /**
  443. * Notes:储值卡-卡动作明细-读取[C]
  444. * @return \support\Response
  445. * User: ycp
  446. * Date: 2023/8/7
  447. */
  448. public function cardActionDetailList()
  449. {
  450. $url = "http://core.wanyuewellness.cn/api.php";
  451. $params['func'] = "functions.funcCardActionDetailList";
  452. $params['join_card_action_id'] = $this->request->get('join_card_action_id');
  453. $result = curlPost($url,$params);
  454. return $result;
  455. }
  456. /**
  457. * Notes:储值卡-卡动作明细-删除[C]
  458. * @return \support\Response
  459. * User: ycp
  460. * Date: 2023/8/7
  461. */
  462. public function cardActionDetailDel()
  463. {
  464. $url = "http://core.wanyuewellness.cn/api.php";
  465. $params['func'] = "functions.funcCardActionDetailDel";
  466. $params['card_action_detail_id'] = $this->request->get('card_action_detail_id');
  467. $result = curlPost($url,$params);
  468. return $result;
  469. }
  470. /**
  471. * Notes:批量导入储值卡芯片码
  472. * @return \support\Response
  473. * @throws \Exception
  474. * User: YCP
  475. * Date: 2023/8/11
  476. */
  477. public function cardImport()
  478. {
  479. $excel_address = $this->request->get('excel_address');//文件地址;
  480. $admin_id = $this->request->admin_id;
  481. require_once 'vendor/phpoffice/phpexcel/Classes/PHPExcel.php';
  482. require_once 'vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
  483. $objPHPExcel = \PHPExcel_IOFactory::load($excel_address);
  484. // 逐行读取 sheet 内的内容(常用)
  485. foreach ($objPHPExcel->getworksheetiterator() as $sheet){ //循环sheet
  486. foreach ($sheet->getrowiterator() as $row){ //循环row
  487. if ($row->getrowindex() < 2){ // 默认从第二行开始
  488. continue;
  489. }
  490. foreach ($row->getcelliterator() as $cell){ //循环cell
  491. $data[] = $cell->getvalue();
  492. }
  493. if(!empty($data)){
  494. $params['card_no_chip'] = $data[0];
  495. $result = DB::connection('mysql2')->table('tbl__core_card_list')->where(['card_no' => $data[1]])->update($params);
  496. if (!empty($result)){
  497. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '导入储值卡芯片码-编号: ' . $result;
  498. plog('user-card-update', '储值卡-导入芯片码', $msg);
  499. }
  500. unset($data);
  501. }else{
  502. throw new \Exception('读取失败');
  503. }
  504. }
  505. }
  506. return json_success($excel_address, '导入成功');
  507. }
  508. }