GiveOutCoupon.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\controller;
  13. use app\store\model\GiveOutCoupon as GiveOutCouponModel;
  14. use app\store\model\store\UserRole;
  15. use app\store\service\store\Role as StoreRoleService;
  16. use PhpOffice\PhpSpreadsheet\Reader\Xls;
  17. use think\cache\driver\Redis;
  18. use think\facade\Filesystem;
  19. /**
  20. * 申请分销员
  21. * Class Setting
  22. * @package app\store\controller
  23. */
  24. class GiveOutCoupon extends Controller
  25. {
  26. /**
  27. * 申请列表
  28. * @return array
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function list()
  34. {
  35. $cs = request()->get();
  36. $m = new GiveOutCouponModel();
  37. $list = $m->getList($cs);
  38. return $this->renderSuccess(compact('list'));
  39. }
  40. /**
  41. * 详情
  42. * @param $id
  43. * @return array
  44. */
  45. public function details($id)
  46. {
  47. $m = new GiveOutCouponModel();
  48. $list = $m->detail($id);
  49. return $this->renderSuccess(compact('list'));
  50. }
  51. /**
  52. * 创建
  53. * @return array
  54. */
  55. public function create()
  56. {
  57. // 保存商城设置
  58. $model = new GiveOutCouponModel();
  59. $params = $this->postForm();
  60. $params['create_admin_id'] =$this->store['user']['store_user_id'];
  61. if ($model->add($params )) {
  62. return $this->renderSuccess('操作成功');
  63. }
  64. return $this->renderError($model->getError() ?: '操作失败');
  65. }
  66. /**
  67. * 审核
  68. * @return array
  69. */
  70. public function audit(){
  71. $params = request()->get();
  72. $params['audit_user_id'] =$this->store['user']['store_user_id'];
  73. $params['audit_time'] = date('Y-m-d H:i:s');
  74. $model = new GiveOutCouponModel();
  75. if ($model->audit($params)) {
  76. return $this->renderSuccess('操作成功');
  77. }
  78. return $this->renderError($model->getError() ?: '操作失败');
  79. }
  80. /**
  81. * 上传文件
  82. * @return array|false
  83. * @throws \PhpOffice\PhpSpreadsheet\Exception
  84. * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
  85. */
  86. public function uploadMobiles(){
  87. // 获取表单上传文件 例如上传了001.jpg
  88. $file = request()->file('iFile');
  89. // 上传到本地服务器
  90. $savename = Filesystem::putFile( 'topic', $file);
  91. $fileName = runtime_root_path().'storage/'.$savename;
  92. if (!$fileName)return false;
  93. $reader = new Xls();
  94. $excel = $reader->load($fileName);
  95. $sheet = $excel->getSheet(0);
  96. $sheetRows = $sheet->getHighestRow();
  97. $mobiles = [];
  98. for ($i = 2; $i <= $sheetRows; $i++) {
  99. $mobiles[] = trim(strval($sheet->getCell('A' . $i)->getValue()??''));
  100. }
  101. $keys = 'GIVEOUTCOUPONKEY'.time().rand(1000,9999);
  102. $rds = new Redis(config('cache.stores.redis'));
  103. $rds->set($keys,json_encode($mobiles),900);//写10000秒
  104. if (file_exists($fileName)){
  105. unlink($fileName);
  106. }
  107. return $this->renderSuccess(compact('keys'),'操作成功');
  108. }
  109. }