SecurityCodeRecord.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\user\member;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\user\member\SecurityCodeRecordServices;
  14. use app\services\user\member\SecurityCategoryServices;
  15. use crmeb\services\FileService;
  16. use think\facade\App;
  17. /**
  18. * Class MemberCard
  19. * @package app\adminapi\controller\v1\user\member
  20. */
  21. class SecurityCodeRecord extends AuthController
  22. {
  23. /**
  24. * 初始化service层句柄
  25. * MemberCard constructor.
  26. * @param App $app
  27. * @param MemberCardServices $memberCardServices
  28. */
  29. public function __construct(App $app, SecurityCodeRecordServices $securityCodeRecordServices)
  30. {
  31. parent::__construct($app);
  32. $this->services = $securityCodeRecordServices;
  33. }
  34. /**
  35. * 防伪码列表
  36. * @param $card_batch_id
  37. * @return mixed
  38. */
  39. public function list()
  40. {
  41. $where = $this->request->getMore([
  42. ['category_id', ""],
  43. ['security_code', ""],
  44. ['scan_uid', ""],
  45. ['status', ""],
  46. ['page', 1],
  47. ['limit', 20],
  48. ]);
  49. $data = $this->services->getSearchList($where);
  50. return app('json')->success($data);
  51. }
  52. /**
  53. * 会员分类
  54. * @return mixed
  55. */
  56. public function member_ship()
  57. {
  58. /** @var MemberShipServices $memberShipService */
  59. $memberShipService = app()->make(MemberShipServices::class);
  60. $data = $memberShipService->getSearchList();
  61. return app('json')->success($data);
  62. }
  63. /**
  64. * 保存
  65. * @param $id
  66. * @param MemberShipServices $memberShipServices
  67. * @return mixed
  68. */
  69. public function save($id, SecurityCodeRecordServices $securityCodeRecordServices)
  70. {
  71. $data = $this->request->postMore([
  72. ['category_id', ''],
  73. ['security_code', ''],
  74. ['wx_url', '']
  75. ]);
  76. $securityCodeRecordServices->save((int)$id, $data);
  77. return app('json')->success($id ? 100001 : 100021);
  78. }
  79. /**
  80. * 删除
  81. * @param $id
  82. * @throws \Exception
  83. */
  84. public function delete()
  85. {
  86. list($id) = $this->request->getMore([
  87. ['id', 0],
  88. ], true);
  89. if (!$id) return app('json')->fail(100100);
  90. $this->services->delCode((int)$id);
  91. return app('json')->success(100002);
  92. }
  93. /**
  94. * 导入
  95. * @return \think\Response|void
  96. * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
  97. */
  98. public function import()
  99. {
  100. [$file] = $this->request->getMore([
  101. ['file', '']
  102. ], true);
  103. if (!$file) return app('json')->fail(400168);
  104. $file = public_path() . substr($file, 1);
  105. $expressData = app()->make(FileService::class)->readExcel($file, 'securityCode', 2);
  106. foreach ($expressData as $item) {
  107. $this->services->save(0, $item);
  108. }
  109. return app('json')->success('批量发货成功');
  110. }
  111. }