123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * 账户明细管理模块
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/10/30
- * Time: 14:02
- */
- namespace JinDouYun\Model\Finance;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Model\MBaseModel;
- use JinDouYun\Dao\Finance\DAccountDetail;
- class MAccountDetail extends MBaseModel {
- private $objDAccountDetail;
- private $enterpriseId;
- private $userCenterId;
- private $cutTable = 100;
- public function __construct($enterpriseId, $userCenterId)
- {
- $this->userCenterId = $userCenterId;
- $this->enterpriseId = $enterpriseId;
- parent::__construct($enterpriseId, $userCenterId);
- $this->objDAccountDetail = new DAccountDetail('finance');
- }
- /**
- * 添加账户明细
- * @param $params
- * @return ResultWrapper
- * @throws \Exception
- */
- public function addAccountDetail($params)
- {
- $tableName = $this->objDAccountDetail->getTableName('qianniao_account_detail_' . $this->enterpriseId, $params['accountId'], $this->cutTable);
- $this->objDAccountDetail->setTable($tableName);
- $AccountDetailId = $this->objDAccountDetail->insert($params);
- if($AccountDetailId === false){
- return ResultWrapper::fail($this->objDAccountDetail->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($AccountDetailId);
- }
- }
- /**
- * 获取所有账户明细数据
- * @param array $selectParams 过滤条件
- * @return ResultWrapper
- * @throws \Exception
- */
- public function getAllAccountDetail($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $accountId = $selectParams['accountId'];
- unset($selectParams['accountId']);
- $shopId = $selectParams['shopId'];
- unset($selectParams['shopId']);
- $start = $selectParams['start'];
- unset($selectParams['start']);
- $end = $selectParams['end'];
- unset($selectParams['end']);
- $tableName = $this->objDAccountDetail->getTableName('qianniao_account_detail_' . $this->enterpriseId, $accountId, $this->cutTable);
- $this->objDAccountDetail->setTable($tableName);
- $where = "accountId = " . $accountId . ' AND createTime>=' . $start . ' AND createTime<=' . $end;
- if($shopId) {
- $where .= ' And shopId='.$shopId;
- }
- $dbResult = $this->objDAccountDetail->select($where, '*', 'createTime asc', $limit, $offset);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAccountDetail->error(), ErrorCode::$dberror);
- }
- $total = $this->objDAccountDetail->count($where);
- $return = [
- 'data' => self::format($dbResult),
- 'total' => ($total)?intval($total):0,
- ];
- return ResultWrapper::success($return);
- }
- public function format($data) {
- foreach ($data as $k=>$v) {
- $data[$k]['accountCode'] = createCode(StatusCode::$code['account']['prefix'], $v['accountId'], StatusCode::$code['account']['length']);
- switch ($v['financeType']){
- case '线上支付收款':
- case '预存收款':
- case '销售收款':
- case '银行打款收款':
- $data[$k]['sourceNo'] = StatusCode::$noPrefix[17].'-'.$v['sourceNo'];
- break;
- case '采购预付':
- case '采购付款':
- $data[$k]['sourceNo'] = StatusCode::$noPrefix[19].'-'.$v['sourceNo'];
- break;
- case '退款单退款':
- $data[$k]['sourceNo'] = StatusCode::$noPrefix[20].'-'.$v['sourceNo'];
- break;
- }
- }
- return $data;
- }
-
- }
|