GoodChange.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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)->json(['before','after'],true)
  22. ->order('id desc')
  23. ->select();
  24. $result = [];
  25. foreach ($list as $item){
  26. $keys = array_keys($item["before"]);
  27. foreach ($keys as $key){
  28. $temp=[];
  29. $temp['field'] = \app\admin\model\GoodChange::$mapField[$key] ?? "";
  30. $temp['before'] = $item['before'][$key] ?? "";
  31. $temp['after'] = $item['after'][$key] ?? "";
  32. $temp['apply_name'] = $item['apply_name'];
  33. $temp['addtime'] = $item['addtime'];
  34. $result[] = $temp;
  35. }
  36. }
  37. $this->success('获取成功', $result);
  38. }
  39. //详情
  40. public function info(){
  41. $params=$this->request->param(['id'=>''],'post','trim');
  42. $valid=Validate::rule(['id|修改记录ID'=>'require']);
  43. if($valid->check($params)==false){
  44. $this->error($valid->getError());
  45. }
  46. $changeInfo = $this->model
  47. ->json(['before','after'])
  48. ->where(["id"=>$params['id']])
  49. ->findOrEmpty();
  50. if($changeInfo->isEmpty()){
  51. $this->error("修改记录不存在");
  52. }
  53. $this->success("获取成功",$changeInfo);
  54. }
  55. }