You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Http\Logic;
  3. use App\Common\ReturnData;
  4. use App\Http\Model\UserGoodsHistory;
  5. use App\Http\Requests\UserGoodsHistoryRequest;
  6. use Validator;
  7. class UserGoodsHistoryLogic extends BaseLogic
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function getModel()
  14. {
  15. return new UserGoodsHistory();
  16. }
  17. public function getValidate($data, $scene_name)
  18. {
  19. //数据验证
  20. $validate = new UserGoodsHistoryRequest();
  21. return Validator::make($data, $validate->getSceneRules($scene_name), $validate->getSceneRulesMessages());
  22. }
  23. //列表
  24. public function getList($where = array(), $order = '', $field = '*', $offset = '', $limit = '')
  25. {
  26. $res = $this->getModel()->getList($where, $order, $field, $offset, $limit);
  27. if($res['count'] > 0)
  28. {
  29. foreach($res['list'] as $k=>$v)
  30. {
  31. $res['list'][$k] = $this->getDataView($v);
  32. $goods = logic('Goods')->getOne(array('id'=>$v->goods_id),array('id', 'typeid', 'tuijian', 'click', 'title', 'sn', 'price','litpic', 'pubdate', 'add_time', 'market_price', 'goods_number', 'sale', 'comments','promote_start_date','promote_price','promote_end_date','goods_img','spec','point'));
  33. $res['list'][$k]->goods = $goods;
  34. }
  35. }
  36. return $res;
  37. }
  38. //分页html
  39. public function getPaginate($where = array(), $order = '', $field = '*', $limit = '')
  40. {
  41. $res = $this->getModel()->getPaginate($where, $order, $field, $limit);
  42. return $res;
  43. }
  44. //全部列表
  45. public function getAll($where = array(), $order = '', $field = '*', $limit = '')
  46. {
  47. $res = $this->getModel()->getAll($where, $order, $field, $limit);
  48. /* if($res)
  49. {
  50. foreach($res as $k=>$v)
  51. {
  52. $res[$k] = $this->getDataView($v);
  53. }
  54. } */
  55. return $res;
  56. }
  57. //详情
  58. public function getOne($where = array(), $field = '*')
  59. {
  60. $res = $this->getModel()->getOne($where, $field);
  61. if(!$res){return false;}
  62. $res = $this->getDataView($res);
  63. return $res;
  64. }
  65. //添加
  66. public function add($data = array(), $type=0)
  67. {
  68. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  69. $validator = $this->getValidate($data, 'add');
  70. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  71. if($this->getModel()->getOne(['goods_id'=>$data['goods_id'],'user_id'=>$data['user_id']])){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'亲,已经添加了');}
  72. $data['add_time'] = time();
  73. $res = $this->getModel()->add($data,$type);
  74. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  75. return ReturnData::create(ReturnData::FAIL);
  76. }
  77. //修改
  78. public function edit($data, $where = array())
  79. {
  80. if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);}
  81. $validator = $this->getValidate($data, 'edit');
  82. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  83. $res = $this->getModel()->edit($data,$where);
  84. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  85. return ReturnData::create(ReturnData::FAIL);
  86. }
  87. //删除
  88. public function del($where)
  89. {
  90. if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  91. //$validator = $this->getValidate($where,'del');
  92. //if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  93. $res = $this->getModel()->del($where);
  94. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  95. return ReturnData::create(ReturnData::FAIL);
  96. }
  97. /**
  98. * 数据获取器
  99. * @param array $data 要转化的数据
  100. * @return array
  101. */
  102. private function getDataView($data = array())
  103. {
  104. return getDataAttr($this->getModel(),$data);
  105. }
  106. }