GoodsInstall.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. /**
  5. * 安装费管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class GoodsInstall extends Backend
  10. {
  11. protected $noNeedRight=['goods'];
  12. /**
  13. * GoodsInstall模型对象
  14. * @var \app\admin\model\GoodsInstall
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\GoodsInstall;
  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 = false;
  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. ->where($where)
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. foreach ($list as $row) {
  51. $row->visible(['id','name','create_time','update_time']);
  52. }
  53. $result = array("total" => $list->total(), "rows" => $list->items());
  54. return json($result);
  55. }
  56. return $this->view->fetch();
  57. }
  58. public function goods(){
  59. $category=\app\common\model\Category::mall(['goods','goods.sku']);
  60. $data=[];
  61. foreach ($category as $cate){
  62. $data[]=[
  63. 'id'=>$cate['id'],
  64. 'parent'=>'#',
  65. 'state'=>[
  66. 'selected'=>false,
  67. ],
  68. 'text'=>$cate['name'],
  69. 'type'=>'menu',
  70. ];
  71. foreach ($cate['goods'] as $goods){
  72. $data[]=[
  73. 'id'=>"goods-".$goods['id'],
  74. 'parent'=>$cate['id'],
  75. 'state'=>[
  76. 'selected'=>false,
  77. ],
  78. 'text'=>$goods['name'],
  79. 'type'=>'menu',
  80. ];
  81. foreach ($goods['sku'] as $sku){
  82. $data[]=[
  83. 'id'=>"sku-".$sku['id'],
  84. 'parent'=>"goods-".$goods['id'],
  85. 'state'=>[
  86. 'selected'=>false,
  87. ],
  88. 'text'=>$sku['name'],
  89. 'type'=>'menu',
  90. ];
  91. }
  92. }
  93. }
  94. $this->success('',null,$data);
  95. }
  96. public function add()
  97. {
  98. return $this->makeAdd();
  99. }
  100. protected function makeAdd($id=null){
  101. if($this->request->isGet()){
  102. return $this->fetch();
  103. }else{
  104. $data=input('row/a');
  105. $this->validate($data,[
  106. 'name'=>['require'],
  107. 'goods'=>['require'],
  108. 'fee'=>['require','array','min:1']
  109. ]);
  110. if($id) {
  111. $install = $this->model->find($id);
  112. $install['name']=$data['name'];
  113. $install['fee']=$data['fee'];
  114. foreach ($data['goods'] as $good){
  115. }
  116. }else{
  117. $install = new $this->model;
  118. }
  119. }
  120. }
  121. }