Productchufabanci.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 Productchufabanci extends Backend
  11. {
  12. /**
  13. * Productchufabanci模型对象
  14. * @var \app\admin\model\Productchufabanci
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Productchufabanci;
  21. $this->view->assign("chufatypeList", $this->model->getChufatypeList());
  22. $this->view->assign("facheStatusList", $this->model->getFacheStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //当前是否为关联查询
  35. $this->relationSearch = true;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $list = $this->model
  45. ->with(['product','road','car','coach'])
  46. ->where($where)
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. foreach ($list as $row) {
  50. $row->getRelation('product')->visible(['name']);
  51. $row->getRelation('road')->visible(['roadname']);
  52. $row->getRelation('car')->visible(['chepaihao']);
  53. $row->getRelation('coach')->visible(['nickname','mobile']);
  54. }
  55. $result = array("total" => $list->total(), "rows" => $list->items());
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 复制到明天
  62. */
  63. public function copytomorrow(){
  64. $id = input('id',0);
  65. $info = Db::name('product_chufabanci')->where('id',$id)->find();
  66. if($this->request->isPost()){
  67. //准备单条
  68. $newone = $info;
  69. unset($newone['id']);
  70. $newone['ticket_remain'] = $info['ticket_number'];
  71. $newone['chepaihao'] = '';
  72. $newone['sijimobile'] = '';
  73. $newone['fache_status'] = 0;
  74. $newone['fache_time'] = 0;
  75. $newone['daozhan_time'] = 0;
  76. $newone['fache_ready'] = 0;
  77. //
  78. $data = [];
  79. $copydays = input('copydays',1,'intval');
  80. if(empty($copydays)){
  81. $copydays = 1;
  82. }
  83. for($i=1;$i<=$copydays;$i++){
  84. $newone['chufatime'] = $info['chufatime'] + (86400*$i);
  85. $data[] = $newone;
  86. }
  87. Db::name('product_chufabanci')->insertAll($data);
  88. $this->success('复制成功');
  89. }
  90. $this->view->assign('row', $info);
  91. return $this->view->fetch();
  92. }
  93. }