Waterbookapi.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Elton
  5. * Date: 2020/8/8
  6. * Time: 14:00
  7. * JOB 调用 是否清水小说
  8. */
  9. namespace app\api\controller\v1;
  10. use app\common\library\Redis;
  11. use app\main\constants\CacheConstants;
  12. use app\main\service\LogService;
  13. use think\Config;
  14. use think\Request;
  15. class Waterbookapi extends Init
  16. {
  17. public function waterRules()
  18. {
  19. LogService::info('API:Waterbookapi->waterRules:params:'.json_encode(Request::instance()->param()));
  20. $channel_id = (integer)Request::instance()->param('channel_id') ?? 0;
  21. $aim_city = [];
  22. if($channel_id){
  23. // 读取Hash中的规则
  24. $waterRule = array_filter(Redis::instance()->hMGet(CacheConstants::LIGHT_RULE, ['*', $channel_id]));
  25. $push_type = 0;
  26. if($waterRule){
  27. foreach ($waterRule as $k=>$item)
  28. {
  29. $waterRule[$k] = json_decode($item, true);
  30. }
  31. //
  32. if (isset($waterRule['*']['t']) && $waterRule['*']['t'] == 1) {
  33. $push_type = 1;
  34. }else{
  35. if(isset($waterRule[$channel_id]['t'])){
  36. $push_type = $waterRule[$channel_id]['t'];
  37. }
  38. }
  39. $aim_city = array_column($waterRule, 'c');
  40. }
  41. $data = [
  42. 'push_type' => $push_type,
  43. 'city_ids' => implode(',', $aim_city),
  44. 'water_uids' => Config::get('site.water_uids')
  45. ];
  46. $this->setMsg('success')->setData($data)->getReturn();
  47. }else{
  48. $this->setCode(1)->setMsg('fail')->getReturn();
  49. }
  50. }
  51. }