MHoldersBonus.Class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * 分红记录
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Model\Holders;
  10. use Exception;
  11. use JinDouYun\Dao\Holders\DHoldersBonus;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. use Mall\Framework\Core\ResultWrapper;
  15. use JinDouYun\Model\MBaseModel;
  16. use Monolog\Handler\IFTTTHandler;
  17. class MHoldersBonus extends MBaseModel
  18. {
  19. private $obj;
  20. private $cutTable = 250000;
  21. private $enterpriseId;
  22. private $userCenterId;
  23. public function __construct($enterpriseId = '', $userCenterId = '')
  24. {
  25. $this->enterpriseId = $enterpriseId;
  26. $this->userCenterId = $userCenterId;
  27. parent::__construct($this->enterpriseId, $this->userCenterId);
  28. $this->obj = new DHoldersBonus('default');
  29. }
  30. /**
  31. * 列表
  32. * @param $where
  33. * @return mixed
  34. */
  35. public function list($where)
  36. {
  37. $limit = $where['limit'];
  38. unset($where['limit']);
  39. $offset = $where['offset'];
  40. unset($where['offset']);
  41. $join = 'Left Join qianniao_holders as b on a.hol_id = b.id';
  42. $wherein[] = ['a.en_id', '=', $this->enterpriseId];
  43. if (isset($where['name']))
  44. {
  45. $wherein[] = ['b.name|a.hol_id', '=', $where['name']];
  46. }
  47. if (isset($where['hol_id']))
  48. {
  49. $wherein[] = ['a.hol_id', '=', $where['hol_id']];
  50. }
  51. if (isset($where['start_time']))
  52. {
  53. $wherein[] = ['a.createTime', '>=', strtotime($where['start_time'])];
  54. $wherein[] = ['a.createTime', '<=', strtotime( date('Y-m-t 23:59:59', strtotime($where['start_time'])))];
  55. }
  56. if (isset($where['end_time']))
  57. {
  58. $wherein[] = ['a.createTime', '<=', strtotime($where['end_time'])];
  59. }
  60. if (isset($where['type'])){
  61. $wherein[] = ['a.type', '=', $where['type']];
  62. }
  63. $dbResult = $this->obj->select($wherein, 'a.*,b.name', 'id DESC', $limit, $offset, array(), true, false,$join);
  64. $count = $this->obj->count($wherein, [], $join);
  65. if ($dbResult === false) {
  66. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  67. }
  68. $return = [
  69. 'data' => $dbResult,
  70. 'total' => $count,
  71. ];
  72. if($return === false){
  73. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  74. }else{
  75. return ResultWrapper::success($return);
  76. }
  77. }
  78. /**
  79. * 详情
  80. * @param $where
  81. * @return mixed
  82. */
  83. public function details($where)
  84. {
  85. if(empty($where)){
  86. return ResultWrapper::success($where);
  87. }
  88. $dbResult = $this->obj->get($where);
  89. if($dbResult === false){
  90. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  91. }
  92. return ResultWrapper::success(self::formatInfo($dbResult));
  93. }
  94. /**
  95. * Doc: (des="添加")
  96. * User: XMing
  97. * Date: 2020/7/15
  98. * Time: 10:42 上午
  99. * @throws Exception
  100. * @param array $params
  101. * @return ResultWrapper
  102. */
  103. public function insert(array $params)
  104. {
  105. $res = $this->obj->insert($params);
  106. if ($res){
  107. return ResultWrapper::success('添加成功');
  108. }else{
  109. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  110. }
  111. }
  112. public function update($params, $id)
  113. {
  114. $data = $this->obj->get($id);
  115. if (!$data){
  116. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  117. }
  118. $dbResult = $this->obj->update($params,$id);
  119. if($dbResult === false){
  120. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  121. }
  122. return ResultWrapper::success('修改成功');
  123. }
  124. /**
  125. * 格式数据详情
  126. * @param $data
  127. * @return mixed
  128. */
  129. public function formatInfo($data)
  130. {
  131. return $data;
  132. }
  133. public function delete($where)
  134. {
  135. $res = $this->obj->delete($where);
  136. if ($res){
  137. return ResultWrapper::success('删除成功');
  138. }
  139. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  140. }
  141. }