ProgrammeGoods.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\service\InstallService;
  5. use app\common\service\OrderService;
  6. /**
  7. * 快速报价商品管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class ProgrammeGoods extends Backend
  12. {
  13. protected $relationSearch=true;
  14. /**
  15. * ProgrammeGoods模型对象
  16. * @var \app\admin\model\ProgrammeGoods
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\ProgrammeGoods;
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. $pid=$this->request->get('pid');
  39. //当前是否为关联查询
  40. $this->relationSearch = false;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if ($this->request->isAjax()) {
  44. //如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $map=[];
  50. if($pid){
  51. $map['programme_id']=$pid;
  52. }
  53. $list = $this->model
  54. ->with(['goods','sku_obj'])
  55. ->where($where)
  56. ->where($map)
  57. ->order($sort, $order)
  58. ->paginate($limit);
  59. foreach ($list as $row) {
  60. list($row['amount_goods'],$_,$row['amount'])=OrderService::getAmount($row['sku_obj'],$row['goods'],$row['num']);
  61. $row['amount_install']=InstallService::getFee($row);
  62. $row['amount_total']=bcAddAll($row['amount_goods'],$row['amount_install']);
  63. }
  64. $result = array("total" => $list->total(), "rows" => $list->items());
  65. return json($result);
  66. }
  67. return $this->view->fetch();
  68. }
  69. }