MMerchantDetail.Class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gss
  5. * Date: 2021/4/7 0007
  6. * Time: 15:26
  7. */
  8. namespace JinDouYun\Model\Merchant;
  9. use JinDouYun\Dao\Merchant\DMerchantApply;
  10. use JinDouYun\Dao\Merchant\DMerchantDetail;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use Mall\Framework\Core\ResultWrapper;
  14. class MMerchantDetail
  15. {
  16. private $objDMerchantDetail;
  17. private $objDMerchantApply;
  18. private $enterpriseId;
  19. private $userCenterId;
  20. public function __construct($enterpriseId, $userCenterId)
  21. {
  22. $this->userCenterId = $userCenterId;
  23. $this->enterpriseId = $enterpriseId;
  24. $this->objDMerchantDetail = new DMerchantDetail('finance');
  25. $this->objDMerchantApply = new DMerchantApply();
  26. $this->objDMerchantDetail->setTable('qianniao_merchant_detail_' . $enterpriseId);
  27. }
  28. /*
  29. * 新增收支记录
  30. * */
  31. public function addMerchantDetail($params)
  32. {
  33. $beginTransactionStatus = $this->objDMerchantDetail->beginTransaction();
  34. $merchantDetailId = $this->objDMerchantDetail->insert($params);
  35. if ($merchantDetailId === false) {
  36. return ResultWrapper::fail($this->objDMerchantDetail->error(), ErrorCode::$dberror);
  37. }
  38. if($beginTransactionStatus){
  39. $this->objDMerchantDetail->commit();
  40. }
  41. return ResultWrapper::success($merchantDetailId);
  42. }
  43. /*
  44. * 所有收支记录
  45. * */
  46. public function getAllMerchantDetail($selectParams)
  47. {
  48. $limit = $selectParams['limit'];
  49. unset($selectParams['limit']);
  50. $offset = $selectParams['offset'];
  51. unset($selectParams['offset']);
  52. $returnData = [
  53. 'data' => [],
  54. 'total' => 0,
  55. ];
  56. $whereSql = '';
  57. // if (isset($selectParams['operatorName']) && !empty($selectParams['operatorName'])) {
  58. // $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  59. // $whereSql .= $where . ' operatorName like "%' . $selectParams['operatorName'] . '%"';
  60. // }
  61. if (isset($selectParams['merchantId']) && !empty($selectParams['merchantId'])) {
  62. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  63. $whereSql .= $where . ' merchantId = ' . $selectParams['merchantId'];
  64. }
  65. if (isset($selectParams['type']) && !empty($selectParams['type'])) {
  66. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  67. $whereSql .= $where . ' type = ' . $selectParams['type'];
  68. }
  69. if ( (isset($selectParams['start']) && !empty($selectParams['start']))&&(isset($selectParams['end']) && !empty($selectParams['end'])) ) {
  70. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  71. $whereSql .= $where . ' createTime BETWEEN ' . $selectParams['start'] . ' AND '. $selectParams['end'];
  72. }
  73. $sql = 'SELECT * FROM ' .$this->objDMerchantDetail->get_Table().$whereSql . ' ORDER BY createTime DESC LIMIT ' . $offset . ' , ' . $limit;
  74. $dbResult = $this->objDMerchantDetail->query($sql);
  75. if ($dbResult === false) {
  76. return ResultWrapper::fail($this->objDMerchantDetail->error(), ErrorCode::$dberror);
  77. }
  78. if(empty($dbResult)){
  79. return ResultWrapper::success($returnData);
  80. }
  81. $totalSql = 'SELECT COUNT(1) as count FROM ' .$this->objDMerchantDetail->get_Table() . $whereSql;
  82. $dbTotalResult = $this->objDMerchantDetail->query($totalSql);
  83. if ($dbTotalResult === false) {
  84. return ResultWrapper::fail($this->objDMerchantDetail->error(), ErrorCode::$dberror);
  85. }
  86. if(empty($dbTotalResult)){
  87. return ResultWrapper::success([]);
  88. }
  89. $return = [
  90. 'data' => $dbResult,
  91. 'total' => $dbTotalResult[0]['count']
  92. ];
  93. return ResultWrapper::success($return);
  94. }
  95. }