123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Gss
- * Date: 2021/4/7 0007
- * Time: 15:26
- */
- namespace JinDouYun\Model\Merchant;
- use JinDouYun\Dao\Merchant\DMerchantApply;
- use JinDouYun\Dao\Merchant\DMerchantDetail;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- class MMerchantDetail
- {
- private $objDMerchantDetail;
- private $objDMerchantApply;
- private $enterpriseId;
- private $userCenterId;
- public function __construct($enterpriseId, $userCenterId)
- {
- $this->userCenterId = $userCenterId;
- $this->enterpriseId = $enterpriseId;
- $this->objDMerchantDetail = new DMerchantDetail('finance');
- $this->objDMerchantApply = new DMerchantApply();
- $this->objDMerchantDetail->setTable('qianniao_merchant_detail_' . $enterpriseId);
- }
- /*
- * 新增收支记录
- * */
- public function addMerchantDetail($params)
- {
- $beginTransactionStatus = $this->objDMerchantDetail->beginTransaction();
- $merchantDetailId = $this->objDMerchantDetail->insert($params);
- if ($merchantDetailId === false) {
- return ResultWrapper::fail($this->objDMerchantDetail->error(), ErrorCode::$dberror);
- }
- if($beginTransactionStatus){
- $this->objDMerchantDetail->commit();
- }
- return ResultWrapper::success($merchantDetailId);
- }
- /*
- * 所有收支记录
- * */
- public function getAllMerchantDetail($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $returnData = [
- 'data' => [],
- 'total' => 0,
- ];
- $whereSql = '';
- // if (isset($selectParams['operatorName']) && !empty($selectParams['operatorName'])) {
- // $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- // $whereSql .= $where . ' operatorName like "%' . $selectParams['operatorName'] . '%"';
- // }
- if (isset($selectParams['merchantId']) && !empty($selectParams['merchantId'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' merchantId = ' . $selectParams['merchantId'];
- }
- if (isset($selectParams['type']) && !empty($selectParams['type'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' type = ' . $selectParams['type'];
- }
- if ( (isset($selectParams['start']) && !empty($selectParams['start']))&&(isset($selectParams['end']) && !empty($selectParams['end'])) ) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' createTime BETWEEN ' . $selectParams['start'] . ' AND '. $selectParams['end'];
- }
- $sql = 'SELECT * FROM ' .$this->objDMerchantDetail->get_Table().$whereSql . ' ORDER BY createTime DESC LIMIT ' . $offset . ' , ' . $limit;
- $dbResult = $this->objDMerchantDetail->query($sql);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDMerchantDetail->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::success($returnData);
- }
- $totalSql = 'SELECT COUNT(1) as count FROM ' .$this->objDMerchantDetail->get_Table() . $whereSql;
- $dbTotalResult = $this->objDMerchantDetail->query($totalSql);
- if ($dbTotalResult === false) {
- return ResultWrapper::fail($this->objDMerchantDetail->error(), ErrorCode::$dberror);
- }
- if(empty($dbTotalResult)){
- return ResultWrapper::success([]);
- }
- $return = [
- 'data' => $dbResult,
- 'total' => $dbTotalResult[0]['count']
- ];
- return ResultWrapper::success($return);
- }
- }
|