JsController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-09
  6. * Time: 13:43
  7. */
  8. namespace app\back\controller;
  9. use app\back\model\CouponModel;
  10. use app\back\model\JsModel;
  11. use app\back\model\JsProjectModel;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. use think\exception\DbException;
  15. class JsController extends AdminBaseController
  16. {
  17. public function index()
  18. {
  19. $JsModel = new JsModel();
  20. $where = [];
  21. $pw = [];
  22. $keyword = $this->request->param('keyword');
  23. if ($keyword) {
  24. $this->assign('keyword', $keyword);
  25. $pw['keyword'] = $keyword;
  26. }
  27. $project_id = $this->request->param('project_id');
  28. $js_ids = Db::name('js_project_relevancy')->field('js_id')->where('status', 0)->group('js_id')->select();
  29. $js_new_ids = [];
  30. foreach ($js_ids as $vo) {
  31. $js_new_ids[] = $vo['js_id'];
  32. }
  33. $where['id'] = $js_new_ids;
  34. if ($project_id) {
  35. $this->assign('project_id', $project_id);
  36. $pw['project_id'] = $project_id;
  37. $js_ids = Db::name('js_project_relevancy')->where('project_id', $project_id)->field('js_id')->group('js_id')->where('status', 0)->select();
  38. $js_new_ids = [];
  39. foreach ($js_ids as $vo) {
  40. $js_new_ids[] = $vo['js_id'];
  41. }
  42. $where['id'] = $js_new_ids;
  43. }
  44. $page = $this->request->param('page');
  45. $list = $JsModel::with(['user', 'project' => function ($query) {
  46. $query->where('status', 0);
  47. },])->where($where)->where(function ($query) use ($keyword) {
  48. if ($keyword) {
  49. $query->where('name|phone', 'like', '%' . $keyword . '%');
  50. }
  51. })->field('id,user_id,name,phone')->order('id', 'desc')->paginate(30, false, array($page, url('index'), 'query' => $pw));
  52. if ($this->request->param('debug') == 'zl') {
  53. $list = $JsModel::where($where)->where(function ($query) use ($keyword) {
  54. if ($keyword) {
  55. $query->where('name|phone', 'like', '%' . $keyword . '%');
  56. }
  57. })->field('id,user_id,name,phone')->order('id', 'desc')->paginate(30, false, array($page, url('index'), 'query' => $pw));
  58. echo $JsModel::getLastSql();
  59. var_dump($list);
  60. }
  61. $JsProjectModel = new JsProjectModel();
  62. $js_project_list = $JsProjectModel::field('id,name')->select();
  63. $this->assign('list', $list);
  64. $this->assign('js_project_list', $js_project_list);
  65. $this->assign('page', $list->render());
  66. return $this->fetch();
  67. }
  68. public function codeindex()
  69. {
  70. $pw = [];
  71. $keyword = $this->request->param('keyword');
  72. $bstatus = $this->request->param('band_status', '-1');
  73. $status = $this->request->param('made_type', '-1');
  74. $user = $this->request->param('uid_bind');
  75. $page = $this->request->param('page', 1);
  76. $where = [];
  77. if ($keyword) {
  78. $this->assign('keyword', $keyword);
  79. $pw['keyword'] = $keyword;
  80. $where[] = ['code', '=', $keyword];
  81. }
  82. if ($bstatus !== '-1') {
  83. $pw['band_status'] = $bstatus;
  84. $where[] = $bstatus == 1 ? ['user_id', '<>', 0] : ['user_id', '=', 0];
  85. }
  86. if ($status !== '-1') {
  87. $pw['made_type'] = $status;
  88. $where[] = ['status', '=', $status];
  89. }
  90. if ($user) {
  91. $this->assign('uid_bind', $user);
  92. $pw['uid_bind'] = $user;
  93. // $where['uid_bind'] = $user;
  94. }
  95. $this->assign('made_type', $status);
  96. $this->assign('band_status', $bstatus);
  97. $Model = new CouponModel();
  98. try {
  99. $list = $Model::with([($user ? 'useri' : 'user') => function ($query) use ($user) {
  100. if ($user) {
  101. $query->where('mobile', '=', $user);
  102. }
  103. }, 'optuser'])->where($where)->order('id', 'desc')->paginate(20, false, array($page, url('codeindex'), 'query' => $pw));
  104. } catch (DbException $e) {
  105. $list = [];
  106. }
  107. $this->assign('list', $list);
  108. $this->assign('page', $list->render());
  109. return $this->fetch();
  110. }
  111. public function downcode()
  112. {
  113. $Model = new CouponModel();
  114. $no = $this->request->param('no');
  115. if ($this->request->isPost()) {
  116. //压缩打包下载
  117. $fileG = WEB_ROOT . 'upload/';
  118. $list = $Model->where('opt_no',$no)->where('status', 0)->select();
  119. $file = $fileG . 'backwrm/' . time() . '.zip';
  120. $zip = new \ZipArchive();
  121. if ($zip->open($file, \ZipArchive::OVERWRITE) !== true) {
  122. //OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在
  123. if ($zip->open($file, \ZipArchive::CREATE) !== true) {
  124. // 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
  125. exit ('无法打开文件,或者文件创建失败');
  126. }
  127. }
  128. foreach ($list as $vo) {
  129. $zip->addFile($fileG . $vo['code_url'], $vo['code'] . '.png');
  130. }
  131. // var_dump($zip);exit();
  132. $zip->close();
  133. header("Cache-Control: max-age=0");
  134. header("Content-Description: File Transfer");
  135. header('Content-disposition: attachment; filename=' . basename($file)); // 文件名
  136. header("Content-Type: application/zip"); // zip格式的
  137. header("Content-Transfer-Encoding: binary"); // 告诉浏览器,这是二进制文件
  138. header('Content-Length: ' . filesize($file)); // 告诉浏览器,文件大小
  139. @readfile($file);//输出文件;
  140. @unlink($file);
  141. exit();
  142. }
  143. $info = $Model->where('status', 0)->count();
  144. $this->assign('info', $info);
  145. return $this->fetch();
  146. }
  147. public function codeedit()
  148. {
  149. $id = $this->request->param('id');
  150. $status = $this->request->param('status', 0);
  151. $Model = new CouponModel();
  152. if ($this->request->isPost()) {
  153. $data = $this->request->post();
  154. $data['status'] = $status;
  155. $Model->where('id', $id)->update($data);
  156. $this->success('操作成功');
  157. }
  158. $info = $Model->where('id', $id)->find();
  159. $this->assign('info', $info);
  160. return $this->fetch();
  161. }
  162. public function codeadd()
  163. {
  164. if ($this->request->isPost()) {
  165. $Model = new CouponModel();
  166. $num = $this->request->param('num');
  167. $no = $this->request->param('no');
  168. if (empty($num)) {
  169. $this->error('请输入数量');
  170. }
  171. $Model->add_cdk($num, $no, session('ADMIN_ID'));
  172. $this->success('添加成功');
  173. }
  174. return $this->fetch();
  175. }
  176. public function selectproject()
  177. {
  178. $id = $this->request->param('id');
  179. $info = JsModel::with(['project' => function ($query) {
  180. $query->where('status', 0);
  181. }])->where('id', $id)->find();
  182. $this->assign('info', $info);
  183. $this->assign('id', $id);
  184. return $this->fetch();
  185. }
  186. public function setProject()
  187. {
  188. $car_ids = $this->request->param('car_ids/a');
  189. foreach ($car_ids as $v) {
  190. Db::name('js_project_relevancy')->where('id', $v)->update(['status' => 1, 'chuli_time' => time()]);
  191. }
  192. return json(['code' => 1]);
  193. }
  194. public function setall()
  195. {
  196. $ids = $this->request->param('ids/a');
  197. foreach ($ids as $v) {
  198. Db::name('js_project_relevancy')->where(['js_id' => $v, 'status' => 0])->update(['status' => 1, 'chuli_time' => time()]);
  199. }
  200. $this->success('操作成功');
  201. }
  202. public function delete()
  203. {
  204. $id = $this->request->param('id');
  205. Db::name('js_project_relevancy')->where(['js_id' => $id, 'status' => 0])->delete();
  206. $this->success('删除成功');
  207. }
  208. }