Purchased.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\contract\controller;
  15. use app\base\BaseController;
  16. use app\contract\model\Purchased as PurchasedModel;
  17. use app\contract\validate\PurchasedValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Purchased extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new PurchasedModel();
  31. }
  32. public function datalist()
  33. {
  34. if (request()->isAjax()) {
  35. $param = get_params();
  36. $where = [];
  37. if (!empty($param['keywords'])) {
  38. $where[] = ['p.title', 'like', '%' . $param['keywords'] . '%'];
  39. }
  40. if (isset($param['status']) && $param['status']!='') {
  41. $where[] = ['p.status', '=', $param['status']];
  42. }
  43. if (!empty($param['cate_id'])) {
  44. $cate_id_array = get_cate_son('PurchasedCate',$param['cate_id']);
  45. $where[] = ['p.cate_id', 'in', $cate_id_array];
  46. }
  47. $where[] = ['p.delete_time', '=', 0];
  48. $list = $this->model->datalist($where, $param);
  49. return table_assign(0, '', $list);
  50. } else {
  51. return view();
  52. }
  53. }
  54. //新建编辑
  55. public function add()
  56. {
  57. $param = get_params();
  58. if (request()->isAjax()) {
  59. $param['purchase_price'] = empty($param['purchase_price'])?0:$param['purchase_price'];
  60. if (!empty($param['id']) && $param['id'] > 0) {
  61. try {
  62. validate(PurchasedValidate::class)->scene('edit')->check($param);
  63. } catch (ValidateException $e) {
  64. // 验证失败 输出错误信息
  65. return to_assign(1, $e->getError());
  66. }
  67. $this->model->edit($param);
  68. } else {
  69. try {
  70. validate(PurchasedValidate::class)->scene('add')->check($param);
  71. } catch (ValidateException $e) {
  72. // 验证失败 输出错误信息
  73. return to_assign(1, $e->getError());
  74. }
  75. $param['admin_id'] = $this->uid;
  76. $this->model->add($param);
  77. }
  78. } else {
  79. $id = isset($param['id']) ? $param['id'] : 0;
  80. if($id>0){
  81. $detail = $this->model->getById($id);
  82. if($detail['file_ids'] !=''){
  83. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  84. $detail['file_array'] = $file_array;
  85. }
  86. View::assign('detail', $detail);
  87. return view('edit');
  88. }
  89. return view();
  90. }
  91. }
  92. //查看
  93. public function view()
  94. {
  95. $param = get_params();
  96. $id = isset($param['id']) ? $param['id'] : 0;
  97. $detail = $this->model->getById($id);
  98. if($detail['cate_id']>0){
  99. $detail['cate'] = Db::name('PurchasedCate')->where('id',$detail['cate_id'])->value('title');
  100. }
  101. if($detail['file_ids'] !=''){
  102. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  103. $detail['file_array'] = $file_array;
  104. }
  105. View::assign('detail', $detail);
  106. return view();
  107. }
  108. //设置
  109. public function set()
  110. {
  111. $param = get_params();
  112. $res = $this->model->strict(false)->field('id,status')->update($param);
  113. if ($res) {
  114. add_log('set', $param['id'], $param);
  115. return to_assign();
  116. }
  117. else{
  118. return to_assign(0, '操作失败');
  119. }
  120. }
  121. /**
  122. * 删除
  123. */
  124. public function del()
  125. {
  126. $param = get_params();
  127. $id = isset($param['id']) ? $param['id'] : 0;
  128. if (request()->isDelete()) {
  129. $this->model->delById($id);
  130. } else {
  131. return to_assign(1, "错误的请求");
  132. }
  133. }
  134. }