Lottery.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller\lottery;
  3. use app\common\controller\Backend;
  4. /**
  5. *
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Lottery extends Backend
  10. {
  11. /**
  12. * Lottery模型对象
  13. * @var \app\admin\model\lottery\Lottery
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\lottery\Lottery;
  20. }
  21. /**
  22. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  23. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  24. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  25. */
  26. //过滤
  27. public function filter($ids = null){
  28. $restore = $this->request->get("restore");
  29. if(isset($restore) && $restore ==1 ){
  30. $deletetime = null;
  31. }else{
  32. $deletetime = time();
  33. }
  34. $row = $this->model->get($ids);
  35. if (!$row) {
  36. $this->error(__('No Results were found'));
  37. }
  38. $adminIds = $this->getDataLimitAdminIds();
  39. if (is_array($adminIds)) {
  40. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  41. $this->error(__('You have no permission'));
  42. }
  43. }
  44. $code = $row->code;
  45. $arr = array_unique(explode('-',$code));//去重
  46. if(count($arr) != 5){
  47. $this->error('录入code有问题!');
  48. }
  49. $tickets = new \app\admin\model\lottery\Tickets;
  50. $tickets = $tickets->withTrashed();//包含软连的数据
  51. // 构建五个字段数组
  52. $fieldsAll = array("t1", "t2", "t3", "t4", "t5");
  53. $where5 = array_combine($fieldsAll,$arr);
  54. //先去掉 5个的
  55. $tickets->where($where5)->update(['deletetime'=>$deletetime]);
  56. //echo $tickets->getLastsql()."</br>";
  57. //print_r($where);exit;
  58. //去掉 4个 的 5 种
  59. foreach ($fieldsAll as $k1 => $v1) {
  60. $fields = $fieldsAll;
  61. unset($fields[$k1]);
  62. foreach ($arr as $k2 => $v2) {
  63. $temp = $arr;
  64. unset($temp[$k2]);
  65. $where4 = array_combine($fields,$temp);
  66. $tickets->where($where4)->update(['deletetime'=>$deletetime]);
  67. //echo $tickets->getLastsql()."</br>";
  68. $where4 = [];
  69. }
  70. }
  71. //去掉 3个的 c5 3 10*10种情况
  72. // 构建两个初始数组
  73. // 构建结果数组
  74. //$results = array();
  75. // 遍历两个数组,生成所有的三个元素的组合
  76. foreach ($fieldsAll as $i => $key) {
  77. foreach (array_slice($fieldsAll, $i + 1) as $j => $key2) {
  78. foreach (array_slice($fieldsAll, $j + $i + 2) as $k => $key3) {
  79. foreach ($arr as $v1) {
  80. foreach (array_slice($arr, array_search($v1, $arr) + 1) as $v2) {
  81. foreach (array_slice($arr, array_search($v2, $arr) + 1) as $v3) {
  82. $where3 = array(
  83. $key => $v1,
  84. $key2 => $v2,
  85. $key3 => $v3
  86. );
  87. //$results[] = $where3;
  88. $tickets->where($where3)->update(['deletetime'=>$deletetime]);
  89. //echo $tickets->getLastsql()."</br>";
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. $this->success("成功处理--".$row['title'].'--号码!');
  97. }
  98. }