MAccountDetail.Class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 账户明细管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/30
  7. * Time: 14:02
  8. */
  9. namespace JinDouYun\Model\Finance;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use JinDouYun\Model\MBaseModel;
  14. use JinDouYun\Dao\Finance\DAccountDetail;
  15. class MAccountDetail extends MBaseModel {
  16. private $objDAccountDetail;
  17. private $enterpriseId;
  18. private $userCenterId;
  19. private $cutTable = 100;
  20. public function __construct($enterpriseId, $userCenterId)
  21. {
  22. $this->userCenterId = $userCenterId;
  23. $this->enterpriseId = $enterpriseId;
  24. parent::__construct($enterpriseId, $userCenterId);
  25. $this->objDAccountDetail = new DAccountDetail('finance');
  26. }
  27. /**
  28. * 添加账户明细
  29. * @param $params
  30. * @return ResultWrapper
  31. * @throws \Exception
  32. */
  33. public function addAccountDetail($params)
  34. {
  35. $tableName = $this->objDAccountDetail->getTableName('qianniao_account_detail_' . $this->enterpriseId, $params['accountId'], $this->cutTable);
  36. $this->objDAccountDetail->setTable($tableName);
  37. $AccountDetailId = $this->objDAccountDetail->insert($params);
  38. if($AccountDetailId === false){
  39. return ResultWrapper::fail($this->objDAccountDetail->error(), ErrorCode::$dberror);
  40. }else{
  41. return ResultWrapper::success($AccountDetailId);
  42. }
  43. }
  44. /**
  45. * 获取所有账户明细数据
  46. * @param array $selectParams 过滤条件
  47. * @return ResultWrapper
  48. * @throws \Exception
  49. */
  50. public function getAllAccountDetail($selectParams)
  51. {
  52. $limit = $selectParams['limit'];
  53. unset($selectParams['limit']);
  54. $offset = $selectParams['offset'];
  55. unset($selectParams['offset']);
  56. $accountId = $selectParams['accountId'];
  57. unset($selectParams['accountId']);
  58. $shopId = $selectParams['shopId'];
  59. unset($selectParams['shopId']);
  60. $start = $selectParams['start'];
  61. unset($selectParams['start']);
  62. $end = $selectParams['end'];
  63. unset($selectParams['end']);
  64. $tableName = $this->objDAccountDetail->getTableName('qianniao_account_detail_' . $this->enterpriseId, $accountId, $this->cutTable);
  65. $this->objDAccountDetail->setTable($tableName);
  66. $where = "accountId = " . $accountId . ' AND createTime>=' . $start . ' AND createTime<=' . $end;
  67. if($shopId) {
  68. $where .= ' And shopId='.$shopId;
  69. }
  70. $dbResult = $this->objDAccountDetail->select($where, '*', 'createTime asc', $limit, $offset);
  71. if($dbResult === false){
  72. return ResultWrapper::fail($this->objDAccountDetail->error(), ErrorCode::$dberror);
  73. }
  74. $total = $this->objDAccountDetail->count($where);
  75. $return = [
  76. 'data' => self::format($dbResult),
  77. 'total' => ($total)?intval($total):0,
  78. ];
  79. return ResultWrapper::success($return);
  80. }
  81. public function format($data) {
  82. foreach ($data as $k=>$v) {
  83. $data[$k]['accountCode'] = createCode(StatusCode::$code['account']['prefix'], $v['accountId'], StatusCode::$code['account']['length']);
  84. switch ($v['financeType']){
  85. case '线上支付收款':
  86. case '预存收款':
  87. case '销售收款':
  88. case '银行打款收款':
  89. $data[$k]['sourceNo'] = StatusCode::$noPrefix[17].'-'.$v['sourceNo'];
  90. break;
  91. case '采购预付':
  92. case '采购付款':
  93. $data[$k]['sourceNo'] = StatusCode::$noPrefix[19].'-'.$v['sourceNo'];
  94. break;
  95. case '退款单退款':
  96. $data[$k]['sourceNo'] = StatusCode::$noPrefix[20].'-'.$v['sourceNo'];
  97. break;
  98. }
  99. }
  100. return $data;
  101. }
  102. }