GoodChange.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;
  5. use think\facade\Validate;
  6. class GoodChange extends Base
  7. {
  8. protected $model=null;
  9. public function __construct(App $app) {
  10. parent::__construct($app);
  11. $this->model=new \app\admin\model\GoodChange();
  12. }
  13. //列表详情
  14. public function list(){
  15. $params = $this->request->param(['spuCode'=>'','page' => 1,'size' => 15],'post','trim');
  16. $where = [];
  17. if($params['spuCode'] !== '') {
  18. $where[] = ['spuCode','like',"%{$params['spuCode']}%"];
  19. }
  20. $list = $this->model
  21. ->where($where)
  22. ->order('id desc')
  23. ->paginate(["page"=>$params['page'],"list_rows"=>$params["size"]]);
  24. foreach ($list as $item) {
  25. $item->before = json_decode($item->before);
  26. $item->after = json_decode($item->after);
  27. }
  28. $this->success('获取成功',['list' => $list->items(),'count' => $list->total()]);
  29. }
  30. //详情
  31. public function info(){
  32. $params=$this->request->param(['id'=>''],'post','trim');
  33. $valid=Validate::rule(['id|修改记录ID'=>'require']);
  34. if($valid->check($params)==false){
  35. $this->error($valid->getError());
  36. }
  37. $changeInfo = $this->model->where(["id"=>$params['id']])->findOrEmpty();
  38. if($changeInfo->isEmpty()){
  39. $this->error("修改记录不存在");
  40. }
  41. $changeInfo->before = json_decode($changeInfo->before);
  42. $changeInfo->after = json_decode($changeInfo->after);
  43. $this->success("获取成功",$changeInfo);
  44. }
  45. }