Packageorder.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Packageorder extends Backend
  11. {
  12. /**
  13. * Packageorder模型对象
  14. * @var \app\admin\model\Packageorder
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Packageorder;
  21. $this->view->assign("orderStatusList", $this->model->getOrderStatusList());
  22. $this->view->assign("useStatusList", $this->model->getUseStatusList());
  23. $this->view->assign("isGiftList", $this->model->getIsGiftList());
  24. $this->view->assign("noticeStatusList", $this->model->getNoticeStatusList());
  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(['user','package'])
  48. ->where($where)
  49. ->where('packageorder.order_status',1)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('user')->visible(['firstname','lastname']);
  54. $row->getRelation('package')->visible(['name','name_en']);
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. /**
  62. * 激活
  63. */
  64. public function jihuo(){
  65. $id = input('id',0);
  66. $package_order = Db::name('package_order')->where('id',$id)->find();
  67. if(empty($package_order)){
  68. $this->error(__('请刷新重试'));
  69. }
  70. if($package_order['use_status'] == 1){
  71. $this->error(__('请刷新重试'));
  72. }
  73. $time = time();
  74. $update = [
  75. 'updatetime' => $time,
  76. ];
  77. $update['use_status'] = 1;
  78. $update['starttime'] = $time;
  79. $update['endtime'] = $time + ($package_order['days'] * 86400);
  80. $rs = Db::name('package_order')->where('id',$id)->update($update); //这里不用order_no,主订单和赠品各自激活
  81. $this->success(__('已激活'));
  82. }
  83. }