Supplier.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\admin\controller\equipment;
  3. use app\common\controller\Backend;
  4. /**
  5. * 供应商管理管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Supplier extends Backend
  10. {
  11. /**
  12. * Supplier模型对象
  13. * @var \app\admin\model\equipment\Supplier
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\equipment\Supplier;
  20. $this->view->assign("statusList", $this->model->getStatusList());
  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 add()
  35. {
  36. if ($this->request->isPost()) {
  37. $this->token();
  38. }
  39. $count = $this->model->withTrashed()->count();
  40. $this->view->assign('supplierCode', 'GYS-' . str_pad($count + 1, 4, "0", STR_PAD_LEFT));
  41. $this->view->assign('relationshipList', build_select('row[relationship]', $this->model->getRelationshipList(), '', ['id' => 'c-relationship', 'class' => 'form-control selectpicker']));
  42. return parent::add();
  43. }
  44. /**
  45. * 编辑
  46. */
  47. public function edit($ids = null)
  48. {
  49. if ($this->request->isPost()) {
  50. $this->token();
  51. }
  52. $row = $this->model->get($ids);
  53. // $this->modelValidate = true;
  54. if (!$row) {
  55. $this->error(__('No Results were found'));
  56. }
  57. $this->view->assign('relationshipList', build_select('row[relationship]', $this->model->getRelationshipList(), $row['relationship'], ['id' => 'c-relationship', 'class' => 'form-control selectpicker']));
  58. return parent::edit($ids);
  59. }
  60. /**
  61. * 合作关系选项
  62. */
  63. public function getRelationshipList()
  64. {
  65. $relationshipList = $this->model->getRelationshipList();
  66. $this->success('', '', $relationshipList);
  67. }
  68. }