Group.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. <?php
  2. namespace app\admin\controller\ad\user;
  3. use app\common\controller\Backend;
  4. use app\common\service\AdPlanService;
  5. use think\Controller;
  6. use think\Request;
  7. /**
  8. * 广告系统-用户组管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Group extends Backend
  13. {
  14. /**
  15. * AdUserGroup模型对象
  16. */
  17. protected $model = null;
  18. protected $noNeedRight = ['viewgroup'];
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = model('AdUserGroup');
  23. $this->adUserGroupExtendModel = model('AdUserGroupExtend');
  24. $this->view->assign('typeList', $this->model->getTypeList());
  25. $this->view->assign('userCate', $this->model->getUserCate());
  26. $this->view->assign('userSex', $this->model->getUserSex());
  27. $this->view->assign('baseType', $this->model->getBaseType());
  28. $this->view->assign('vipType', $this->model->getVipType());
  29. $this->view->assign('tailNumType', $this->model->getTailNumType());
  30. $this->view->assign('rechargeProperty', $this->model->getRechargeProperty());
  31. $this->view->assign('rechargeType', $this->model->getRechargeType());
  32. $this->view->assign('readProperty', $this->model->getReadProperty());
  33. $this->view->assign('consumerProperty', $this->model->getConsumerProperty());
  34. $this->view->assign('readType', $this->model->getReadType());
  35. $this->view->assign('readRecordType', $this->model->getReadRecordType());
  36. }
  37. /**
  38. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  39. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  40. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  41. */
  42. /**
  43. * 查看
  44. */
  45. public function index()
  46. {
  47. //设置过滤方法
  48. $this->request->filter(['strip_tags']);
  49. if ($this->request->isAjax())
  50. {
  51. //如果发送的来源是Selectpage,则转发到Selectpage
  52. if ($this->request->request('pkey_name'))
  53. {
  54. return $this->selectpage();
  55. }
  56. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  57. $map = ['is_del' => 0, 'create_by' => $this->auth->id];
  58. $total = $this->model
  59. ->where($where)
  60. ->where($map)
  61. ->order($sort, $order)
  62. ->count();
  63. $list = $this->model
  64. ->where($where)
  65. ->where($map)
  66. ->order($sort, $order)
  67. ->limit($offset, $limit)
  68. ->select();
  69. $result = array("total" => $total, "rows" => $list);
  70. return json($result);
  71. }
  72. return $this->view->fetch();
  73. }
  74. /**
  75. * 添加
  76. */
  77. public function add()
  78. {
  79. $selcted_categories = [];
  80. $this->assign('selcted_categories', $selcted_categories);
  81. $selcted_consumer_categories = [];
  82. $this->assign('selcted_consumer_categories', $selcted_consumer_categories);
  83. if ($this->request->isPost())
  84. {
  85. $params = $this->request->post("row/a");
  86. if ($params)
  87. {
  88. /*
  89. * 已经弃用,如果为了兼容老版可取消注释
  90. foreach ($params as $k => &$v)
  91. {
  92. $v = is_array($v) ? implode(',', $v) : $v;
  93. }
  94. */
  95. if ($this->dataLimit)
  96. {
  97. $params[$this->dataLimitField] = $this->auth->id;
  98. }
  99. try
  100. {
  101. //是否采用模型验证
  102. if ($this->modelValidate)
  103. {
  104. $name = basename(str_replace('\\', '/', get_class($this->model)));
  105. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  106. $this->model->validate($validate);
  107. }
  108. if(empty($params['group_name'])){
  109. $this->error('用户集合名词不能为空');
  110. }
  111. $group_type = $params['group_type'];
  112. if($group_type == 0){
  113. //全部用户
  114. $data = [];
  115. $data['group_name'] = $params['group_name'];
  116. $data['group_type'] = $params['group_type'];
  117. $data['create_by'] = $this->auth->id;
  118. $data['edit_by'] = $this->auth->id;
  119. $result = $this->model->allowField(true)->save($data);
  120. }elseif ($group_type == 1){
  121. //自定义
  122. $data = [];
  123. $data['group_name'] = $params['group_name'];
  124. $data['group_type'] = $params['group_type'];
  125. $user_ids = $this->arr_uni_str($params['user_ids']);
  126. if (empty($user_ids)) {
  127. $this->error('用户ID不能为空');
  128. } elseif (count(explode(',', $user_ids)) < 2) {
  129. $this->error('用户ID最少填写两个');
  130. }
  131. $data['create_by'] = $this->auth->id;
  132. $data['edit_by'] = $this->auth->id;
  133. $rst = $this->model->allowField(true)->save($data);
  134. if ($rst) {
  135. $send_user_group_id = $this->model->id;
  136. $send_extend_data = [
  137. 'user_group_id' => $send_user_group_id,
  138. 'user_ids' => $user_ids,
  139. 'create_by' => $this->auth->id,
  140. 'edit_by' => $this->auth->id
  141. ];
  142. $result = $this->adUserGroupExtendModel->allowField(true)->save($send_extend_data);
  143. }else{
  144. $result = false;
  145. }
  146. }else{
  147. //条件筛选
  148. $data = [];
  149. $data['group_name'] = $params['group_name'];
  150. $data['group_type'] = $params['group_type'];
  151. unset($params['group_name']);
  152. unset($params['group_type']);
  153. unset($params['user_ids']);
  154. if(!isset($params['vipType'])){
  155. $params['vipType'] = '';
  156. }
  157. if(!isset($params['tailNum'])){
  158. $params['tailNum'] = '';
  159. }
  160. if(!isset($params['rechargeType'])){
  161. $params['rechargeType'] = '';
  162. }
  163. if(!isset($params['readType'])){
  164. $params['readType'] = '';
  165. }
  166. //重构 $params
  167. $this->restruct_params($params);
  168. //
  169. $this->filterFromParams($params);
  170. // 校验表单
  171. $this->validateForm($params);
  172. if($params['userSex'] == -1){
  173. $params['userSex'] = '';
  174. }
  175. $params['read_book_categories'] = implode(',', array_unique(array_filter(explode(',', $params['read_book_categories']))));
  176. //$params['consumer_book_categories'] = implode(',', array_unique(array_filter(explode(',', $params['consumer_book_categories']))));
  177. $user_json = json_encode($params);
  178. $data['user_json'] = $user_json;
  179. $data['create_by'] = $this->auth->id;
  180. $data['edit_by'] = $this->auth->id;
  181. $result = $this->model->allowField(true)->save($data);
  182. }
  183. if ($result !== false)
  184. {
  185. $this->success();
  186. }
  187. else
  188. {
  189. $this->error($this->model->getError());
  190. }
  191. }
  192. catch (\think\exception\PDOException $e)
  193. {
  194. $this->error($e->getMessage());
  195. }
  196. }
  197. $this->error(__('Parameter %s can not be empty', ''));
  198. }
  199. return $this->view->fetch();
  200. }
  201. /**
  202. * 编辑
  203. */
  204. public function edit($ids = NULL)
  205. {
  206. $row = $this->model->get($ids);
  207. if (!$row)
  208. $this->error(__('No Results were found'));
  209. $adminIds = $this->getDataLimitAdminIds();
  210. if (is_array($adminIds))
  211. {
  212. if (!in_array($row[$this->dataLimitField], $adminIds))
  213. {
  214. $this->error(__('You have no permission'));
  215. }
  216. }
  217. if ($this->request->isPost())
  218. {
  219. $params = $this->request->post("row/a");
  220. if ($params)
  221. {
  222. /*
  223. * 已经弃用,如果为了兼容老版可取消注释
  224. foreach ($params as $k => &$v)
  225. {
  226. $v = is_array($v) ? implode(',', $v) : $v;
  227. }
  228. */
  229. try
  230. {
  231. //是否采用模型验证
  232. if ($this->modelValidate)
  233. {
  234. $name = basename(str_replace('\\', '/', get_class($this->model)));
  235. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  236. $row->validate($validate);
  237. }
  238. if(empty($params['group_name'])){
  239. $this->error('用户集合名词不能为空');
  240. }
  241. $group_type = $params['group_type'];
  242. if($group_type == 0){
  243. //全部用户
  244. $data = [];
  245. $data['group_name'] = $params['group_name'];
  246. $data['group_type'] = $params['group_type'];
  247. $data['edit_by'] = $this->auth->id;
  248. $result = $this->model->allowField(true)->update($data, ['id'=>$ids]);
  249. }elseif ($group_type == 1){
  250. //自定义
  251. $data = [];
  252. $data['group_name'] = $params['group_name'];
  253. $data['group_type'] = $params['group_type'];
  254. $user_ids = trim($this->arr_uni_str($params['user_ids']));
  255. if (empty($user_ids)) {
  256. $this->error('用户ID不能为空');
  257. } elseif (count(explode(',', $user_ids)) < 2) {
  258. $this->error('用户ID最少填写两个');
  259. }
  260. $data['edit_by'] = $this->auth->id;
  261. $rst = $this->model->allowField(true)->update($data, ['id'=>$ids]);
  262. if ($rst) {
  263. $send_extend_data = [
  264. 'user_ids' => $user_ids,
  265. 'edit_by' => $this->auth->id
  266. ];
  267. $result = $this->adUserGroupExtendModel->where(['user_group_id' => $ids])->update($send_extend_data);
  268. }else{
  269. $result = false;
  270. }
  271. }else{
  272. //条件筛选
  273. $data = [];
  274. $data['group_name'] = $params['group_name'];
  275. $data['group_type'] = $params['group_type'];
  276. unset($params['group_name']);
  277. unset($params['group_type']);
  278. unset($params['user_ids']);
  279. if(!isset($params['vipType'])){
  280. $params['vipType'] = '';
  281. }
  282. if(!isset($params['tailNum'])){
  283. $params['tailNum'] = '';
  284. }
  285. if(!isset($params['rechargeType'])){
  286. $params['rechargeType'] = '';
  287. }
  288. if(!isset($params['readType'])){
  289. $params['readType'] = '';
  290. }
  291. $params['read_book_categories'] = implode(',', array_unique(array_filter(explode(',', $params['read_book_categories']))));
  292. //
  293. $this->filterFromParams($params);
  294. // 校验表单
  295. $this->validateForm($params);
  296. if($params['userSex'] == -1){
  297. $params['userSex'] = '';
  298. }
  299. $user_json = json_encode($params);
  300. $data['user_json'] = $user_json;
  301. $data['edit_by'] = $this->auth->id;
  302. $result = $this->model->allowField(true)->update($data, ['id'=>$ids]);
  303. }
  304. if ($result !== false)
  305. {
  306. $this->success();
  307. }
  308. else
  309. {
  310. $this->error($row->getError());
  311. }
  312. }
  313. catch (\think\exception\PDOException $e)
  314. {
  315. $this->error($e->getMessage());
  316. }
  317. }
  318. $this->error(__('Parameter %s can not be empty', ''));
  319. }
  320. if($row['group_type'] == 2){
  321. $user_json = json_decode($row['user_json'], true);
  322. $this->restruct_params($user_json);
  323. }else{
  324. $user_json = $this->initUserJson();
  325. }
  326. if(!empty($user_json['read_book_categories'])){
  327. $read_book_categories = model('BookCategory')->where('id', 'in', $user_json['read_book_categories'])->select();
  328. }else{
  329. $read_book_categories = [];
  330. }
  331. if($row['group_type'] === 1){
  332. $extend_data = $this->adUserGroupExtendModel->where(['user_group_id' => $row['id']])->find();
  333. $row['user_ids'] = $extend_data->user_ids ?? '';
  334. }
  335. if(!isset($user_json['userSex']) || $user_json['userSex'] === ''){
  336. $user_json['userSex'] = -1;
  337. }
  338. $this->view->assign('read_book_categories', $read_book_categories);
  339. $this->view->assign('user_json',$user_json);
  340. $this->view->assign("row", $row);
  341. return $this->view->fetch();
  342. }
  343. /**
  344. * 删除
  345. */
  346. public function del($ids = "")
  347. {
  348. if ($ids)
  349. {
  350. $pk = $this->model->getPk();
  351. $adminIds = $this->getDataLimitAdminIds();
  352. if (is_array($adminIds))
  353. {
  354. $count = $this->model->where($this->dataLimitField, 'in', $adminIds);
  355. }
  356. $list = $this->model->where($pk, 'in', $ids)->select();
  357. $count = 0;
  358. foreach ($list as $k => $v)
  359. {
  360. $count += $v->where(['id'=>$v->id])->update(['is_del'=>1]);
  361. //$count += $v->delete();
  362. }
  363. if ($count)
  364. {
  365. $this->success();
  366. }
  367. else
  368. {
  369. $this->error(__('No rows were deleted'));
  370. }
  371. }
  372. $this->error(__('Parameter %s can not be empty', 'ids'));
  373. }
  374. /**
  375. * 详情页面
  376. * @param $ids
  377. * @return string
  378. * @throws \think\Exception
  379. */
  380. public function detail($ids)
  381. {
  382. $row = $this->model->get($ids);
  383. if ($row['group_type'] == 2) {
  384. $user_json = json_decode($row['user_json'], true);
  385. $this->restruct_params($user_json);
  386. } else {
  387. $user_json = $this->initUserJson();
  388. }
  389. if(!empty($user_json['read_book_categories'])){
  390. $read_book_categories = model('BookCategory')->where('id', 'in', $user_json['read_book_categories'])->select();
  391. }else{
  392. $read_book_categories = [];
  393. }
  394. if(!isset($user_json['userSex']) || $user_json['userSex'] === ''){
  395. $user_json['userSex'] = -1;
  396. }
  397. if($row['group_type'] === 1){
  398. $extend_data = $this->adUserGroupExtendModel->where(['user_group_id' => $row['id']])->find();
  399. $row['user_ids'] = $extend_data->user_ids ?? '';
  400. }
  401. $this->view->assign('read_book_categories', $read_book_categories);
  402. $this->view->assign('user_json',$user_json);
  403. $this->view->assign("row", $row);
  404. return $this->view->fetch();
  405. }
  406. /**
  407. * 导入用户id
  408. */
  409. public function idimport()
  410. {
  411. $file = $this->request->request('file');
  412. if (!$file)
  413. {
  414. $this->error(__('Parameter %s can not be empty', 'file'));
  415. }
  416. $filePath = ROOT_PATH . DS . 'public' . DS . $file;
  417. if (!is_file($filePath))
  418. {
  419. $this->error(__('No results were found'));
  420. }
  421. $PHPReader = new \PHPExcel_Reader_Excel2007();
  422. if (!$PHPReader->canRead($filePath))
  423. {
  424. $PHPReader = new \PHPExcel_Reader_Excel5();
  425. if (!$PHPReader->canRead($filePath))
  426. {
  427. $PHPReader = new \PHPExcel_Reader_CSV();
  428. if (!$PHPReader->canRead($filePath))
  429. {
  430. $this->error(__('Unknown data format'));
  431. }
  432. }
  433. }
  434. $fieldArr = ['id' =>'id'];
  435. $PHPExcel = $PHPReader->load($filePath); //加载文件
  436. $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
  437. $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
  438. $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
  439. $maxColumnNumber = \PHPExcel_Cell::columnIndexFromString($allColumn);
  440. for ($currentRow = 1; $currentRow <= 1; $currentRow++)
  441. {
  442. for ($currentColumn = 0; $currentColumn < $maxColumnNumber; $currentColumn++)
  443. {
  444. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  445. $fields[] = $val;
  446. }
  447. }
  448. $insert = [];
  449. for ($currentRow = 2; $currentRow <= $allRow; $currentRow++)
  450. {
  451. $values = [];
  452. for ($currentColumn = 0; $currentColumn < $maxColumnNumber; $currentColumn++)
  453. {
  454. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  455. $values[] = is_null($val) ? '' : $val;
  456. }
  457. $row = [];
  458. $temp = array_combine($fields, $values);
  459. foreach ($temp as $k => $v)
  460. {
  461. if (isset($fieldArr[$k]) && $k !== '')
  462. {
  463. $row[$fieldArr[$k]] = $v;
  464. }
  465. }
  466. if ($row)
  467. {
  468. $insert[] = $row;
  469. }
  470. }
  471. if (!$insert)
  472. {
  473. $this->error(__('上传文件有误,请核对数据'));
  474. }
  475. try
  476. {
  477. $str = implode(',', array_column($insert, 'id'));
  478. $this->success('Success', '', $str);
  479. }
  480. catch (\think\exception\PDOException $exception)
  481. {
  482. $this->error($exception->getMessage());
  483. }
  484. }
  485. /**
  486. * 选择书籍分类
  487. * @return string|\think\response\Json
  488. * @throws \think\Exception
  489. */
  490. public function ajaxcategoryslect()
  491. {
  492. $this->model = model('BookCategory');
  493. if ($this->request->isAjax()) {
  494. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  495. $total = $this->model
  496. ->where(['status' => 'normal'])
  497. ->where($where)
  498. ->count();
  499. $list = $this->model
  500. ->where(['status' => 'normal'])
  501. ->where($where)
  502. ->limit($offset, $limit)
  503. ->select();
  504. $result = array("total" => $total, "rows" => $list);
  505. return json($result);
  506. }
  507. return $this->view->fetch();
  508. }
  509. /**
  510. * Ajax设置有效失效
  511. */
  512. public function ajaxValidate()
  513. {
  514. $id = $this->request->param("ids");
  515. $data = $this->model->where('id', $id)->find();
  516. $status = $data->status;
  517. $this->model->update(['status' => !$status], ['id' => $id]);
  518. $data = ['code' => 0, 'msg' => 'success'];
  519. echo json_encode($data);
  520. }
  521. /**
  522. * 批量生效 | 失效
  523. */
  524. public function validbatch()
  525. {
  526. $params = $this->request->param();
  527. $ids = $params['ids'];
  528. $status = $params['status'];
  529. if (is_array($ids)) {
  530. foreach ($ids as $id) {
  531. $result = $this->model->update(['status' => $status], ['id' => $id]);
  532. }
  533. } else {
  534. $result = $this->model->update(['status' => $status], ['id' => $ids]);
  535. }
  536. if($result){
  537. $this->success('设置成功');
  538. }else{
  539. $this->error('设置失败');
  540. }
  541. }
  542. /**
  543. * 关联用户组
  544. */
  545. public function viewgroup()
  546. {
  547. //设置过滤方法
  548. $this->request->filter(['strip_tags']);
  549. if ($this->request->isAjax()) {
  550. //如果发送的来源是Selectpage,则转发到Selectpage
  551. if ($this->request->request('pkey_name')) {
  552. return $this->selectpage();
  553. }
  554. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  555. $map = ['status' => 1, 'is_del' => 0, 'create_by' => $this->auth->id];
  556. $total = $this->model
  557. ->where($where)
  558. ->where($map)
  559. ->order($sort, $order)
  560. ->count();
  561. $list = $this->model
  562. ->where($where)
  563. ->where($map)
  564. ->order($sort, $order)
  565. ->limit($offset, $limit)
  566. ->select();
  567. $result = array("total" => $total, "rows" => $list);
  568. return json($result);
  569. }
  570. return $this->view->fetch();
  571. }
  572. // region 额外的方法
  573. /**
  574. * 过滤字符串中重复的ID
  575. * @param $str 字符串
  576. * @param string $delimiter 分隔符
  577. */
  578. private function arr_uni_str($str, $delimiter=',')
  579. {
  580. $str = str_replace(',', ',', $str);
  581. $arr = array_unique(explode($delimiter, $str));
  582. // 过滤掉字符串
  583. $arr = array_filter($arr, function ($v){
  584. if(is_numeric($v)){
  585. return true;
  586. }else{
  587. return false;
  588. }
  589. });
  590. return implode(",", $arr);
  591. }
  592. private function restruct_params(&$params)
  593. {
  594. if ($params) {
  595. foreach ($params as $key => $item) {
  596. if (is_array($params[$key])) {
  597. $params[$key] = $this->array_filter_group($item);
  598. }
  599. }
  600. }
  601. }
  602. private function array_filter_group(array $arr)
  603. {
  604. return array_filter($arr, function ($v) {
  605. if($v == ''){
  606. return false;
  607. }else{
  608. return true;
  609. }
  610. });
  611. }
  612. public function validateForm(&$params)
  613. {
  614. // region 基础属性
  615. if (in_array(0, $params['baseType']) && $params['baseType'][0] == '0') {
  616. if (empty($params['follow-etime'])) {
  617. $this->error('请完善关注时间');
  618. }else{
  619. if($params['follow-stime'] >= $params['follow-etime']){
  620. $this->error('关注结束时间应大于关注开始时间');
  621. }
  622. }
  623. }
  624. if (in_array(1, $params['baseType'])) {
  625. if (empty($params['interactive-etime'])) {
  626. $this->error('请完善互动时间');
  627. } else {
  628. if ($params['interactive-stime'] >= $params['interactive-etime']) {
  629. $this->error('互动结束时间应大于互动开始时间');
  630. }
  631. }
  632. }
  633. if (in_array(2, $params['baseType'])) {
  634. if ($params['vipType'] == '') {
  635. $this->error('请完善VIP用户');
  636. }
  637. }
  638. if (in_array(3, $params['baseType'])) {
  639. if ($params['tailNum'] == '') {
  640. $this->error('请完善用户尾号');
  641. }
  642. }
  643. // endregion 基础属性
  644. // region 充值属性
  645. if (in_array(0, $params['rechargeProperty']) && $params['rechargeProperty'][0] == '0') {
  646. if (empty($params['amount-e'])) {
  647. $this->error('请完善充值金额');
  648. } else {
  649. if($params['amount-s'] >= $params['amount-e']){
  650. $this->error('充值结束金额应大于充值开始金额');
  651. }
  652. }
  653. }
  654. if (in_array(1, $params['rechargeProperty'])) {
  655. if (empty($params['recharge-times-e'])) {
  656. $this->error('请完善充值次数');
  657. } else {
  658. if ($params['recharge-times-s'] >= $params['recharge-times-e']) {
  659. $this->error('充值结束次数应大于充值开始次数');
  660. }
  661. }
  662. }
  663. if (in_array(2, $params['rechargeProperty'])) {
  664. if ($params['rechargeType'] == '') {
  665. $this->error('请完善充值用户');
  666. }
  667. }
  668. if (in_array(3, $params['rechargeProperty'])) {
  669. if (empty($params['kandian-e'])) {
  670. $this->error('请完善账户余额');
  671. } else {
  672. if ($params['kandian-s'] >= $params['kandian-e']) {
  673. $this->error('账户结束余额应大于账户开始余额');
  674. }
  675. }
  676. }
  677. if (in_array(4, $params['rechargeProperty'])) {
  678. if (empty($params['giftkandian-e'])) {
  679. $this->error('请完善赠送书币金额');
  680. } else {
  681. if ($params['giftkandian-s'] >= $params['giftkandian-e']) {
  682. $this->error('赠送书币结束金额应大于赠送书币开始金额');
  683. }
  684. }
  685. }
  686. // endregion 充值属性
  687. // region 阅读属性
  688. if (in_array(0, $params['readProperty']) && $params['readProperty'][0] == '0') {
  689. if ($params['readType'] === '' || empty($params['readnum-e'])) {
  690. $this->error('请完善阅读章节数属性');
  691. } else {
  692. if ($params['readnum-s'] >= $params['readnum-e']) {
  693. $this->error('阅读结束章节数应大于阅读开始章节数');
  694. }
  695. }
  696. }
  697. if (in_array(1, $params['readProperty'])) {
  698. if ($params['book_id'] == '') {
  699. $this->error('请完善阅读记录属性');
  700. }
  701. }
  702. if (in_array(2, $params['readProperty'])) {
  703. if (empty($params['read_book_categories'])) {
  704. $this->error('请完善阅读书籍分类');
  705. }
  706. }
  707. // endregion 阅读属性
  708. // region 消费属性
  709. if (in_array(0, $params['consumerProperty']) && $params['consumerProperty'][0] == '0') {
  710. if (empty($params['spendkandian-e'])) {
  711. $this->error('请完善消费赠送书币数量');
  712. } else {
  713. if ($params['spendkandian-s'] >= $params['spendkandian-e']) {
  714. $this->error('消费赠送书币结束数额应大于消费赠送书币开始数额');
  715. }
  716. }
  717. }
  718. if (in_array(1, $params['consumerProperty'])) {
  719. if (empty($params['spendrecharge-e'])) {
  720. $this->error('请完善消费充值金额');
  721. } else {
  722. if ($params['spendrecharge-s'] >= $params['spendrecharge-e']) {
  723. $this->error('消费充值结束金额应大于消费充值开始金额');
  724. }
  725. }
  726. }
  727. // endregion 消费属性
  728. }
  729. public function initUserJson(){
  730. $user_json = [
  731. 'baseType' => [],
  732. 'readRecordType' => [],
  733. 'read_book_categories' => '',
  734. 'vipType' => '',
  735. 'tailNum' => '',
  736. 'readType' => '',
  737. 'rechargeType' => '',
  738. 'follow-stime' => 0,
  739. 'follow-etime' => 0,
  740. 'interactive-stime' => 0,
  741. 'interactive-etime' => 0,
  742. 'amount-s' => 0,
  743. 'amount-e' => 0,
  744. 'recharge-times-s' => 0,
  745. 'recharge-times-e' => 0,
  746. 'giftkandian-s' => 0,
  747. 'giftkandian-e' => 0,
  748. 'kandian-s' => 0,
  749. 'kandian-e' => 0,
  750. 'readnum-s' => 0,
  751. 'readnum-e' => 0,
  752. 'book_id' => '',
  753. 'spendkandian-s' => 0,
  754. 'spendkandian-e' => 0,
  755. 'spendrecharge-s' => 0,
  756. 'spendrecharge-e' => 0,
  757. 'userCate' => 0,
  758. 'userSex' => '',
  759. 'consumerProperty' => [],
  760. 'rechargeProperty' =>[],
  761. 'readProperty' => [],
  762. ];
  763. return $user_json;
  764. }
  765. public function filterFromParams(&$params)
  766. {
  767. if (!in_array(0, $params['baseType'])) {
  768. $params['follow-stime'] = '';
  769. $params['follow-etime'] = '';
  770. }else{
  771. if(trim($params['follow-stime']) == '' && !empty($params['follow-etime'])){
  772. $params['follow-stime'] = 0;
  773. }
  774. }
  775. if (!in_array(1, $params['baseType'])) {
  776. $params['interactive-stime'] = '';
  777. $params['interactive-etime'] = '';
  778. }else{
  779. if(trim($params['interactive-stime']) == '' && !empty($params['interactive-etime'])){
  780. $params['interactive-stime'] = 0;
  781. }
  782. }
  783. if (!in_array(2, $params['baseType'])) {
  784. $params['vipType'] = '';
  785. }
  786. if (!in_array(3, $params['baseType'])) {
  787. $params['tailNum'] = '';
  788. }
  789. // rechargeProperty
  790. if (!in_array(0, $params['rechargeProperty'])) {
  791. $params['amount-s'] = '';
  792. $params['amount-e'] = '';
  793. }else{
  794. if(trim($params['amount-s']) == '' && !empty($params['amount-e'])){
  795. $params['amount-s'] = 0;
  796. }
  797. }
  798. if (!in_array(1, $params['rechargeProperty'])) {
  799. $params['recharge-times-s'] = '';
  800. $params['recharge-times-e'] = '';
  801. }else{
  802. if(trim($params['recharge-times-s']) == '' && !empty($params['recharge-times-e'])){
  803. $params['recharge-times-s'] = 0;
  804. }
  805. }
  806. if (!in_array(2, $params['rechargeProperty'])) {
  807. $params['rechargeType'] = '';
  808. }
  809. if (!in_array(3, $params['rechargeProperty'])) {
  810. $params['kandian-s'] = '';
  811. $params['kandian-e'] = '';
  812. }else{
  813. if(trim($params['kandian-s']) == '' && !empty($params['kandian-e'])){
  814. $params['kandian-s'] = 0;
  815. }
  816. }
  817. if (!in_array(4, $params['rechargeProperty'])) {
  818. $params['giftkandian-s'] = '';
  819. $params['giftkandian-e'] = '';
  820. }else{
  821. if(trim($params['giftkandian-s']) == '' && !empty($params['giftkandian-e'])){
  822. $params['giftkandian-s'] = 0;
  823. }
  824. }
  825. // readProperty
  826. if (!in_array(0, $params['readProperty'])) {
  827. $params['readType'] = '';
  828. $params['readnum-s'] = '';
  829. $params['readnum-e'] = '';
  830. }
  831. if (!in_array(1, $params['readProperty'])) {
  832. $params['readRecordType'] = '';
  833. $params['book_id'] = '';
  834. }
  835. if (!in_array(2, $params['readProperty'])) {
  836. $params['read_book_categories'] = '';
  837. }
  838. // consumerProperty
  839. if (!in_array(0, $params['consumerProperty'])) {
  840. $params['spendkandian-s'] = '';
  841. $params['spendkandian-e'] = '';
  842. }else{
  843. if(trim($params['spendkandian-s']) == '' && !empty($params['spendkandian-e'])){
  844. $params['spendkandian-s'] = 0;
  845. }
  846. }
  847. if (!in_array(1, $params['consumerProperty'])) {
  848. $params['spendrecharge-s'] = '';
  849. $params['spendrecharge-e'] = '';
  850. }else{
  851. if(trim($params['spendrecharge-s']) == '' && !empty($params['spendrecharge-e'])){
  852. $params['spendrecharge-s'] = 0;
  853. }
  854. }
  855. /*if (!in_array(2, $params['consumerProperty'])) {
  856. $params['consumer_book_categories'] = '';
  857. }*/
  858. }
  859. // endregion 额外的方法
  860. }