FCleanPlan.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. class FCleanPlan extends Base {
  7. protected $createTime = 'create_time';
  8. protected $updateTime = 'update_time';
  9. public $table = 'f_clean_plan';
  10. protected $validateName = 'FCleanPlan';
  11. public function updates() {
  12. $data = request()->post();
  13. $data['forms'] = !empty($data['forms'])?implode(',',$data['forms']):'';
  14. $data['addrs'] = !empty($data['addrs'])?implode(',',$data['addrs']):'';
  15. $data['org_id'] = cur_org_id();
  16. $result = validate($this->validateName)->check($data, [], 'add');
  17. if (true !== $result) {
  18. $this->error = validate($this->validateName)->getError();
  19. return false;
  20. }
  21. $id = $data['id'];
  22. unset($data['id']);
  23. $this->startTrans();
  24. try {
  25. if ($id > 0) {
  26. $data['update_time'] = date('Y-m-d H:i:s');
  27. $ret = $this->allowField(true)->save($data, ['id' => $id]);
  28. }
  29. else {
  30. $data['create_time'] = date('Y-m-d H:i:s');
  31. $ret = $this->allowField(true)->save($data);
  32. }
  33. if (!$ret) {
  34. throw new Exception('任务保存失败');
  35. }
  36. $this->commit();
  37. return true;
  38. } catch (Exception $e) {
  39. $this->rollback();
  40. $this->error = $e->getMessage();
  41. return false;
  42. }
  43. }
  44. public function mupdates() {
  45. $data = request()->post();
  46. $data['forms'] = !empty($data['forms'])?implode(',',$data['forms']):'';
  47. $data['addrs'] = !empty($data['addrs'])?implode(',',$data['addrs']):'';
  48. $data['org_id'] = cur_org_id();
  49. $result = validate($this->validateName)->check($data, [], 'madd');
  50. if (true !== $result) {
  51. $this->error = validate($this->validateName)->getError();
  52. return false;
  53. }
  54. $id = $data['id'];
  55. unset($data['id']);
  56. $this->startTrans();
  57. try {
  58. if ($id > 0) {
  59. $data['update_time'] = date('Y-m-d H:i:s');
  60. $ret = $this->allowField(true)->save($data, ['id' => $id]);
  61. }
  62. else {
  63. $data['create_time'] = date('Y-m-d H:i:s');
  64. $ret = $this->allowField(true)->save($data);
  65. }
  66. if (!$ret) {
  67. throw new Exception('任务保存失败');
  68. }
  69. $this->commit();
  70. return true;
  71. } catch (Exception $e) {
  72. $this->rollback();
  73. $this->error = $e->getMessage();
  74. return false;
  75. }
  76. }
  77. }