123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace JinDouYun\Model\Holders;
- use JinDouYun\Dao\Customer\DCustomer;
- use JinDouYun\Dao\Holders\DHoldersRecord;
- use JinDouYun\Dao\Holders\Holders as DHolders;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- class Holders
- {
- /**
- * 企业ID
- * @var
- */
- private $onlineEnterpriseId;
- /**
- * 规格名表
- * @var Holders
- */
- private $objHolders;
- private $DHoldersRecord;
- /**
- * MUnits constructor.
- * @param $onlineUserId
- * @param $onlineEnterpriseId
- * @throws \Exception
- */
- public function __construct($onlineEnterpriseId = '')
- {
- $this->onlineEnterpriseId = $onlineEnterpriseId;
- $this->objHolders = new DHolders('default');
- $this->DHoldersRecord = new DHoldersRecord('default');
- }
- // 添加股东
- public function add($data){
- if(empty($data)) return ResultWrapper::fail('参数错误!',ErrorCode::$dberror);
- if($data['id']){
- $where['id']=$data['id'];
- $dbResult = $this->objHolders->update($data,$where);
- }else{
- $dbResult = $this->objHolders->insert($data);
- }
- return $dbResult;
- }
- // 获取股东信息
- public function getinfo($where){
- if(empty($where)) return ResultWrapper::fail('参数错误!',ErrorCode::$dberror);
- $dbResult = $this->objHolders->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objHolders->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- // 获取股东列表
- public function Lst($selectParams){
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $dbResult = $this->objHolders->select($selectParams,'*', 'createTime desc', $limit);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objHolders->error(), ErrorCode::$dberror);
- }
- $countResult = $this->objHolders->count($selectParams);
- if ($countResult === false) {
- return ResultWrapper::fail($this->objHolders->error(), ErrorCode::$dberror);
- }
- $return = [
- 'data' =>$dbResult,
- 'total' => ($countResult) ? intval($countResult) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 增加减少股份
- * @param $parma
- * @return bool
- */
- public function edit_shares($parma)
- {
- $user = $this->objHolders->get(['id' => $parma['id']]);
- $str = '';
- if ($parma['pm'] == 1) {
- if ($parma['type'] == 1){
- $before = $user['shares'];
- $after = $before + $parma['number'];
- $str = 'shares';
- }elseif ($parma['type'] == 2){
- $before = $user['dends'];
- $after = $before + $parma['number'];
- $str = 'dends';
- }
- }elseif ($parma['pm'] == 2) {
- if ($parma['type'] == 1){
- $str = 'shares';
- $before = $user['shares'];
- $after = $before - $parma['number'];
- }elseif ($parma['type'] == 2){
- $str = 'dends';
- $before = $user['dends'];
- $after = $before - $parma['number'];
- }
- }
- if ($after <= 0) $after = 0;
- $insert = [
- 'hol_id' => $parma['id'],
- 'en_id' => $this->onlineEnterpriseId,
- 'number' => $parma['number'],
- 'before' => $before,
- 'after' => $after,
- 'pm' => $parma['pm'],
- 'type' => $parma['type'],
- 'remarks' => $parma['remarks']
- ];
- $res1 = $this->DHoldersRecord->insert($insert);
- $res = $this->objHolders->update([$str => $after], $parma['id']);
- if ($res1 and $res){
- return true;
- }
- return false;
- }
- public function getSum($id)
- {
- $where['en_id'] = $id;
- $res = $this->objHolders->select($where,'sum(shares) as shares,sum(dends) as dends');
- if ($res){
- return $res[0];
- }
- return false;
- }
- public function delete($where)
- {
- $data = $this->objHolders->get(['id' => $where['id']]);
- $res = $this->objHolders->delete($where);
- if ($res){
- $db = new DCustomer('default');
- $db->setTable('qianniao_customer_'.$this->onlineEnterpriseId);
- $db->update(['is_shareholder' => 0], ['id' => $data['us_id']]);
- return ResultWrapper::success('删除成功');
- }
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- }
|