Holders.Class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace JinDouYun\Model\Holders;
  3. use JinDouYun\Dao\Customer\DCustomer;
  4. use JinDouYun\Dao\Holders\DHoldersRecord;
  5. use JinDouYun\Dao\Holders\Holders as DHolders;
  6. use Mall\Framework\Core\ErrorCode;
  7. use Mall\Framework\Core\ResultWrapper;
  8. class Holders
  9. {
  10. /**
  11. * 企业ID
  12. * @var
  13. */
  14. private $onlineEnterpriseId;
  15. /**
  16. * 规格名表
  17. * @var Holders
  18. */
  19. private $objHolders;
  20. private $DHoldersRecord;
  21. /**
  22. * MUnits constructor.
  23. * @param $onlineUserId
  24. * @param $onlineEnterpriseId
  25. * @throws \Exception
  26. */
  27. public function __construct($onlineEnterpriseId = '')
  28. {
  29. $this->onlineEnterpriseId = $onlineEnterpriseId;
  30. $this->objHolders = new DHolders('default');
  31. $this->DHoldersRecord = new DHoldersRecord('default');
  32. }
  33. // 添加股东
  34. public function add($data){
  35. if(empty($data)) return ResultWrapper::fail('参数错误!',ErrorCode::$dberror);
  36. if($data['id']){
  37. $where['id']=$data['id'];
  38. $dbResult = $this->objHolders->update($data,$where);
  39. }else{
  40. $dbResult = $this->objHolders->insert($data);
  41. }
  42. return $dbResult;
  43. }
  44. // 获取股东信息
  45. public function getinfo($where){
  46. if(empty($where)) return ResultWrapper::fail('参数错误!',ErrorCode::$dberror);
  47. $dbResult = $this->objHolders->get($where);
  48. if ($dbResult === false) {
  49. return ResultWrapper::fail($this->objHolders->error(), ErrorCode::$dberror);
  50. }
  51. return ResultWrapper::success($dbResult);
  52. }
  53. // 获取股东列表
  54. public function Lst($selectParams){
  55. $limit = $selectParams['limit'];
  56. unset($selectParams['limit']);
  57. $dbResult = $this->objHolders->select($selectParams,'*', 'createTime desc', $limit);
  58. if ($dbResult === false) {
  59. return ResultWrapper::fail($this->objHolders->error(), ErrorCode::$dberror);
  60. }
  61. $countResult = $this->objHolders->count($selectParams);
  62. if ($countResult === false) {
  63. return ResultWrapper::fail($this->objHolders->error(), ErrorCode::$dberror);
  64. }
  65. $return = [
  66. 'data' =>$dbResult,
  67. 'total' => ($countResult) ? intval($countResult) : 0,
  68. ];
  69. return ResultWrapper::success($return);
  70. }
  71. /**
  72. * 增加减少股份
  73. * @param $parma
  74. * @return bool
  75. */
  76. public function edit_shares($parma)
  77. {
  78. $user = $this->objHolders->get(['id' => $parma['id']]);
  79. $str = '';
  80. if ($parma['pm'] == 1) {
  81. if ($parma['type'] == 1){
  82. $before = $user['shares'];
  83. $after = $before + $parma['number'];
  84. $str = 'shares';
  85. }elseif ($parma['type'] == 2){
  86. $before = $user['dends'];
  87. $after = $before + $parma['number'];
  88. $str = 'dends';
  89. }
  90. }elseif ($parma['pm'] == 2) {
  91. if ($parma['type'] == 1){
  92. $str = 'shares';
  93. $before = $user['shares'];
  94. $after = $before - $parma['number'];
  95. }elseif ($parma['type'] == 2){
  96. $str = 'dends';
  97. $before = $user['dends'];
  98. $after = $before - $parma['number'];
  99. }
  100. }
  101. if ($after <= 0) $after = 0;
  102. $insert = [
  103. 'hol_id' => $parma['id'],
  104. 'en_id' => $this->onlineEnterpriseId,
  105. 'number' => $parma['number'],
  106. 'before' => $before,
  107. 'after' => $after,
  108. 'pm' => $parma['pm'],
  109. 'type' => $parma['type'],
  110. 'remarks' => $parma['remarks']
  111. ];
  112. $res1 = $this->DHoldersRecord->insert($insert);
  113. $res = $this->objHolders->update([$str => $after], $parma['id']);
  114. if ($res1 and $res){
  115. return true;
  116. }
  117. return false;
  118. }
  119. public function getSum($id)
  120. {
  121. $where['en_id'] = $id;
  122. $res = $this->objHolders->select($where,'sum(shares) as shares,sum(dends) as dends');
  123. if ($res){
  124. return $res[0];
  125. }
  126. return false;
  127. }
  128. public function delete($where)
  129. {
  130. $data = $this->objHolders->get(['id' => $where['id']]);
  131. $res = $this->objHolders->delete($where);
  132. if ($res){
  133. $db = new DCustomer('default');
  134. $db->setTable('qianniao_customer_'.$this->onlineEnterpriseId);
  135. $db->update(['is_shareholder' => 0], ['id' => $data['us_id']]);
  136. return ResultWrapper::success('删除成功');
  137. }
  138. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  139. }
  140. }