Channel.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: edison
  5. * Date: 2018/3/26
  6. * Time: 上午11:50
  7. */
  8. namespace app\admin\controller;
  9. use app\common\library\MakeReport;
  10. use app\common\library\MakeReportGo;
  11. use think\Config;
  12. use think\Db;
  13. use think\Exception;
  14. use app\common\logic\SubPackage as SubChannel;
  15. use GuzzleHttp\Client;
  16. use GuzzleHttp\Exception\GuzzleException;
  17. use app\common\logic\Websocket;
  18. use app\common\library\FileUpload;
  19. class Channel extends Admin
  20. {
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->adminModel = Db::table('nw_channel_admin');
  25. $this->channelModel = Db::table('nw_channel');
  26. }
  27. public function index()
  28. {
  29. $condition = $this->getListCondition();
  30. // $status = input('request.status');
  31. $list = $this->adminModel->alias('a')
  32. ->join('nw_channel channel', 'a.channel_id = channel.id')
  33. ->join('nw_channel top', 'channel.id_path like CONCAT(",",top.id,",%") and top.level = 0','left')
  34. ->join('nw_channel_info info', 'channel.id = info.channel_id','left')
  35. ->join('nw_channel_info_apply apply', 'channel.id = apply.channel_id and apply.status = 0','left')
  36. ->where($condition)
  37. ->field('a.id as adminid,a.channel_id as channelid,channel.level as channel_level,channel.amount as ptb_amt,channel.js_amount,a.mobile,a.username as username,a.login_check as login_check,a.beizhu as beizhu,a.create_time as created_time,a.status as status,channel.show_full_account,info.*,channel.level,apply.apply_info,apply.status as apply_status,top.name as top_name,apply.remark as audit_remark,info.apply_status as info_status,apply.id as applyId,channel.deposit_amt, channel.gh_status, channel.yql_id')
  38. ->order("a.id DESC")
  39. ->paginate(10,false, ['query' => input('get.')]);
  40. // if ($list->total()>0) {
  41. // foreach ($list as $key => $item) {
  42. // $channel = get_top_second_channel_name($item['channelid']);
  43. // $list[ $key ]['channel_name'] = $channel['channel_name'];
  44. // $list[ $key ]['second_channel'] = $channel['second_name'];
  45. // $list[ $key ]['top_channel'] = $channel['top_name'];
  46. // }
  47. // }
  48. // $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  49. // $channelWhere = [];
  50. // if ($business != -1) {
  51. // if ($business) {
  52. // $channelWhere['id'] = ['in', $business];
  53. // } else {
  54. // $channelWhere['id'] = -1;
  55. // }
  56. // }
  57. // $uniom = $this->channelModel->where(['level'=>0])->where($channelWhere)->field('id,name')->select();
  58. // 获取分页显示
  59. $page = $list->render();
  60. $this->assign("page", $page);
  61. $this->assign("total", $list->total()); //总记录数
  62. $this->assign("channles", $list);
  63. // $this->assign("uniom", $uniom);
  64. return $this->fetch();
  65. }
  66. // 联盟管理页面
  67. public function leaguesmanage()
  68. {
  69. $channles = $this->adminModel->alias('a')
  70. ->join('nw_channel channel', 'a.channel_id = channel.id','left')
  71. ->join('nw_channel_info info', 'channel.id = info.channel_id','left')
  72. ->join('nw_channel_info_apply apply', 'channel.id = apply.channel_id and apply.status = 0','left')
  73. ->where($this->getListCondition('leaguesmanage'))
  74. ->where(['channel.level'=>0])
  75. ->field('a.id as adminid,a.channel_id as channelid,channel.level as channel_level,channel.amount as ptb_amt,channel.js_amount,a.mobile,a.username as username,a.login_check as login_check,a.beizhu as beizhu,a.create_time as created_time,a.status as status,channel.show_full_account,info.*,apply.status as apply_status,apply.apply_info,info.apply_status as info_status,apply.id as applyId')
  76. ->order("a.id DESC")
  77. ->paginate(10,false, ['query' => input('get.')]);
  78. // var_dump($channles);
  79. // 获取分页显示
  80. $page = $channles->render();
  81. $this->assign("page", $page);
  82. $this->assign("total", $channles->total()); //总记录数
  83. $this->assign("channles", $channles);
  84. return $this->fetch();
  85. }
  86. // 报表下载
  87. public function download()
  88. {
  89. $type = request()->get('type');
  90. $type == 'union'?$action = 'unionList':$action = 'channelList';
  91. $conditionType = $action == 'channelList' ? 'index' : 'leaguesmanage';
  92. $where = $this->getListCondition($conditionType);
  93. if (request()->isAjax()) {
  94. $fields = 'a.channel_id as channel_id,a.username as username,a.beizhu as beizhu,FROM_UNIXTIME(a.create_time) as create_time,info.real_name as real_name,info.linkman_email as linkman_email,info.person_id,info.company_name,info.us_code,info.leson_name,info.leson_person_id,info.address,info.apply_status as info_status,info.id as info_id,apply.status as apply_status,';
  95. //是否有渠道联系方式明文查看权限
  96. if($this->checkHasActionPriv(session('ADMIN_ID'),'Admin','Channel','viewlinkinfo')){
  97. $fields .= 'a.mobile as mobile,info.zfb_account,info.bank_ban_mobile,info.bank_number,info.bank_name';
  98. }
  99. else{
  100. $fields .= 'CASE WHEN a.mobile<>"" THEN concat(substr(trim(a.mobile),1,3),"***",substr(trim(a.mobile),7)) ELSE "" END as mobile,
  101. CASE WHEN info.zfb_account<>"" THEN "***" ELSE "" END as zfb_account,
  102. CASE WHEN info.bank_ban_mobile<>"" THEN concat(substr(trim(info.bank_ban_mobile),1,3),"***",substr(trim(info.bank_ban_mobile),7)) ELSE "" END as bank_ban_mobile,
  103. CASE WHEN info.bank_number<>"" THEN "***" ELSE "" END as bank_number,
  104. CASE WHEN info.bank_name<>"" THEN "***" ELSE "" END as bank_name';
  105. }
  106. if($action == 'channelList'){
  107. $fields .= ',CASE WHEN channel.level =1 THEN "会长" WHEN channel.level = 2 THEN "子会长" ELSE "推广员" END as level_name,CASE WHEN info.id IS NOT NULL AND info.apply_status =1 THEN if( apply_status = 0 ,"待审核","已身份认证") ELSE if( apply_status = 0 ,"待审核","未身份认证") END as apply_name,channel.deposit_amt';
  108. }else{
  109. $where['channel.level'] = ['=', 0];
  110. }
  111. $sql = $this->adminModel->alias('a')
  112. ->join('nw_channel channel', 'a.channel_id = channel.id','left')
  113. ->join('nw_channel top', 'channel.id_path like CONCAT(",",top.id,",%") and top.level = 0','left')
  114. ->join('nw_channel_info info', 'channel.id = info.channel_id','left')
  115. ->join('nw_channel_info_apply apply', 'channel.id = apply.channel_id and apply.status = 0','left')
  116. ->where($where)
  117. ->field($fields)
  118. ->order("a.id DESC")
  119. ->fetchSql(true)
  120. ->select();
  121. // if ((new MakeReport())->addTask($action, $sql, session_id())){
  122. if ((new MakeReportGo())->addTask($action, $sql, session_id())){
  123. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  124. }else{
  125. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  126. }
  127. } else {
  128. $this->error('非法请求');
  129. }
  130. }
  131. // 获取推广四级(商务/会长/子会长/推广员)
  132. public function getSelectList(){
  133. $type = input('type', 'sw');
  134. $pid = input('pid', '');
  135. $newList = [];
  136. if($type == 'sw'){
  137. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  138. $channelWhere = [];
  139. if ($business != -1) {
  140. if ($business) {
  141. $channelWhere['id'] = ['in', $business];
  142. } else {
  143. $channelWhere['id'] = -1;
  144. }
  145. }
  146. $newList = $this->channelModel->where(['level'=>"0"])->where($channelWhere)->field("CAST(id as char) as id,name")->select();
  147. }else if($type == 'hz'){
  148. $where = [
  149. 'level' => 1,
  150. ];
  151. if(!empty($pid)){
  152. $where['parent_id'] = $pid;
  153. }
  154. $newList = model('Common/Channel')->field('CAST(id as char) as id,name,parent_id')->where($where)->select();
  155. }else if ($type == 'zhz') {
  156. $where = [
  157. 'level' => 2,
  158. ];
  159. if (!empty($pid)) {
  160. $where['parent_id'] = $pid;
  161. }
  162. $newList = model('Common/Channel')->field('CAST(id as char) as id,name,parent_id')->where($where)->select();
  163. } else if ($type == 'tgy') {
  164. $where = [
  165. 'level' => 3,
  166. ];
  167. if (!empty($pid)) {
  168. $where['parent_id'] = $pid;
  169. }
  170. $newList = model('Common/Channel')->field('CAST(id as char) as id,name,parent_id')->where($where)->select();
  171. }
  172. $this->jsonResult($newList);
  173. }
  174. /**
  175. * 渠道管理列表的查询条件
  176. */
  177. private function getListCondition($type = 'index')
  178. {
  179. $username = input('username', '', 'trim');
  180. // $start_time = input('request.start_time',date('Y-m-d'));
  181. $start_time = input('request.start_time');
  182. $end_time = input('request.end_time');
  183. $level = input('level', '', 'trim');
  184. $unioid = input('request.unioid');// 联盟
  185. $status = input('request.status');//
  186. $channel_status = input('request.channel_status');//
  187. $gh_status = input('request.gh_status'); // 是否聚合用户:0=否、1=是
  188. // $where['a.type'] = 2;
  189. $end_time = $end_time ? $end_time : $start_time ; // 查询日期当天
  190. $end_time .= ' 23:59:59';
  191. //开始时间和结束时间不为空时
  192. if ($start_time != '' && $end_time != '') {
  193. $where['a.create_time'] = [
  194. ['>=', strtotime($start_time)],
  195. ['<=', strtotime($end_time)],
  196. ];
  197. }
  198. //开始时间不为空时
  199. elseif ($start_time != '') {
  200. $where['a.create_time'] = ['>=', strtotime($start_time)];
  201. }
  202. //结束时间不为空时
  203. elseif ($end_time != '') {
  204. $where['a.create_time'] = ['<=', strtotime($end_time)];
  205. }
  206. if ($username) {
  207. $where['a.username'] = ['like', "%$username%"];
  208. }
  209. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  210. $channelWhere = [];
  211. if($type=='index'){
  212. if ($unioid) {
  213. if ($business != -1) {
  214. if (in_array($unioid,$business)) {
  215. $where['top.id'] = ['in', $unioid];
  216. } else {
  217. $where['top.id'] = -1;
  218. }
  219. }elseif($business == -2){
  220. $where['top.id'] = -1;
  221. }
  222. }else{
  223. if ($business != -1) {
  224. if ($business) {
  225. $where['top.id'] = ['in', $business];
  226. } else {
  227. $where['top.id'] = -1;
  228. }
  229. }elseif($business == -2){
  230. $where['top.id'] = -1;
  231. }
  232. }
  233. }else{
  234. if ($unioid) {
  235. if ($business != -1) {
  236. if (in_array($unioid,$business)) {
  237. $where['channel.id'] = ['in', $unioid];
  238. } else {
  239. $where['channel.id'] = -1;
  240. }
  241. }elseif($business == -2){
  242. $where['channel.id'] = -1;
  243. }
  244. }else{
  245. if ($business != -1) {
  246. if ($business) {
  247. $where['channel.id'] = ['in', $business];
  248. } else {
  249. $where['channel.id'] = -1;
  250. }
  251. }elseif($business == -2){
  252. $where['channel.id'] = -1;
  253. }
  254. }
  255. }
  256. if ($level) {
  257. $where['channel.level'] = ['=', $level];
  258. }elseif ($type == 'index') {
  259. $where['channel.level'] = ['neq', 0];
  260. }
  261. if ($status == '0') {
  262. $where['apply.status'] = $status;
  263. }elseif ($status == '1') {
  264. $where['info.apply_status'] = 1;
  265. }elseif($status == '2'){
  266. $where['info.id'] = ['EXP',Db::raw('IS NULL')];
  267. }
  268. if ($channel_status<>'') {
  269. $where['channel.status'] = $channel_status;
  270. }
  271. if ($gh_status<>'') {
  272. $where['channel.gh_status'] = $gh_status;
  273. }
  274. $business_type = input('business_type', ''); // 商务
  275. $president_type = input('president_type', ''); // 会长
  276. $president_type_son = input('president_type_son', ''); // 子会长
  277. if ($business_type<>'') {
  278. $hasBusinessAccess = $business == -1
  279. || (is_array($business) && in_array($business_type, $business));
  280. $where['top.id'] = $hasBusinessAccess ? $business_type : -1;
  281. }
  282. if ($president_type<>'') {
  283. // $where['channel.id_path'] = ['like', ",{$business_type},{$president_type},%"];
  284. $where['channel.id'] = $president_type;
  285. }
  286. if ($president_type_son<>'') {
  287. unset($where['channel.id_path']);
  288. $where['channel.id'] = $president_type_son;
  289. }
  290. return $where;
  291. }
  292. /**
  293. * 添加渠道
  294. *
  295. * @return mixed
  296. */
  297. public function add()
  298. {
  299. $list = Db::name('nw_channel')->where(['level' => 0])->column('name','id');
  300. $this->assign('list', $list);
  301. return $this->fetch();
  302. }
  303. /**
  304. * 获取历史审核记录
  305. * @param string $value [description]
  306. * @return [type] [description]
  307. */
  308. public function checklog()
  309. {
  310. $channelid = request()->post('channelid');
  311. if (empty($channelid)) {
  312. $this->error("无效用户id");
  313. }
  314. $list = db::name('nw_channel_info_apply')->field('id,FROM_UNIXTIME(apply_time) as apply_time,apply_info,CASE status WHEN 0 THEN "待审核" WHEN 1 THEN "审核通过" ELSE "审核失败" END AS status,status as apply_status, CASE WHEN check_time <> 0 THEN FROM_UNIXTIME(check_time) ELSE "--" END as check_time,check_admin_name,channel_id')->where(['channel_id'=>$channelid])->order('id desc')->select();
  315. $this->success('查询记录',null,$list);
  316. }
  317. /**
  318. * 渠道审核
  319. *
  320. * @return mixed
  321. */
  322. public function examine()
  323. {
  324. $channel_id = request()->get('channelid');
  325. $apply_status = request()->get('apply_status');
  326. $applyId = request()->get('cid');
  327. $log = request()->get('log');
  328. $status = 0;
  329. if ($apply_status == 1) {
  330. $data = Db::name('nw_channel_info')->field('real_name as name,person_id,zfb_account as zhifubao_number,bank_ban_mobile as mobile ,bank_number as bankNum,bank_province_city as provinceCity,bank_name as bankName,bank_open_name as openBank,bank_open_number as bankId,back_image_url,front_image_url')->where(['channel_id'=>$channel_id])->find();
  331. $status = 1;
  332. }else{
  333. $data = Db::name('nw_channel_info_apply')->where(['channel_id'=>$channel_id,'id'=>$applyId])->value('apply_info');
  334. $data = json_decode($data,1);
  335. }
  336. $this->assign('channel_id', $channel_id);
  337. $this->assign('list', $data);
  338. $this->assign('log', $log);
  339. $this->assign('applyId', $applyId);
  340. $this->assign('status', $status);
  341. return $this->fetch();
  342. }
  343. /**
  344. * 查看个人身份认证信息
  345. *
  346. * @return mixed
  347. */
  348. public function checkInfo()
  349. {
  350. $channel_id = request()->get('channelid');
  351. $data = Db::name('nw_channel_info')->field('real_name as name,person_id,zfb_account as zhifubao_number,bank_ban_mobile as mobile ,bank_number as bankNum,bank_province_city as provinceCity,bank_name as bankName,bank_open_name as openBank,bank_open_number as bankId,back_image_url,front_image_url')->where(['channel_id'=>$channel_id])->find();
  352. $this->assign('list', $data);
  353. return $this->fetch();
  354. }
  355. /**
  356. * 更改审核状态
  357. */
  358. public function doExamine()
  359. {
  360. $data = request()->post();
  361. $status = $data['status'];
  362. $channel_id = $data['channel_id'];
  363. $applyId = $data['applyId'];
  364. if (empty($status)) {
  365. $this->error("系统错误");
  366. }
  367. $data['check_time'] = NOW_TIMESTAMP;
  368. $data['check_admin_type'] = 1;
  369. $data['check_admin_name'] = session('USERNAME');
  370. unset($data['channel_id']);
  371. unset($data['applyId']);
  372. Db::startTrans();
  373. try {
  374. $resultChannel = Db::name('nw_channel_info_apply')->where(['channel_id'=>$channel_id,'id'=>$applyId])->update($data);//更新审核状态
  375. if (!$resultChannel) {
  376. $this->error("更新审核状态失败,请刷新后重试");
  377. }
  378. if ($status == 1 ) {//审核内容通过后写入 info表
  379. $apply_data = Db::name('nw_channel_info_apply')->where(['channel_id'=>$channel_id,'id'=>$applyId])->value('apply_info');
  380. if (!$apply_data) {
  381. $this->error("审核内容获取失败,请刷新后重试");
  382. }
  383. $apply_data = json_decode($apply_data,1);
  384. $cont['real_name'] = isset($apply_data['name'])?$apply_data['name']:'';//真实姓名
  385. $cont['person_id'] = isset($apply_data['person_id'])?$apply_data['person_id']:'';//身份证
  386. $cont['zfb_account'] = isset($apply_data['zhifubao_number'])?$apply_data['zhifubao_number']:'';//支付宝账号
  387. $cont['bank_ban_mobile'] = isset($apply_data['mobile'])?$apply_data['mobile']:'';//手机号码
  388. $cont['bank_number'] = isset($apply_data['bankNum'])?$apply_data['bankNum']:'';//银行卡号码
  389. $cont['bank_province_city'] = isset($apply_data['provinceCity'])?$apply_data['provinceCity']:'';//省市
  390. $cont['bank_name'] = isset($apply_data['bankName'])?$apply_data['bankName']:'';//银行名称
  391. $cont['bank_open_name'] = isset($apply_data['openBank'])?$apply_data['openBank']:'';//开户行
  392. $cont['bank_open_number'] = isset($apply_data['bankId'])?$apply_data['bankId']:'';//开户行行号
  393. $cont['back_image_url'] = isset($apply_data['back_image_url'])?$apply_data['back_image_url']:'';//身份证正面
  394. $cont['front_image_url'] = isset($apply_data['front_image_url'])?$apply_data['front_image_url']:'';//身份证背面
  395. $cont['apply_status'] = 1;//审核通过标示
  396. if (Db::name('nw_channel_info')->where(['channel_id'=>$channel_id])->value('id')) {
  397. $resultUpdate = Db::name('nw_channel_info')->where(['channel_id'=>$channel_id])->update($cont);
  398. }else{
  399. $cont['channel_id'] =$channel_id;
  400. $resultUpdate = Db::name('nw_channel_info')->insert($cont);
  401. }
  402. if (!$resultUpdate) {
  403. $this->error("更新系统参数错误,请刷新后重试");
  404. }
  405. }
  406. Db::commit();
  407. } catch (Exception $e) {
  408. Db::rollback();
  409. $this->error("添加失败: " . $e->getMessage());
  410. }
  411. $adminInfo = model('ChannelAdmin')->where(['channel_id'=>$channel_id,'mobile'=>['neq','']])->find();
  412. if (!empty($adminInfo) && $adminInfo['mobile']){
  413. $result = (new \app\common\library\Sms)->sendIdentifyAuditInfo($adminInfo['username'], $adminInfo['mobile'], $status);
  414. }
  415. $this->success("审核成功");
  416. if ($resultChannel) {//ws通知
  417. $ws = new Websocket();
  418. $str = '{"error_code":0,"data":{"action":"applyFnish","data":{"status":'.$status.', "message":"审核完成"}}}';
  419. $ws->sayToUid('cps'.$channel_id, $str);
  420. }
  421. }
  422. /**
  423. * 添加联盟
  424. *
  425. * @return mixed
  426. */
  427. public function league_add()
  428. {
  429. return $this->fetch();
  430. }
  431. /**
  432. * 添加渠道接口
  433. *
  434. */
  435. public function add_league_post()
  436. {
  437. $postParam = $this->request->param();
  438. $postParam['username'] = trim($postParam['username']);
  439. $result = $this->validate($postParam, 'channel.add');
  440. if ($result !== true) {
  441. $this->error($result);
  442. }
  443. elseif ($_POST['password'] != $_POST['repassword']) {
  444. $this->error("两次密码输入不一致");
  445. }
  446. /*
  447. elseif ($_POST['pay_password'] != $_POST['pay_repassword']) {
  448. $this->error("两次支付密码输入不一致");
  449. }
  450. */
  451. else if(intval($_POST['login_check']) && empty($_POST['mobile'])){
  452. $this->error("登录验证开启时手机号必须填写");
  453. }
  454. else {
  455. Db::startTrans();
  456. try {
  457. //1. 添加渠道信息
  458. $channelModel = model('channel');
  459. $channelInfo = $channelModel->where(['name' => $postParam['username']])->find();
  460. if ( $channelInfo ) {
  461. throw new Exception("该联盟信息已存在");
  462. }
  463. $userInfo = model('ChannelAdmin')->field('id')->where(['username' => $postParam['username']])->find();
  464. if ($userInfo) {
  465. throw new Exception("用户名已存在! ");
  466. }
  467. //添加渠道信息
  468. $channelModel->save([
  469. 'name' => $postParam['username'],
  470. 'parent_id' => 0,
  471. 'id_path' => '',
  472. 'level' => 0,
  473. 'create_time' => NOW_TIMESTAMP,
  474. 'flag' => 3,
  475. 'show_full_account' => $postParam['show_full_account'],
  476. 'channel_tg_type' => $postParam['channel_tg_type'],
  477. 'status' => $_POST['status']]);
  478. if ( !$channelModel->id ) {
  479. throw new Exception("添加联盟信息失败");
  480. }
  481. unset($_POST['repassword']);
  482. unset($_POST['channel_tg_type']);
  483. unset($_POST['pay_repassword']);
  484. unset($_POST['show_full_account']);
  485. $_POST['username'] = $postParam['username'];
  486. $_POST['password'] = mg_password($_POST['password']);
  487. // $_POST['pay_password'] = mg_password($_POST['pay_password']);
  488. $_POST['channel_id'] = $channelModel->id;
  489. $_POST['create_time'] = NOW_TIMESTAMP;
  490. $_POST['password_update_time'] = NOW_TIMESTAMP;
  491. $result = $this->adminModel->insertGetId($_POST);
  492. if ($result === false) {
  493. throw new Exception("添加渠道账号失败");
  494. }
  495. Db::commit();
  496. } catch (\Exception $e) {
  497. Db::rollback();
  498. $this->error("添加失败: " . $e->getMessage());
  499. }
  500. // 写日志
  501. $messageStr = '冻结';
  502. if($_POST['status']){
  503. $messageStr = '正常';
  504. }
  505. $this->insertLog($this->current_node, "新增子渠道:".$postParam['username'].",状态:".$messageStr,41);
  506. $this->success("添加成功!", url("channel/leaguesmanage"));
  507. }
  508. }
  509. /**
  510. * 添加渠道接口
  511. *
  512. */
  513. public function addPost()
  514. {
  515. $postParam = $this->request->param();
  516. $postParam['username'] = trim($postParam['username']);
  517. $result = $this->validate($postParam, 'channel.add');
  518. if ($result !== true) {
  519. $this->error($result);
  520. }
  521. elseif ($_POST['password'] != $_POST['repassword']) {
  522. $this->error("两次密码输入不一致");
  523. }
  524. /*
  525. elseif ($_POST['pay_password'] != $_POST['pay_repassword']) {
  526. $this->error("两次支付密码输入不一致");
  527. }
  528. */
  529. else if(intval($_POST['login_check']) && empty($_POST['mobile'])){
  530. $this->error("登录验证开启时手机号必须填写");
  531. }
  532. else if(intval($_POST['belong_lm']) && empty($_POST['belong_lm'])){
  533. $this->error("所属联盟必须填写");
  534. }
  535. else {
  536. Db::startTrans();
  537. try {
  538. //1. 添加渠道信息
  539. $channelModel = model('channel');
  540. $channelInfo = $channelModel->where(['name' => $postParam['username']])->find();
  541. if ( $channelInfo ) {
  542. throw new Exception("该渠道信息已存在");
  543. }
  544. $userInfo = model('ChannelAdmin')->field('id')->where(['username' => $postParam['username']])->find();
  545. if ($userInfo) {
  546. throw new Exception("用户名已存在! ");
  547. }
  548. if ($postParam['mobile']) {
  549. $flag = Db::table('nw_channel_admin')->where(['mobile'=>$postParam['mobile']])->find();
  550. if ($flag) {
  551. throw new Exception("该手机号码已在其他账号上绑定");
  552. }
  553. }
  554. //添加渠道信息
  555. $channelModel->save([
  556. 'name' => $postParam['username'],
  557. 'parent_id' => $postParam['belong_lm'],
  558. 'id_path' => ','.$postParam['belong_lm'].',',
  559. 'create_time' => NOW_TIMESTAMP,
  560. 'level' => 1,
  561. 'flag' => 3,
  562. 'show_full_account' => $postParam['show_full_account'],
  563. 'cps_settle_period' => $postParam['cps_settle_period'],
  564. 'mcps_settle_period' => $postParam['mcps_settle_period'],
  565. 'status' => $_POST['status']]);
  566. if ( !$channelModel->id ) {
  567. throw new Exception("添加渠道信息失败");
  568. }
  569. unset($_POST['repassword']);
  570. unset($_POST['pay_repassword']);
  571. unset($_POST['show_full_account']);
  572. unset($_POST['belong_lm']);
  573. unset($_POST['cps_settle_period']);
  574. unset($_POST['mcps_settle_period']);
  575. $_POST['username'] = $postParam['username'];
  576. $_POST['password'] = mg_password($_POST['password']);
  577. // $_POST['pay_password'] = mg_password($_POST['pay_password']);
  578. $_POST['channel_id'] = $channelModel->id;
  579. $_POST['create_time'] = NOW_TIMESTAMP;
  580. $_POST['password_update_time'] = NOW_TIMESTAMP;
  581. $result = $this->adminModel->insertGetId($_POST);
  582. if ($result === false) {
  583. throw new Exception("添加渠道账号失败");
  584. }
  585. Db::commit();
  586. } catch (\Exception $e) {
  587. Db::rollback();
  588. $this->error("添加失败: " . $e->getMessage());
  589. }
  590. // 写日志
  591. $messageStr = '冻结';
  592. if($_POST['status']){
  593. $messageStr = '正常';
  594. }
  595. $cpsStr = '日结';
  596. if ($postParam['cps_settle_period'] == 1) {
  597. $cpsStr = '周结';
  598. }
  599. $mcpsStr = '日结';
  600. if ($postParam['mcps_settle_period'] == 1) {
  601. $mcpsStr = '周结';
  602. }
  603. $this->insertLog($this->current_node, "新增子渠道:".$postParam['username'].",状态:".$messageStr.",专服结算方式:".$cpsStr.",混服结算方式:".$mcpsStr,41);
  604. $this->success("添加成功!", url("channel/index"));
  605. }
  606. }
  607. /**
  608. * 编辑渠道
  609. *
  610. * @return mixed
  611. */
  612. public function edit()
  613. {
  614. $type = input('type', 0, 'intval');//类型 判断是联盟管理还是渠道管理
  615. $id = input('id', 0, 'intval');
  616. $channel = $this->adminModel->alias('a')
  617. ->join('nw_channel channel', 'a.channel_id = channel.id','left')
  618. ->join('nw_channel_info info', 'channel.id = info.channel_id','left')
  619. ->field('a.id as adminid,a.channel_id as channelid,a.*,channel.show_full_account,channel.level as channel_level,channel.mcps_settle_period,channel.cps_settle_period,channel.channel_tg_type,channel.amount as ptb_amt,channel.js_amount,info.*')
  620. ->where(["a.id" => $id])->find();
  621. $this->assign('channel', $channel);
  622. // var_dump($channel);
  623. //后台管理员列表
  624. $adminList = model('ChannelAdmin')->field('id,username as name')->where(['status'=>1])->order('username asc')->select();
  625. $this->assign('admin_list',$adminList);
  626. $this->assign('type',$type);
  627. return $this->fetch();
  628. }
  629. /**
  630. * 编辑渠道接口
  631. *
  632. */
  633. public function editPost()
  634. {
  635. set_time_limit(0);
  636. $type = input('type', 0, 'intval');
  637. if (empty($_POST['password'])) {
  638. unset($_POST['password']);
  639. } else {
  640. $result = $this->validate($this->request->param(), 'Channel.password');
  641. if (true !== $result) {
  642. $this->error($result);
  643. }
  644. if ($_POST['password'] != $_POST['repassword']) {
  645. $this->error('两次登录密码输入不一致!');
  646. }
  647. $_POST['password'] = mg_password($_POST['password']);
  648. $_POST['password_update_time'] = NOW_TIMESTAMP;
  649. }
  650. if (empty($_POST['pay_password'])) {
  651. unset($_POST['pay_password']);
  652. } else {
  653. $result = $this->validate($this->request->param(), 'Channel.pay_password');
  654. if (true !== $result) {
  655. $this->error($result);
  656. }
  657. if ($_POST['pay_password'] != $_POST['pay_repassword']) {
  658. $this->error('两次支付密码输入不一致!');
  659. }
  660. $_POST['pay_password'] = mg_password($_POST['pay_password']);
  661. }
  662. unset($_POST['repassword']);
  663. unset($_POST['pay_repassword']);
  664. $result = $this->validate($this->request->param(), 'Channel.edit');
  665. if ($result !== true) {
  666. $this->error($result);
  667. }
  668. else if(intval($_POST['login_check']) && empty($_POST['mobile'])){
  669. $this->error("登录验证开启时手机号必须填写");
  670. }
  671. if ($result !== true) {
  672. // 验证失败 输出错误信息
  673. $this->error($result);
  674. } else {
  675. $show_full_account = intval($_POST['show_full_account']);
  676. $id = intval($_POST['channel_id']);
  677. $parent_id = Db::table('nw_channel')->where(['id' => $id])->value('parent_id');
  678. $ParentChannel = Db::table('nw_channel')->where(['id' => $parent_id])->field('id,id_path,level,show_full_account')->find();
  679. // 判断上级渠道的账号显示是否开启
  680. if ($ParentChannel['show_full_account']==0 && $ParentChannel['level']<>0){
  681. $show_full_account = 0;
  682. }
  683. $numArr = model('Channel')->getChildIds($id);
  684. $list = [];
  685. $list[] = ['id'=>$id,'show_full_account'=>$show_full_account];
  686. if($show_full_account==0 && $numArr){
  687. foreach($numArr as $v){
  688. $list[] = ['id'=>$v,'show_full_account'=>$show_full_account];
  689. }
  690. }
  691. unset($_POST['show_full_account']);
  692. Db::startTrans();
  693. $updChannel = array();
  694. // $updChannel['show_full_account'] = $show_full_account;
  695. $updChannel['id'] = $_POST['channel_id'];
  696. $updChannel['status'] = $_POST['status'];
  697. if ($_POST['mobile']) {
  698. $flag = Db::table('nw_channel_admin')->where(['channel_id'=>['neq',$_POST['channel_id']],'mobile'=>$_POST['mobile']])->find();
  699. if ($flag) {
  700. $this->error("保存失败!该手机号码已在其他账号上绑定");
  701. }
  702. }
  703. //会长的时候增加结算周期
  704. if (Db::table('nw_channel')->where(['id' => $id])->value('level') == 1) {
  705. $updChannel['cps_settle_period'] = $_POST['cps_settle_period'];
  706. $updChannel['mcps_settle_period'] = $_POST['mcps_settle_period'];
  707. unset($_POST['cps_settle_period']);
  708. unset($_POST['mcps_settle_period']);
  709. }
  710. $result = $this->adminModel->update($_POST);
  711. $resultChannel = model('channel')->where('id', '=', intval($_POST['channel_id']))->update($updChannel);
  712. $result2 = model('Channel')->saveAll($list);
  713. /*
  714. if(get_channel_level(intval($_POST['channel_id']))==1){ //是否是一级渠道
  715. $ChannelInfoData['update_time'] = time();
  716. $ChannelInfo = model('ChannelInfo')->where('channel_id', '=', intval($_POST['channel_id']))->find();
  717. if(!empty($ChannelInfo)){
  718. $result3 = model('ChannelInfo')->save($ChannelInfoData,array('channel_id'=>intval($_POST['channel_id'])));
  719. }
  720. else{
  721. $ChannelInfoData['admin_id'] = session('ADMIN_ID');
  722. $ChannelInfoData['create_time'] = time();
  723. $result3 = model('ChannelInfo')->insert($ChannelInfoData);
  724. }
  725. }
  726. else{
  727. $result3 = true;
  728. }
  729. if ($result !== false && $result2 !== false && $result3 !== false) {
  730. */
  731. if ($result !== false && $result2 !== false) {
  732. Db::commit();
  733. // 写日志
  734. $channelMessageStr = '密文';
  735. if($show_full_account){
  736. $channelMessageStr = '明文';
  737. }
  738. $messageStr = '冻结';
  739. if($_POST['status']){
  740. $messageStr = '正常';
  741. }
  742. $channel_name = get_channel_name($_POST['channel_id']);
  743. if (Db::table('nw_channel')->where(['id' => $id])->value('level') == 1) {
  744. $cpsStr = '日结';
  745. if ($updChannel['cps_settle_period'] == 1) {
  746. $cpsStr = '周结';
  747. }
  748. $mcpsStr = '日结';
  749. if ($updChannel['mcps_settle_period'] == 1) {
  750. $mcpsStr = '周结';
  751. }
  752. $this->insertLog($this->current_node, "编辑子渠道:".$channel_name.",用户账号:".$channelMessageStr.",状态:".$messageStr.",专服结算方式:".$cpsStr.",混服结算方式:".$mcpsStr,42);
  753. } else{
  754. $this->insertLog($this->current_node, "编辑子渠道:".$channel_name.",用户账号:".$channelMessageStr.",状态:".$messageStr,42);
  755. }
  756. $this->request->param('id', 0, 'intval');
  757. if ($type == 1) {
  758. $this->success("保存成功!",'Channel/leaguesmanage');
  759. }else{
  760. $this->success("保存成功!",'Channel/index');
  761. }
  762. } else {
  763. Db::rollback();
  764. $this->error("保存失败!");
  765. }
  766. }
  767. }
  768. public function delete()
  769. {
  770. $id = $this->request->param('id', 0, 'intval');
  771. Db::startTrans();
  772. try {
  773. if ($this->adminModel->delete($id) === false) {
  774. throw new Exception('删除失败');
  775. }
  776. $channelModel = model('channel');
  777. $channelModel->where('id', '=', $id)->delete();
  778. Db::commit();
  779. } catch (\Exception $e) {
  780. Db::rollback();
  781. $this->error("删除失败!");
  782. }
  783. $this->success("删除成功!");
  784. }
  785. /**
  786. * 渠道停用
  787. *
  788. */
  789. public function ban()
  790. {
  791. $id = $this->request->param('id', 0, 'intval');
  792. if (!empty($id)) {
  793. $adminInfo = model('ChannelAdmin')->where(["id" => $id])->find();
  794. if(empty($adminInfo)){
  795. $this->error('不存在该记录,渠道停用失败!');
  796. }
  797. Db::startTrans();
  798. $result = $this->adminModel->where(["id" => $id])->setField('status', '0');
  799. if($adminInfo['channel_id']){
  800. $result2 = model('channel')->where(["id" => $adminInfo['channel_id']])->setField('status', '0');
  801. }
  802. else{
  803. $result2 = true;
  804. }
  805. if ($result !== false && $result2 !== false) {
  806. Db::commit();
  807. if($adminInfo['channel_id']){
  808. // 写日志
  809. $channelInfo = model('channel')->where(["id" => $adminInfo['channel_id']])->find();
  810. $channelMessageStr = '密文';
  811. if($channelInfo['show_full_account']){
  812. $channelMessageStr = '明文';
  813. }
  814. $channel_name = get_channel_name($adminInfo['channel_id']);
  815. $this->insertLog($this->current_node, "编辑子渠道:".$channel_name.",用户账号:".$channelMessageStr.",状态:冻结",42);
  816. }
  817. $this->success("渠道停用成功!");
  818. } else {
  819. Db::rollback();
  820. $this->error('渠道停用失败!');
  821. }
  822. } else {
  823. $this->error('数据传入失败!');
  824. }
  825. }
  826. /**
  827. * 渠道开启
  828. *
  829. */
  830. public function cancelBan()
  831. {
  832. $id = $this->request->param('id', 0, 'intval');
  833. if (!empty($id)) {
  834. $adminInfo = model('ChannelAdmin')->where(["id" => $id])->find();
  835. if(empty($adminInfo)){
  836. $this->error('不存在该记录,渠道启用失败!');
  837. }
  838. Db::startTrans();
  839. $result = $this->adminModel->where(["id" => $id])->setField('status', '1');
  840. if($adminInfo['channel_id']){
  841. $result2 = model('channel')->where(["id" => $adminInfo['channel_id']])->setField('status', '1');
  842. }
  843. else{
  844. $result2 = true;
  845. }
  846. if ($result !== false && $result2 !== false) {
  847. Db::commit();
  848. if($adminInfo['channel_id']){
  849. // 写日志
  850. $channelInfo = model('channel')->where(["id" => $adminInfo['channel_id']])->find();
  851. $channelMessageStr = '密文';
  852. if($channelInfo['show_full_account']){
  853. $channelMessageStr = '明文';
  854. }
  855. $channel_name = get_channel_name($adminInfo['channel_id']);
  856. $this->insertLog($this->current_node, "编辑子渠道:".$channel_name.",用户账号:".$channelMessageStr.",状态:正常",42);
  857. }
  858. $this->success("渠道启用成功!");
  859. } else {
  860. Db::rollback();
  861. $this->error('渠道启用失败!');
  862. }
  863. } else {
  864. $this->error('数据传入失败!');
  865. }
  866. }
  867. public function down() {
  868. $channel_id = input('channel_id/d');
  869. $game_id = input('game_id/d');
  870. $downChannel = new SubChannel;
  871. $downChannel->down($channel_id, $game_id);
  872. }
  873. /**
  874. * 渠道登录页管理
  875. */
  876. public function loginPage(){
  877. if ($this->request->isPost()){
  878. Db::startTrans();
  879. $pictureModel = model('ChannelLoginPicture');
  880. $res = [true,true,true,true];
  881. for ($i=1; $i<5; $i++){
  882. $operation_type = input('post.operation_type_' . $i, 0 , 'intval');
  883. $operation_id = input('post.operation_id_' . $i, 0 , 'intval');
  884. $address = input('post.address_' . $i, '', 'trim');
  885. $ifJump = input('post.ifJump_' . $i);
  886. $picture_arr = $this->upFile('carrousel_' . $i);
  887. if (!preg_match("/^http(s)?:\\/\\/.+/",$address) && $address != ''){
  888. // 回滚事务
  889. Db::rollback();
  890. $this->error('请输入正确的网址');
  891. }
  892. if (!$picture_arr['code'] && $address != '' && $operation_id == 0 && $operation_type != 2){
  893. // 回滚事务
  894. Db::rollback();
  895. $this->error('未上传图片,不能填写跳转地址!');
  896. }
  897. $condition = [];
  898. if ($ifJump == 'on'){
  899. $condition['isjump'] = 0;
  900. }else{
  901. $condition['isjump'] = 1;
  902. }
  903. $condition['url'] = $address;
  904. if ($picture_arr['code']){
  905. $condition['filename'] = $picture_arr['data'];
  906. }
  907. // 新增
  908. if ($operation_type == 1 && $operation_id == 0){
  909. $condition['create_time'] = time();
  910. $res[$i-1] = Db::table('nw_channel_login_picture')->insertGetId($condition);
  911. }
  912. // 删除
  913. if ($operation_type == 2 && $operation_id != 0){
  914. $res[$i-1] = $pictureModel::destroy(['id' => $operation_id]);
  915. }
  916. // 修改
  917. if (($operation_type == 3 || $operation_type == 0) && $operation_id != 0){
  918. $condition['update_time'] = time();
  919. $res[$i-1] = Db::table('nw_channel_login_picture')->where('id', $operation_id)->update($condition);
  920. }
  921. //$res[$i-1] = ( $res[$i-1]==0 ? true :$res[$i-1] );
  922. }
  923. if ($res[0] && $res[1] && $res[2] && $res[3]){
  924. // 提交事务
  925. Db::commit();
  926. $this->success('提交成功!');
  927. }else{
  928. // 回滚事务
  929. Db::rollback();
  930. $this->error('提交失败!');
  931. }
  932. exit();
  933. }
  934. $list = model('ChannelLoginPicture')->field('id,filename,url,isjump')->limit(4)->select();
  935. $arr = [];
  936. foreach ($list as $v){
  937. $arr[] = ['id'=>$v['id'], 'filename'=>$v['filename'], 'url'=>$v['url'], 'isjump'=>$v['isjump']];
  938. }
  939. for ($i=1; $i<=4-count($list); $i++){
  940. $arr[] = ['id'=>0, 'filename'=>'', 'url'=>'', 'isjump'=>0];
  941. }
  942. $this->assign('list', $arr);
  943. return $this->fetch('loginpage');
  944. }
  945. /**
  946. * 渠道反馈管理
  947. */
  948. public function feedback(){
  949. $condition = [];
  950. $order_num = input('order_num','','trim');
  951. $title = input('title','','trim');
  952. $channelid = input('channel_id',0,'intval');
  953. $start = $this->request->param('start_time');
  954. $end = $this->request->param('end_time');
  955. $reply = input('is_reply');
  956. if (!empty($order_num)){
  957. $condition['a.order_num'] = $order_num;
  958. }
  959. if (!empty($title)){
  960. $condition['a.title'] = ['LIKE', '%'.$title.'%'];
  961. }
  962. if (!empty($channelid)){
  963. $condition['a.channel_id'] = $channelid;
  964. $condition['a.is_anonymous'] = 0;
  965. }
  966. if ($reply != ''){
  967. $condition['a.is_reply'] = $reply;
  968. }
  969. //开始时间和结束时间不为空时
  970. if ($start != '' && $end != '') {
  971. $condition['a.create_time'] = [
  972. ['>=', strtotime($start)],
  973. ['<=', strtotime($end . ' 23:59:59')],
  974. ];
  975. } //开始时间不为空时
  976. elseif ($start != '') {
  977. $condition['a.create_time'] = ['>=', strtotime($start)];
  978. } //结束时间不为空时
  979. elseif ($end != '') {
  980. $condition['a.create_time'] = ['<=', strtotime($end . ' 23:59:59')];
  981. } else {
  982. /*$start = date('Y-m-d', time());
  983. $end = date('Y-m-d', time());
  984. $condition['a.create_time'] = [
  985. ['>=', strtotime($start)],
  986. ['<=', strtotime($end . ' 23:59:59')],
  987. ];*/
  988. }
  989. $feedbackList = model('ChannelFeedback')->alias('a')
  990. ->join('nw_channel channel', 'a.channel_id = channel.id')
  991. ->join('nw_channel_admin admin', 'admin.id = a.operate_id', 'left')
  992. ->where($condition)
  993. ->field('a.*,channel.name as channel_name,admin.username')
  994. ->order("a.is_reply asc, a.create_time DESC")
  995. ->paginate(10,false, ['query' => input('get.')]);
  996. // 获取分页显示
  997. $page = $feedbackList->render();
  998. $this->assign("page", $page);
  999. $this->assign("total", $feedbackList->total()); //总记录数
  1000. $this->assign("list", $feedbackList);
  1001. return $this->fetch();
  1002. }
  1003. public function feedbackReply(){
  1004. $id = input('id',0,'intval');
  1005. if (empty($id)) $this->error('网络出现错误!');
  1006. if ($this->request->isPost()){
  1007. $reply = input('post.reply','','trim');
  1008. if (empty($reply)) $this->error('请输入回复内容');
  1009. model('ChannelFeedback')->save(['reply'=>$reply,'is_reply'=>1,'operate_id'=>session('ADMIN_ID')],['id'=>$id]);
  1010. $this->success('编辑成功!','feedback');
  1011. }
  1012. $info = model('ChannelFeedback')->alias('a')
  1013. ->join('nw_channel channel', 'a.channel_id = channel.id')
  1014. ->where(['a.id'=>$id])
  1015. ->field('a.*,channel.name as channel_name')
  1016. ->find();
  1017. // 文件路径拼接处理
  1018. $imgarr = $filearr = [];
  1019. if (!empty($info['file'])){
  1020. $allFileArr = explode(",", $info['file']);
  1021. foreach ($allFileArr as $v){
  1022. $nameArr = explode("/", $v);
  1023. $name = $nameArr[count($nameArr)-1];
  1024. if (strstr($v,'jpg') || strstr($v,'png') || strstr($v,'bmp') ){
  1025. $imgarr[] = ['path'=>$v,'name'=>$name];
  1026. }else{
  1027. $filearr[] = ['path'=>$v,'name'=>$name];
  1028. }
  1029. }
  1030. }
  1031. $this->assign('info',$info);
  1032. $this->assign('imgarr',$imgarr);
  1033. $this->assign('filearr',$filearr);
  1034. return $this->fetch('feedback_reply');
  1035. }
  1036. /**
  1037. * 渠道游戏推荐管理
  1038. */
  1039. public function gameRecommend(){
  1040. // 游戏数据,页面渲染用
  1041. $arr = ['newGame'=>[],'hotGame'=>[],'typeGame'=>[]];
  1042. /*if ($this->request->isGet()){}*/
  1043. $list = Db::name('nw_game_recommend')->alias('a')
  1044. ->join('cy_game b', 'a.gameid=b.id')
  1045. ->join('cy_gameinfo info', 'a.gameid = info.game_id', 'left')
  1046. //->join('cy_gameinfo info', 'a.id = info.game_id', 'left')
  1047. /*->where('b.cooperation_status <> 3')*/
  1048. ->field('a.id,a.gameid,a.type,b.name,b.type as game_type,b.subject,info.mobileicon')->select();
  1049. $gameType = Db::table('cy_gametype')->column('name', 'id');
  1050. foreach ($list as $v) {
  1051. $v['game_type'] = isset($gameType[$v['game_type']]) ? $gameType[$v['game_type']] : '';
  1052. if ($v['type'] == 1) $arr['newGame'][] = $v;
  1053. if ($v['type'] == 2) $arr['hotGame'][] = $v;
  1054. if ($v['type'] == 3) $arr['typeGame'][] = $v;
  1055. }
  1056. // 所有的游戏列表
  1057. $gameList = model('Common/Game')->getAllByCondition('id,name',['cooperation_status'=>['NEQ',3]]);
  1058. // 游戏题材列表
  1059. $gameSubject_List = Db::table('cy_gamesubject')->select();
  1060. /*dump($gameSubject_List);dump($arr);*/
  1061. // 当前要推荐的游戏题材id
  1062. $current_subject = $gameSubject_List[0]['id'];
  1063. if (count($arr['typeGame'])){
  1064. $current_subject = $arr['typeGame'][0]['subject'];
  1065. }
  1066. // 默认题材的所有游戏列表
  1067. $gameList_Subject = model('Common/Game')->getAllByCondition('id,name',['subject'=>$current_subject]);
  1068. // 未来渲染页面,对每个类型的游戏推荐进行数量补足,补足5个
  1069. foreach ($arr as &$value){
  1070. $num = 5 - count($value);
  1071. if ($num){
  1072. for ($i=0; $i<$num; $i++){
  1073. $value[] = ['id'=>0,'gameid'=>0,'type'=>0,'name'=>0,'game_type'=>0,'subject'=>0,'mobileicon'=>0];
  1074. }
  1075. }
  1076. }
  1077. /*dump(count($list));
  1078. dump($arr);*/
  1079. $this->assign('list',$arr);
  1080. $this->assign('game_list',$gameList);
  1081. $this->assign('subject_List',$gameSubject_List);
  1082. $this->assign('game_list_subject',$gameList_Subject);
  1083. $this->assign('current_subject',$current_subject);
  1084. return $this->fetch('game_recommend');
  1085. }
  1086. /**
  1087. * 设置 推荐游戏
  1088. */
  1089. public function setGameRecommend(){
  1090. $gameRecommendModel = Db::name('nw_game_recommend');
  1091. /*$param = $this->request->post();
  1092. dump($param);
  1093. exit;*/
  1094. Db::startTrans();
  1095. $recommend = $this->request->post('type',0,'intval'); // 游戏推荐类型
  1096. $delall = $this->request->post('recommIfReset',0,'intval'); // 是否重置
  1097. // todo 测试
  1098. //$recommend = 3;
  1099. //$delall = 1;
  1100. if (empty($recommend)) $this->error('参数错误');
  1101. // 若重置,则删除该类型的所有推荐游戏
  1102. $res_del = true;
  1103. if($delall == 1){
  1104. $res_del = $gameRecommendModel->where('type',$recommend)->delete();
  1105. $res_del = $res_del==0?true:$res_del;
  1106. }
  1107. // 新增 或 更新 推荐游戏
  1108. if ($res_del){
  1109. // todo 测试 todo 测试 todo 测试 todo 测试
  1110. /*$idArr = [7,9,13,14,15];
  1111. $gameidArr = [584,590,591,592,590];
  1112. $operateArr = [0,0,0,0,2];*/
  1113. for ($i=1;$i<6; $i++){
  1114. // 获取参数
  1115. $gameid = $this->request->post('gameid_' . $i , 0 , 'intval');
  1116. $id = $this->request->post('id_' . $i , 0 , 'intval');
  1117. $operate = $this->request->post('ope_' . $i , 0 , 'intval');
  1118. $res = true;
  1119. // todo 测试 todo 测试 todo 测试
  1120. /*$gameid = $gameidArr[$i - 1];
  1121. $id = $idArr[$i - 1];
  1122. $operate = $operateArr[$i - 1];*/
  1123. if ($operate == 0){
  1124. continue;
  1125. }
  1126. // 判断参数是否有误
  1127. if (empty($gameid)){
  1128. Db::rollback();
  1129. $this->error('参数错误');
  1130. }
  1131. // 判断 要新增 或者 更新的 游戏 是否已经存在 推荐列表
  1132. $info = $gameRecommendModel->where(['gameid' =>$gameid])->find();
  1133. if ($info) {
  1134. Db::rollback();
  1135. $this->error('游戏重复,请重新选择');
  1136. }
  1137. $newData = ['gameid' =>$gameid,'operate_id'=>session('ADMIN_ID')];
  1138. // 新增 || ($res_del && $operate == 2)
  1139. if ($operate == 1 || ($delall && $operate == 2)){
  1140. $newData['create_time'] = time();
  1141. $newData['type'] = $recommend;
  1142. $res = $gameRecommendModel->insertGetId($newData);
  1143. }
  1144. // 更新 && !$res_del
  1145. if ($operate == 2 && $delall != 1){
  1146. $newData['update_time'] = time();
  1147. $newData['id'] = $id;
  1148. $res = $gameRecommendModel->update($newData);
  1149. }
  1150. if (!$res){
  1151. Db::rollback();
  1152. $this->error('提交失败 '.$operate);
  1153. }
  1154. }
  1155. DB::commit();
  1156. $this->success('修改成功');
  1157. }else{
  1158. Db::rollback();
  1159. $this->error('提交失败');
  1160. }
  1161. }
  1162. /**
  1163. * 上传文件
  1164. * @param $fileName 上传的文件流key
  1165. * @return array
  1166. */
  1167. public function upFile($fileName)
  1168. {
  1169. $fileUpload = new FileUpload();
  1170. if (empty(request()->file($fileName))) return ['code' => 0 , 'data' => '请上传文件!'];
  1171. $file_path = $fileUpload->set('allowExt' , 'jpg,png,bmp')->set('maxsize' , 1024000 * 3)->set('dir' , 'image/channel_login/')->upload(request()->file($fileName));
  1172. if ( !$file_path) {
  1173. return ['code' => 0 , 'data' => '上传失败,' . $fileUpload->getError()];
  1174. }
  1175. return ['code' => 1 , 'data' => $file_path];
  1176. }
  1177. /**
  1178. * 渠道管理--渠道联系方式明文查看
  1179. */
  1180. public function viewlinkinfo(){
  1181. $Id = $this->request->param('id', 0, 'intval');
  1182. $file = $this->request->param('file' , '' , 'trim');
  1183. if (empty($Id) || empty($file)){
  1184. $this->result('',0,'参数错误!');
  1185. }
  1186. $file = trim($file);
  1187. if ($file == 'mobile'){
  1188. $action = '手机号';
  1189. $info = $this->adminModel->where(['id'=>$Id])->value('mobile');
  1190. $ChannelId = model('ChannelAdmin')->where(['id'=>$Id])->value('channel_id');
  1191. if($ChannelId){
  1192. $ChannelName = $this->channelModel->where(['id'=>$ChannelId])->value('name');
  1193. }
  1194. else{
  1195. $ChannelName = model('ChannelAdmin')->where(['id'=>$Id])->value('username');
  1196. }
  1197. }elseif ($file=='account_qq' || $file=='account_wechat'){
  1198. if($file=='account_qq'){
  1199. $action = 'QQ号';
  1200. }
  1201. else if($file=='account_wechat'){
  1202. $action = '微信号';
  1203. }
  1204. $info = model('ChannelInfo')->where(['channel_id'=>$Id])->value($file);
  1205. $ChannelName = $this->channelModel->where(['id'=>$Id])->value('name');
  1206. }else{
  1207. $this->result('',0,'参数错误!');
  1208. }
  1209. // 记录操作日志
  1210. $this->insertLog($this->current_node,'查看渠道“'.$ChannelName.'”'.$action.':'.$info,45);
  1211. $this->result($info,1,$info);
  1212. }
  1213. /**
  1214. * 渠道管理--渠道支付类型明文查看
  1215. */
  1216. public function viewpayinfo(){
  1217. $Id = $this->request->param('id', 0, 'intval');
  1218. $file = $this->request->param('file' , '' , 'trim');
  1219. // echo $Id."---id----".$file."--file----<br>";
  1220. if (empty($Id) || empty($file)){
  1221. $this->result('',0,'参数错误!');
  1222. }
  1223. $file = trim($file);
  1224. if ($file=='account_type' ||$file=='alipay_realname' || $file=='alipay_account' || $file=='bank_account' || $file=='company_name' || $file=='bank_name' || $file=='linkman_email' || $file=='account_qq' ||$file=='account_wechat'){
  1225. $ChannelInfo = model('ChannelInfo')->where(['channel_id'=>$Id])->find();
  1226. // var_dump($ChannelInfo);
  1227. if($file=='account_type'){
  1228. $action = '账户类型';
  1229. if($ChannelInfo['account_type']=='private'){
  1230. $info = '对私';
  1231. }
  1232. else if($ChannelInfo['account_type']=='public'){
  1233. $info = '对公';
  1234. }
  1235. else{
  1236. $info = '';
  1237. }
  1238. }
  1239. else if($file=='alipay_account'){
  1240. $action = '支付宝账号';
  1241. if($ChannelInfo['account_type']=='private'){
  1242. $info = $ChannelInfo['alipay_account'];
  1243. }
  1244. else{
  1245. $info = '';
  1246. }
  1247. }
  1248. else if($file=='alipay_realname'){
  1249. $action = '支付宝姓名';
  1250. if($ChannelInfo['account_type']=='private'){
  1251. $info = $ChannelInfo['alipay_realname'];
  1252. }
  1253. else{
  1254. $info = '';
  1255. }
  1256. }
  1257. else if($file=='bank_account'){
  1258. $action = '银行账号';
  1259. if($ChannelInfo['account_type']=='public'){
  1260. $info = $ChannelInfo['bank_account'];
  1261. }
  1262. else{
  1263. $info = '';
  1264. }
  1265. }
  1266. else if($file=='company_name'){
  1267. $action = '公司全称';
  1268. if($ChannelInfo['account_type']=='public'){
  1269. $info = $ChannelInfo['company_name'];
  1270. }
  1271. else{
  1272. $info = '';
  1273. }
  1274. }
  1275. else if($file=='bank_name'){
  1276. $action = '开户银行';
  1277. if($ChannelInfo['account_type']=='public'){
  1278. $BanknameArrs = array("1"=>"工商银行","2"=>"建设银行","3"=>"农业银行","4"=>"中国银行","5"=>"招商银行","6"=>"民生银行","7"=>"光大银行","8"=>"交通银行","9"=>"中信银行","10"=>"平安银行","11"=>"兴业银行","12"=>"华夏银行","13"=>"广发银行","14"=>"浦发银行","15"=>"日照银行");
  1279. if(array_key_exists($ChannelInfo['bank_name'],$BanknameArrs)){
  1280. $info = $BanknameArrs{$ChannelInfo['bank_name']};
  1281. }
  1282. else{
  1283. $info = '';
  1284. }
  1285. }
  1286. else{
  1287. $info = '';
  1288. }
  1289. }
  1290. else if($file=='linkman_email'){
  1291. $action = '联系人邮箱';
  1292. if($ChannelInfo['account_type']=='public'){
  1293. $info = $ChannelInfo['linkman_email'];
  1294. }
  1295. else{
  1296. $info = '';
  1297. }
  1298. }
  1299. }else{
  1300. $this->result('',0,'参数错误!');
  1301. }
  1302. $ChannelName = $this->channelModel->where(['id'=>$Id])->value('name');
  1303. // 记录操作日志
  1304. $this->insertLog($this->current_node,'查看渠道“'.$ChannelName.'”'.$action.':'.$info,46);
  1305. $this->result($info,1,$info);
  1306. }
  1307. private function checkHasActionPriv($userId,$module,$controller,$action)
  1308. {
  1309. if (empty($userId)) {
  1310. return false;
  1311. }
  1312. // 如果用户id是1,则无需判断
  1313. if ($userId == 1) {
  1314. return true;
  1315. }
  1316. if(!$module || !$controller || !$action){
  1317. return false;
  1318. }
  1319. $rule = $module . $controller . $action;
  1320. // action检测
  1321. $actionCheck = in_array(strtolower($action),
  1322. array_map(function ($val){
  1323. return strtolower($val);
  1324. }, $this->noCheckAuth)
  1325. );
  1326. $notRequire = ["adminIndexindex", "adminMainindex"];
  1327. if (!in_array($rule, $notRequire) &&
  1328. ! $actionCheck) {
  1329. $authObj = new \app\common\logic\Auth();
  1330. $name = strtolower($module . "/" . $controller . "/" . $action);
  1331. return $authObj->check($userId, $name, 'or');
  1332. } else {
  1333. return true;
  1334. }
  1335. }
  1336. public function getGaneByType(){
  1337. $current_subject = input('type',0,'intval');
  1338. if (empty($current_subject)){
  1339. $this->error('请选择游戏题材!');
  1340. }
  1341. // 默认题材的所有游戏列表
  1342. $gameList_Subject = model('Common/Game')->getAllByCondition('id,name',['subject'=>$current_subject]);
  1343. $this->success('','',$gameList_Subject);
  1344. }
  1345. /**
  1346. * 公会保证金
  1347. *
  1348. * @return mixed
  1349. */
  1350. public function deposit() {
  1351. if ($this->request->isPost()){
  1352. $channel_id = input('post.channel_id',0,'intval');
  1353. $deposit_amt = input('post.deposit_amt',0,'floatval');
  1354. $remark = input('post.remark','','trim');
  1355. if(!$channel_id){
  1356. $this->error("请选择要操作的公会");
  1357. }
  1358. $channelInfo = model("Channel")->field('id,name,level,status,deposit_amt')->where(['id'=>$channel_id])->find();
  1359. if(!$channelInfo || $channelInfo['level']<>1){
  1360. $this->error("您选择设置保证金的公会不存在");
  1361. }
  1362. Db::startTrans();
  1363. try {
  1364. $updData['deposit_amt'] = $deposit_amt;
  1365. if($remark){
  1366. $updData['remark'] = $remark;
  1367. }
  1368. $updData['update_time'] = time();
  1369. $updResult = model("Channel")->where(['id'=>$channel_id])->update($updData);
  1370. if (!$updResult) {
  1371. $this->error("更新系统参数错误,请刷新后重试");
  1372. }
  1373. Db::commit();
  1374. $message = '设置公会保证金:管理员"'.session('USERNAME').'" 设置了公会保证金金额,公会账号:'.$channelInfo['name'].',金额:'.$deposit_amt.'元 。操作时间:'.date('Y-m-d H:i:s');
  1375. $this->insertLog($this->current_node,$message, 401);
  1376. } catch (Exception $e) {
  1377. Db::rollback();
  1378. $this->error("添加失败: " . $e->getMessage());
  1379. }
  1380. $this->success("公会保证金设置成功");
  1381. }
  1382. $channel_id = intval(request()->get('channelid'));
  1383. if(!$channel_id){
  1384. $this->error("请选择要操作的公会");
  1385. }
  1386. $channelInfo = model("Channel")->field('id,name,level,status,deposit_amt')->where(['id'=>$channel_id])->find();
  1387. if(!$channelInfo || $channelInfo['level']<>1){
  1388. $this->error("您选择设置保证金的公会不存在");
  1389. }
  1390. $this->assign('channel_id', $channel_id);
  1391. $this->assign('channelInfo', $channelInfo);
  1392. return $this->fetch();
  1393. }
  1394. // 修改是否聚合用户状态
  1395. public function editGhStatus(){
  1396. $id = input('channelid', '');
  1397. $status = input('gh_status', '');
  1398. if(!isset($id)){
  1399. $this->error("渠道标识ID参数有误!");
  1400. }
  1401. if(!isset($status) && !in_array($status, [0, 1])){
  1402. $this->error("状态参数有误!");
  1403. }
  1404. $data['gh_status'] = $status;
  1405. $data['update_time'] = time();
  1406. if ($this->channelModel->where(['id' => $id])->update($data)){
  1407. $this->success('修改成功!');
  1408. }else{
  1409. $this->error('修改失败!');
  1410. }
  1411. }
  1412. }