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.

143 lines
4.4 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
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. if($res->count() > 0)
  43. {
  44. foreach($res as $k=>$v)
  45. {
  46. $res[$k] = $this->getDataView($v);
  47. }
  48. }
  49. return $res;
  50. }
  51. //全部列表
  52. public function getAll($where = array(), $order = '', $field = '*', $limit = '')
  53. {
  54. $res = $this->getModel()->getAll($where, $order, $field, $limit);
  55. if($res)
  56. {
  57. foreach($res as $k=>$v)
  58. {
  59. $res[$k] = $this->getDataView($v);
  60. }
  61. }
  62. return $res;
  63. }
  64. //详情
  65. public function getOne($where = array(), $field = '*')
  66. {
  67. $res = $this->getModel()->getOne($where, $field);
  68. if(!$res){return false;}
  69. $res = $this->getDataView($res);
  70. return $res;
  71. }
  72. //添加
  73. public function add($data = array(), $type=0)
  74. {
  75. if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  76. $validator = $this->getValidate($data, 'add');
  77. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  78. if($this->getModel()->getOne(['goods_id'=>$data['goods_id'],'user_id'=>$data['user_id']])){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'亲,已经添加了');}
  79. $data['add_time'] = time();
  80. $res = $this->getModel()->add($data,$type);
  81. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  82. return ReturnData::create(ReturnData::FAIL);
  83. }
  84. //修改
  85. public function edit($data, $where = array())
  86. {
  87. if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);}
  88. $validator = $this->getValidate($data, 'edit');
  89. if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  90. $res = $this->getModel()->edit($data,$where);
  91. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  92. return ReturnData::create(ReturnData::FAIL);
  93. }
  94. //删除
  95. public function del($where)
  96. {
  97. if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  98. //$validator = $this->getValidate($where,'del');
  99. //if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());}
  100. $res = $this->getModel()->del($where);
  101. if($res){return ReturnData::create(ReturnData::SUCCESS,$res);}
  102. return ReturnData::create(ReturnData::FAIL);
  103. }
  104. /**
  105. * 数据获取器
  106. * @param array $data 要转化的数据
  107. * @return array
  108. */
  109. private function getDataView($data = array())
  110. {
  111. return getDataAttr($this->getModel(),$data);
  112. }
  113. }