Group.php 33 KB

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