Account.Class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /**
  3. * 账户管理模块
  4. * Created by PhpStorm.
  5. * User: tpl
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\Finance;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Finance\MAccount;
  14. class Account extends BaseController
  15. {
  16. private $objMAccount;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMAccount = new MAccount($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 添加和编辑账户管理公共字段处理方法
  24. *
  25. * @return array
  26. */
  27. public function commonFieldFilter(){
  28. $params = $this->request->getRawJson();
  29. if( empty($params) ){
  30. $this->sendOutput('参数为空', ErrorCode::$paramError );
  31. }
  32. $accountData = [
  33. 'enterpriseId' => $this->onlineEnterpriseId,
  34. 'type' => getArrayItem($params, 'type', 0),
  35. 'name' => isset($params['name']) ? $params['name'] : '',
  36. 'accountNumber' => isset($params['accountNumber']) ? $params['accountNumber'] : '',
  37. 'beginMoney' => isset($params['beginMoney']) ? intval($params['beginMoney']) : 0,
  38. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  39. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  40. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  41. 'isDefault' => isset($params['isDefault']) ? $params['isDefault'] : StatusCode::$delete,
  42. ];
  43. foreach($accountData as $key => $value){
  44. if(empty($value) && $value !== 0){
  45. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  46. }
  47. }
  48. $accountData['bankAccount'] = getArrayItem($params, 'bankAccount');
  49. $accountData['bankName'] = getArrayItem($params, 'bankName');
  50. $accountData['remark']= isset($params['remark']) ? $params['remark'] : '';
  51. $accountData['money']= $accountData['beginMoney'];
  52. $accountData['createTime'] = time();
  53. $accountData['updateTime'] = time();
  54. // 如果是新行卡类型需要设置开户行名称
  55. if( $accountData['type'] == StatusCode::$financeAccountType['bank'] && empty($params['bankName'])){
  56. $this->sendOutput('bankName参数错误', ErrorCode::$paramError );
  57. }
  58. return $accountData;
  59. }
  60. /**
  61. * 添加账户
  62. */
  63. public function addAccount()
  64. {
  65. $accountData = $this->commonFieldFilter();
  66. $result = $this->objMAccount ->addAccount($accountData);
  67. if($result->isSuccess()){
  68. parent::sendOutput($result->getData());
  69. }else{
  70. parent::sendOutput($result->getData(), $result->getErrorCode());
  71. }
  72. }
  73. /**
  74. * 获取指定账户信息
  75. */
  76. public function getAccountInfo()
  77. {
  78. $accountId = $this->request->param('request_id');
  79. if ( !$accountId ) {
  80. $this->sendOutput('参数错误', ErrorCode::$paramError );
  81. }
  82. $result = $this->objMAccount->getAccountInfo($accountId);
  83. if($result->isSuccess()){
  84. $this->sendOutput($result->getData());
  85. }else{
  86. $this->sendOutput($result->getData(), $result->getErrorCode());
  87. }
  88. }
  89. /**
  90. * 编辑账户
  91. */
  92. public function editAccount()
  93. {
  94. $accountId = $this->request->param('request_id');
  95. if(empty($accountId)){
  96. $this->sendOutput('参数错误', ErrorCode::$paramError);
  97. }
  98. $accountData = $this->commonFieldFilter();
  99. $accountData['id'] = $accountId;
  100. unset($accountData['createTime']);
  101. unset($accountData['beginMoney']);
  102. unset($accountData['money']);
  103. $result = $this->objMAccount->editAccount($accountData);
  104. if($result->isSuccess()){
  105. parent::sendOutput($result->getData());
  106. }else{
  107. parent::sendOutput($result->getData(), $result->getErrorCode());
  108. }
  109. }
  110. /**
  111. * 删除账户
  112. */
  113. public function delAccount()
  114. {
  115. $accountId = $this->request->param('request_id');
  116. if(!$accountId){
  117. $this->sendOutput('参数错误', ErrorCode::$paramError);
  118. }
  119. $result = $this->objMAccount->delAccount($accountId);
  120. if($result->isSuccess()){
  121. parent::sendOutput($result->getData());
  122. }else{
  123. parent::sendOutput($result->getData(), $result->getErrorCode());
  124. }
  125. }
  126. /**
  127. * 账户启用和禁用
  128. */
  129. public function updateAccountStatus()
  130. {
  131. $params = $this->request->getRawJson();
  132. if( empty($params['id']) && empty($params['enableStatus'])){
  133. $this->sendOutput('参数为空', ErrorCode::$paramError );
  134. }
  135. $result = $this->objMAccount->updateAccountStatus($params);
  136. if($result->isSuccess()){
  137. parent::sendOutput($result->getData());
  138. }else{
  139. parent::sendOutput($result->getData(), $result->getErrorCode());
  140. }
  141. }
  142. /**
  143. * 账户默认
  144. */
  145. public function updateAccountDefaultStatus()
  146. {
  147. $params = $this->request->getRawJson();
  148. if( empty($params['id']) && empty($params['isDefault'])){
  149. $this->sendOutput('参数为空', ErrorCode::$paramError );
  150. }
  151. $result = $this->objMAccount->updateAccountDefaultStatus($params);
  152. if($result->isSuccess()){
  153. parent::sendOutput($result->getData());
  154. }else{
  155. parent::sendOutput($result->getData(), $result->getErrorCode());
  156. }
  157. }
  158. /**
  159. * 后台所有账户列表
  160. */
  161. public function getAllAccount()
  162. {
  163. $params = $this->request->getRawJson();
  164. if( empty($params) ){
  165. $this->sendOutput('参数为空', ErrorCode::$paramError );
  166. }
  167. $includeMaster = true;
  168. if(isset($params['shopId']) && !empty($params['shopId'])) {
  169. $selectParams['shopId'] = $params['shopId'];
  170. }
  171. if(!empty($params['includeType']) && $params['includeType']==2){
  172. $includeMaster = false;
  173. }
  174. if(isset($params['enableStatus']) && !empty($params['enableStatus'])) {
  175. $selectParams['enableStatus'] = $params['enableStatus'];
  176. }
  177. if(isset($params['type']) && !empty($params['type'])) {
  178. $selectParams['type'] = $params['type'];
  179. }
  180. if(isset($params['start']) && !empty($params['start'])) {
  181. $selectParams['start'] = $params['start'];
  182. }
  183. if(isset($params['end']) && !empty($params['end'])) {
  184. $selectParams['end'] = $params['end'];
  185. }
  186. if(isset($params['isMem']) && !empty($params['isMem'])){
  187. $selectParams['isMem'] = $params['isMem'];
  188. }
  189. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  190. $selectParams['limit'] = $pageParams['limit'];
  191. $selectParams['offset'] = $pageParams['offset'];
  192. $result = $this->objMAccount->getAllAccount($selectParams,$includeMaster);
  193. if($result->isSuccess()){
  194. $returnData = $result->getData();
  195. $pageData = [
  196. 'pageIndex' => $params['page'],
  197. 'pageSize' => $params['pageSize'],
  198. 'pageTotal' => $returnData['total'],
  199. ];
  200. parent::sendOutput($returnData['data'], 0, $pageData);
  201. }else{
  202. parent::sendOutput($result->getData(), $result->getErrorCode());
  203. }
  204. }
  205. /**
  206. * 财务今日报表
  207. */
  208. public function getTodayStatistics()
  209. {
  210. $params['start'] = $this->request->param('start');
  211. $params['end'] = $this->request->param('end');
  212. $result = $this->objMAccount->getTodayStatistics($params);
  213. if($result->isSuccess()){
  214. parent::sendOutput($result->getData());
  215. }
  216. parent::sendOutput($result->getData(), $result->getErrorCode());
  217. }
  218. }