Eggjackpotchanchu.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 奖池产出日志
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Eggjackpotchanchu extends Backend
  11. {
  12. /**
  13. * Eggjackpotchanchu模型对象
  14. * @var \app\admin\model\Eggjackpotchanchu
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Eggjackpotchanchu;
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model
  47. ->with(['eggjackpot'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $row) {
  52. $row->getRelation('eggjackpot')->visible(['name']);
  53. }
  54. $result = array("total" => $list->total(), "rows" => $list->items());
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. //奖池产出
  60. public function chanchu(){
  61. if ($this->request->isAjax()) {
  62. $list = Db::name('egg_jackpot')->where('status',1)->order('type asc')->select();
  63. $typea_arr = [
  64. 1 => '普通',
  65. 2 => '高级',
  66. 3 => '大转盘',
  67. ];
  68. foreach($list as $key => &$jackpot){
  69. $jackpot_id = $jackpot['id'];
  70. $jackpot_chanchu = [
  71. 'type' => $typea_arr[$jackpot['type']],
  72. //奖池的
  73. 'jp_giftnum' => Db::name('egg_gift')->where('Jackpot_id',$jackpot_id)->count(), //总礼物数量
  74. 'jp_giftprice' => Db::name('egg_gift')->where('Jackpot_id',$jackpot_id)->sum('price'), //总礼物价值
  75. //抽奖的
  76. 'do_payfee' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->sum('pay_fee'), //物抽总礼奖费用
  77. 'do_usercount' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->group('user_id')->count('id'),//抽奖总人数
  78. 'do_usertimes' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->group('do_no')->count('id'),//抽奖总次数
  79. 'do_giftnum' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->count('id'),//抽奖总礼物数量
  80. 'do_giftprice' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->sum('price'),//抽奖总礼物价值
  81. ];
  82. //产出比
  83. if($jackpot_chanchu['jp_giftprice'] == 0){
  84. $jackpot_chanchu['chanchubi'] = 0;
  85. }else{
  86. $jackpot_chanchu['chanchubi'] = bcdiv($jackpot_chanchu['do_giftprice'],$jackpot_chanchu['jp_giftprice'],2);
  87. }
  88. $jackpot = array_merge($jackpot,$jackpot_chanchu);
  89. }
  90. $result = array("total" => 3, "rows" => $list);
  91. return json($result);
  92. }
  93. return $this->view->fetch();
  94. }
  95. }