Ratio.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\admin\controller\qingdong\general;
  3. use app\common\controller\Backend;
  4. /**
  5. * 员工业绩比例分割
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Ratio extends Backend
  10. {
  11. /**
  12. * Ratio模型对象
  13. * @var \addons\qingdong\model\Ratio
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \addons\qingdong\model\Ratio();
  20. }
  21. /**
  22. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  23. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  24. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  25. */
  26. /**
  27. * 添加比例
  28. * @return string
  29. */
  30. public function add(){
  31. if ($this->request->isAjax()) {
  32. $data = $this->request->post('row/a');
  33. if(empty($data['ratio'])){
  34. $this->error('');
  35. }
  36. $ratio=0;
  37. $data['ratio']=json_decode($data['ratio'],true);
  38. foreach ($data['ratio'] as $datum) {
  39. $ratio+=$datum['ratio'];
  40. }
  41. if($ratio != 100){
  42. $this->error('业绩比例总数必须等于100%');
  43. }
  44. }
  45. return parent::add();
  46. }
  47. /**
  48. * 修改比例
  49. * @return string
  50. */
  51. public function edit($ids=null){
  52. if ($this->request->isAjax()) {
  53. $data = $this->request->post('row/a');
  54. if(empty($data['ratio'])){
  55. $this->error('');
  56. }
  57. $ratio=0;
  58. $data['ratio']=json_decode($data['ratio'],true);
  59. foreach ($data['ratio'] as $datum) {
  60. $ratio+=$datum['ratio'];
  61. }
  62. if($ratio != 100){
  63. $this->error('业绩比例总数必须等于100%');
  64. }
  65. }
  66. return parent::edit($ids);
  67. }
  68. }