MHoldersRecord.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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\DHoldersRecord;
  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 MHoldersRecord 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 DHoldersRecord('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['pm']))
  48. {
  49. if ($where['pm'] == 1){
  50. $wherein[] = ['a.pm', '=', 1];
  51. }
  52. if ($where['pm'] == 2){
  53. $wherein[] = ['a.pm', '=', 2];
  54. }
  55. }
  56. if (isset($where['type'])){
  57. $wherein[] = ['a.type', '=', $where['type']];
  58. }
  59. if (isset($where['hol_id'])){
  60. $wherein[] = ['hol_id', '=', $where['hol_id']];
  61. }
  62. if (isset($where['start_time']))
  63. {
  64. $wherein[] = ['a.createTime', '>=', strtotime($where['start_time'])];
  65. }
  66. if (isset($where['end_time']))
  67. {
  68. $wherein[] = ['a.createTime', '<=', strtotime($where['end_time'])];
  69. }
  70. $dbResult = $this->obj->select($wherein, 'a.*,b.name', 'id DESC', $limit, $offset, array(), true, false,$join);
  71. $count = $this->obj->count($wherein, [], $join);
  72. if ($dbResult === false) {
  73. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  74. }
  75. $return = [
  76. 'data' => $dbResult,
  77. 'total' => $count,
  78. ];
  79. if($return === false){
  80. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  81. }else{
  82. return ResultWrapper::success($return);
  83. }
  84. }
  85. /**
  86. * 详情
  87. * @param $where
  88. * @return mixed
  89. */
  90. public function details($where)
  91. {
  92. if(empty($where)){
  93. return ResultWrapper::success($where);
  94. }
  95. $dbResult = $this->obj->get($where);
  96. if($dbResult === false){
  97. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  98. }
  99. return ResultWrapper::success(self::formatInfo($dbResult));
  100. }
  101. /**
  102. * Doc: (des="添加")
  103. * User: XMing
  104. * Date: 2020/7/15
  105. * Time: 10:42 上午
  106. * @throws Exception
  107. * @param array $params
  108. * @return ResultWrapper
  109. */
  110. public function insert(array $params)
  111. {
  112. $res = $this->obj->insert($params);
  113. if ($res){
  114. return ResultWrapper::success('添加成功');
  115. }else{
  116. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  117. }
  118. }
  119. public function update($params, $id)
  120. {
  121. $data = $this->obj->get($id);
  122. if (!$data){
  123. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  124. }
  125. $dbResult = $this->obj->update($params,$id);
  126. if($dbResult === false){
  127. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  128. }
  129. return ResultWrapper::success('修改成功');
  130. }
  131. /**
  132. * 格式数据详情
  133. * @param $data
  134. * @return mixed
  135. */
  136. public function formatInfo($data)
  137. {
  138. return $data;
  139. }
  140. public function delete($where)
  141. {
  142. $res = $this->obj->delete($where);
  143. if ($res){
  144. return ResultWrapper::success('删除成功');
  145. }
  146. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  147. }
  148. }