MExpenseSingle.Class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gss
  5. * Date: 2021/3/8 0008
  6. * Time: 15:31
  7. */
  8. namespace JinDouYun\Model\Finance;
  9. use JinDouYun\Controller\Market\VipCard;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use JinDouYun\Dao\Finance\DExpenseSingle;
  14. use JinDouYun\Dao\Finance\DExpenseSingleAccount;
  15. use JinDouYun\Model\Finance\MAccount;
  16. use JinDouYun\Model\Finance\MAccountDetail;
  17. class MExpenseSingle
  18. {
  19. private $objDExpenseSingle;
  20. private $objDExpenseSingleAccount;
  21. private $objMAccount;
  22. private $objMAccountDetail;
  23. private $objMCustomerBalanceDetail;
  24. private $objMCustomerBalance;
  25. private $objMSupplierBalanceDetail;
  26. private $objMSupplierBalance;
  27. private $enterpriseId;
  28. private $userCenterId;
  29. public function __construct($enterpriseId, $userCenterId)
  30. {
  31. $this->userCenterId = $userCenterId;
  32. $this->enterpriseId = $enterpriseId;
  33. $this->objDExpenseSingle = new DExpenseSingle('finance');
  34. $this->objDExpenseSingleAccount = new DExpenseSingleAccount('finance');
  35. $this->objMAccount = new MAccount($enterpriseId, $userCenterId);
  36. $this->objMAccountDetail = new MAccountDetail($enterpriseId, $userCenterId);
  37. $this->objMCustomerBalanceDetail = new MCustomerBalanceDetail($enterpriseId, $userCenterId);
  38. $this->objMCustomerBalance = new MCustomerBalance($enterpriseId, $userCenterId);
  39. $this->objMSupplierBalanceDetail = new MSupplierBalanceDetail($enterpriseId, $userCenterId);
  40. $this->objMSupplierBalance = new MSupplierBalance($enterpriseId, $userCenterId);
  41. $this->objDExpenseSingle->setTable('qianniao_expense_single_' . $enterpriseId);
  42. $this->objDExpenseSingleAccount->setTable('qianniao_expense_single_account_' . $enterpriseId);
  43. }
  44. /**
  45. * 新增费用单
  46. */
  47. public function addExpenseSingle($params)
  48. {
  49. $expenseSingleAccountDate = $params['expenseSingleAccountDate'];
  50. unset($params['expenseSingleAccountDate']);
  51. // 生成编号
  52. $dbResult = $this->objDExpenseSingle->get('createTime >='.strtotime(date('Ymd'.'0:0:0')), 'no', 'createTime desc');
  53. if ($dbResult === false) {
  54. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  55. }
  56. if(empty($dbResult)){
  57. $params['no'] = createSerialNumberByDate('');
  58. }else{
  59. $params['no'] = createSerialNumberByDate($dbResult['no']);
  60. }
  61. //开启事务
  62. $beginTransactionStatus = $this->objDExpenseSingle->beginTransaction();
  63. $expenseSingleId = $this->objDExpenseSingle->insert($params);
  64. if ($expenseSingleId === false) {
  65. $this->objDExpenseSingle->rollBack();
  66. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  67. }
  68. foreach ($expenseSingleAccountDate as $key => $value){
  69. $expenseSingleAccountDate[$key]['expenseSingleId'] = $expenseSingleId;
  70. }
  71. $expenseSingleAccountId = $this->objDExpenseSingleAccount->insert($expenseSingleAccountDate,true);
  72. if ($expenseSingleAccountId === false) {
  73. $this->objDExpenseSingle->rollBack();
  74. return ResultWrapper::fail($this->objDExpenseSingleAccount->error(), ErrorCode::$dberror);
  75. }
  76. if($beginTransactionStatus){
  77. $this->objDExpenseSingle->commit();
  78. }
  79. return ResultWrapper::success($expenseSingleId);
  80. }
  81. /**
  82. * 获取指定的费用单
  83. */
  84. public function getExpenseSingleInfo($expenseSingleId)
  85. {
  86. $dbResult = $this->objDExpenseSingle->get($expenseSingleId);
  87. if($dbResult === false){
  88. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  89. }
  90. if(empty($dbResult)){
  91. return ResultWrapper::success([]);
  92. }
  93. //渲染前缀
  94. $dbResult['no'] = StatusCode::$noPrefix[28] . '-' . $dbResult['no'];
  95. $dbResultAccount = $this->objDExpenseSingleAccount->select(['expenseSingleId'=>$expenseSingleId,'deleteStatus'=>StatusCode::$standard]);
  96. if($dbResultAccount === false){
  97. return ResultWrapper::fail($this->objDExpenseSingleAccount->error(), ErrorCode::$dberror);
  98. }
  99. if(!empty($dbResultAccount)){
  100. $dbResult['accountList'] = $dbResultAccount;
  101. }
  102. return ResultWrapper::success($dbResult);
  103. }
  104. /**
  105. * 编辑指定的费用单
  106. */
  107. public function editExpenseSingle($params)
  108. {
  109. $updateExpenseSingleId = $params['id'];
  110. unset($params['id']);
  111. unset($params['createTime']);
  112. $expenseSingleAccountDate = $params['expenseSingleAccountDate'];
  113. unset($params['expenseSingleAccountDate']);
  114. //累计金额
  115. $params['totalCollectionAmount'] = 0;
  116. $params['totalPreferentialAmount'] = 0;
  117. $params['totalActualAmount'] = 0;
  118. foreach ($expenseSingleAccountDate as $account) {
  119. $account['preferentialAmount'] = !empty($account['preferentialAmount']) ? $account['preferentialAmount'] : 0;
  120. $params['totalCollectionAmount'] += $account['amount'];
  121. $params['totalPreferentialAmount'] += $account['preferentialAmount'];
  122. $params['totalActualAmount'] += ($account['amount'] - $account['preferentialAmount']);
  123. }
  124. //开启事务
  125. $beginTransactionStatus = $this->objDExpenseSingle->beginTransaction();
  126. $receiptRequisitionId = $this->objDExpenseSingle->update($params, $updateExpenseSingleId);
  127. if($receiptRequisitionId === false){
  128. $this->objDExpenseSingle->rollBack();
  129. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  130. }
  131. foreach ($expenseSingleAccountDate as $key => $value){
  132. $id = getArrayItem($value, 'id', 0);
  133. if($id){
  134. $dbResult = $this->objDExpenseSingleAccount->update($value,$id);
  135. }else{
  136. $value['expenseSingleId'] = $updateExpenseSingleId;
  137. $dbResult = $this->objDExpenseSingleAccount->insert($value);
  138. }
  139. }
  140. if ($dbResult === false) {
  141. $this->objDExpenseSingle->rollBack();
  142. return ResultWrapper::fail($this->objDExpenseSingleAccount->error(), ErrorCode::$dberror);
  143. }
  144. if($beginTransactionStatus){
  145. $this->objDExpenseSingle->commit();
  146. }
  147. return ResultWrapper::success($receiptRequisitionId);
  148. }
  149. /**
  150. * 删除指定的费用单
  151. */
  152. public function delExpenseSingle($expenseSingleId)
  153. {
  154. if (empty($expenseSingleId)) {
  155. return ResultWrapper::fail('参数错误', ErrorCode::$paramError);
  156. }
  157. $beginTransactionStatus = $this->objDExpenseSingle->beginTransaction();
  158. $dbResult = $this->objDExpenseSingle->update( ['deleteStatus'=>StatusCode::$delete], $expenseSingleId);
  159. if($dbResult === false){
  160. $this->objDExpenseSingle->rollBack();
  161. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  162. }
  163. unset($dbResult);
  164. $dbResult = $this->objDExpenseSingleAccount->update( ['deleteStatus'=>StatusCode::$delete], ['expenseSingleId'=>$expenseSingleId]);
  165. if($dbResult === false){
  166. $this->objDExpenseSingle->rollBack();
  167. return ResultWrapper::fail($this->objDExpenseSingleAccount->error(), ErrorCode::$dberror);
  168. }
  169. if($beginTransactionStatus){
  170. $this->objDExpenseSingle->commit();
  171. }
  172. return ResultWrapper::success($expenseSingleId);
  173. }
  174. /**
  175. * 获取所有的费用单
  176. */
  177. public function getAllExpenseSingle($selectParams)
  178. {
  179. $limit = $selectParams['limit'];
  180. unset($selectParams['limit']);
  181. $offset = $selectParams['offset'];
  182. unset($selectParams['offset']);
  183. $selectParams['deleteStatus'] = StatusCode::$standard;
  184. $returnData = [
  185. 'data' => [],
  186. 'total' => 0,
  187. ];
  188. $whereSql = '';
  189. if (isset($selectParams['currentUnitId']) && !empty($selectParams['currentUnitId'])) {
  190. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  191. $whereSql .= $where . ' currentUnitId = ' . $selectParams['currentUnitId'];
  192. }
  193. if (isset($selectParams['payType']) && !empty($selectParams['payType'])) {
  194. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  195. $whereSql .= $where . ' payType = ' . $selectParams['payType'];
  196. }
  197. if (isset($selectParams['consumeTypeId']) && !empty($selectParams['consumeTypeId'])) {
  198. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  199. $whereSql .= $where . ' consumeTypeId = ' . $selectParams['consumeTypeId'];
  200. }
  201. if (isset($selectParams['auditStatus']) && !empty($selectParams['auditStatus'])) {
  202. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  203. $whereSql .= $where . ' auditStatus = ' . $selectParams['auditStatus'];
  204. }
  205. if ( (isset($selectParams['start']) && !empty($selectParams['start']))&&(isset($selectParams['end']) && !empty($selectParams['end'])) ) {
  206. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  207. $whereSql .= $where . ' createTime BETWEEN ' . $selectParams['start'] . ' AND '. $selectParams['end'];
  208. }
  209. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  210. $whereSql .= $where . 'deleteStatus = ' . StatusCode::$standard;
  211. $sql = 'SELECT * FROM ' .$this->objDExpenseSingle->get_Table().$whereSql . ' ORDER BY createTime DESC LIMIT ' . $offset . ' , ' . $limit;
  212. $dbResult = $this->objDExpenseSingle->query($sql);
  213. if ($dbResult === false) {
  214. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  215. }
  216. if(empty($dbResult)){
  217. return ResultWrapper::success($returnData);
  218. }
  219. //渲染前缀
  220. foreach ($dbResult as $key => $value){
  221. $dbResult[$key]['no'] = StatusCode::$noPrefix[28] . '-' . $value['no'];
  222. }
  223. $totalSql = 'SELECT COUNT(1) as count FROM ' .$this->objDExpenseSingle->get_Table() . $whereSql;
  224. $dbTotalResult = $this->objDExpenseSingle->query($totalSql);
  225. if ($dbTotalResult === false) {
  226. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  227. }
  228. if(empty($dbTotalResult)){
  229. return ResultWrapper::success([]);
  230. }
  231. $return = [
  232. 'data' => $dbResult,
  233. 'total' => $dbTotalResult[0]['count']
  234. ];
  235. return ResultWrapper::success($return);
  236. }
  237. /**
  238. * 审核费用单
  239. */
  240. public function updateExpenseStatus($params)
  241. {
  242. $dbResult = $this->objDExpenseSingle->get($params['id']);
  243. if ($dbResult === false) {
  244. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  245. }
  246. if(empty($dbResult)){
  247. return ResultWrapper::fail('要审核的单据不存在', ErrorCode::$contentNotExists);
  248. }
  249. if ($dbResult['auditStatus'] === StatusCode::$auditStatus['auditPass']) {
  250. return ResultWrapper::fail('单据已审核', ErrorCode::$actionIsDo);
  251. }
  252. $beginTransactionStatus = $this->objDExpenseSingle->beginTransaction();
  253. //修改审核状态
  254. $updateDbResult = $this->objDExpenseSingle->update(['auditStatus' => StatusCode::$auditStatus['auditPass']], $params['id']);
  255. if ($updateDbResult === false) {
  256. $this->objDExpenseSingle->rollBack();
  257. return ResultWrapper::fail($this->objDExpenseSingle->error(), ErrorCode::$dberror);
  258. }
  259. //计算费用金额
  260. $accountDbResult = $this->objDExpenseSingleAccount->select(['expenseSingleId'=>$params['id']]);
  261. if( $accountDbResult === false ){
  262. return ResultWrapper::fail($this->objDExpenseSingleAccount->error(), ErrorCode::$dberror);
  263. }
  264. if( empty($accountDbResult) ){
  265. return ResultWrapper::success($updateDbResult);
  266. }
  267. foreach ($accountDbResult as $key => $value){
  268. $accountResult = $this->objMAccount->getAccountInfo($value['accountId']);
  269. if(!$accountResult->isSuccess()) {
  270. $this->objDExpenseSingle->rollBack();
  271. return ResultWrapper::fail($accountResult->getData(), $accountResult->getErrorCode());
  272. }
  273. $accountInfo = $accountResult->getData();
  274. if(empty($accountInfo)){
  275. continue;
  276. }
  277. //账户明细
  278. $accountDetail = [
  279. 'accountId'=> $accountInfo['id'],
  280. 'accountCode'=> $accountInfo['accountCode'],
  281. 'accountName'=> $accountInfo['name'],
  282. 'accountNumber'=> $accountInfo['accountNumber'],
  283. 'sourceNo'=>StatusCode::$noPrefix['28'].'-'.$dbResult['no'],
  284. 'sourceId'=>$dbResult['id'],
  285. 'financeType'=> ($dbResult['payType'] == StatusCode::$standard) ? StatusCode::$systemFinanceType[7] :StatusCode::$systemFinanceType[8],
  286. 'beginBalance'=>$accountInfo['money'],
  287. 'shopId'=>$dbResult['shopId'],
  288. 'shopName'=>$dbResult['shopName'],
  289. 'income'=>($dbResult['payType'] == StatusCode::$standard) ? $value['amount'] : 0,
  290. 'expend'=>($dbResult['payType'] == StatusCode::$delete) ? $value['amount'] : 0,
  291. 'endBalance'=>($dbResult['payType'] == StatusCode::$standard) ? bcadd($accountInfo['money'],$value['amount'],4) : bcsub($accountInfo['money'],$value['amount'],4),
  292. 'contactUnit'=>$dbResult['currentUnit'],
  293. 'supplierId'=>0,
  294. 'customerId'=>0,
  295. 'operatorId'=>$this->userCenterId,
  296. 'receiveOrPayPerson'=>$dbResult['manager'],
  297. 'remark'=>'费用单审核通过',
  298. 'createTime'=>time(),
  299. 'updateTime'=>time(),
  300. ];
  301. $result = $this->objMAccountDetail->addAccountDetail($accountDetail);
  302. if ($result->isSuccess() === false) {
  303. $this->objDExpenseSingle->rollBack();
  304. return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  305. }
  306. //给账户减钱
  307. $changedMoney = ($dbResult['payType'] == StatusCode::$standard) ? abs($value['amount']) : -1 * $value['amount'];
  308. $result = $this->objMAccount->updateMoney($value['accountId'], $changedMoney);
  309. if ($result->isSuccess() === false) {
  310. $this->objDExpenseSingle->rollBack();
  311. return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  312. }
  313. }
  314. //往来
  315. // switch ($dbResult['type']){
  316. // case StatusCode::$partion://员工 不需要操作
  317. // break;
  318. // case StatusCode::$delete://客户
  319. // // 获取客户往来余额
  320. // $customerBalance = $this->objMCustomerBalance->getCustomerBalance($dbResult['currentUnitId']);
  321. // if($dbResult['payType'] == StatusCode::$standard){//收入
  322. // $detailData = [
  323. // 'customerId' => $dbResult['currentUnitId'],//'客户id',
  324. // 'receiptTime' => $dbResult['createTime'],//'单据日期',
  325. // 'sourceId' => $dbResult['id'],//'单据编号',
  326. // 'sourceNo' => $dbResult['no'],//'单据编号',
  327. // 'financeType' => '费用单',//'财务类型名称',
  328. // 'financeTypeId' => '',//'财务类型id',
  329. // 'originNo' => '',//'源订单销货号',
  330. // 'originId' => 0,//'源订单销货号',
  331. // 'salesAmount' => $dbResult['totalCollectionAmount'],//总金额
  332. // 'discountMoney' => $dbResult['totalPreferentialAmount'],// '优惠金额',
  333. // 'customerAmount' => $dbResult['totalActualAmount'],// '客户承担金额',
  334. // 'receivableAmount' => $dbResult['totalActualAmount'],// '应收金额',
  335. // 'actualReceivableAmount' => $dbResult['totalActualAmount'],//'实际收款金额',
  336. // 'receivableBalance' => bcsub($customerBalance , $dbResult['totalActualAmount'], 4),//'应收后余额',
  337. // 'remark' => '费用单审核通过,本次优惠后实收' . $dbResult['totalActualAmount'] . '元,优惠'.$dbResult['totalPreferentialAmount'].'元',//'备注',
  338. // 'createTime' => time(),//'创建日期',
  339. // 'updateTime' => time(),//'修改日期',
  340. // ];
  341. // // 添加客户往来余额明细,修改客户往来余额
  342. // $result = $this->objMCustomerBalanceDetail->addCustomerBalanceDetail($detailData);
  343. // if (!$result->isSuccess()) {
  344. // $this->objDExpenseSingle->rollBack();
  345. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  346. // }
  347. //
  348. // // 编辑客户往来余额
  349. // $changedMoney = $dbResult['payType'] ==StatusCode::$standard ? -1 * $dbResult['totalActualAmount'] : abs($dbResult['totalActualAmount']);
  350. // $result = $this->objMCustomerBalance->addCustomerBalance($dbResult['currentUnitId'], $changedMoney);
  351. // if (!$result->isSuccess()) {
  352. // $this->objDExpenseSingle->rollBack();
  353. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  354. // }
  355. // }else{
  356. // $detailData = [
  357. // 'customerId' => $dbResult['currentUnitId'],//'客户id',
  358. // 'receiptTime' => $dbResult['createTime'],//'单据日期',
  359. // 'sourceId' => $dbResult['id'],//'单据编号',
  360. // 'sourceNo' => $dbResult['no'],//'单据编号',
  361. // 'financeType' => '费用单',//'财务类型名称',
  362. // 'financeTypeId' => '',//'财务类型id',
  363. // 'originNo' => '',//'源订单销货号',
  364. // 'originId' => 0,//'源订单销货号',
  365. // 'salesAmount' => $dbResult['totalCollectionAmount'],//总金额
  366. // 'discountMoney' => $dbResult['totalPreferentialAmount'],// '优惠金额',
  367. // 'customerAmount' => $dbResult['totalActualAmount'],// '客户承担金额',
  368. // 'receivableAmount' => $dbResult['totalActualAmount'],// '应收金额',
  369. // 'actualReceivableAmount' => $dbResult['totalActualAmount'],//'实际收款金额',
  370. // 'receivableBalance' => bcadd($customerBalance , $dbResult['totalActualAmount'], 4),
  371. // 'remark' => '费用单审核通过,本次优惠后实收' . $dbResult['totalActualAmount'] . '元,优惠'.$dbResult['totalPreferentialAmount'].'元',//'备注',
  372. // 'createTime' => time(),//'创建日期',
  373. // 'updateTime' => time(),//'修改日期',
  374. // ];
  375. // // 添加客户往来余额明细,修改客户往来余额
  376. // $result = $this->objMCustomerBalanceDetail->addCustomerBalanceDetail($detailData);
  377. // if (!$result->isSuccess()) {
  378. // $this->objDExpenseSingle->rollBack();
  379. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  380. // }
  381. //
  382. // // 编辑客户往来余额
  383. // $changedMoney = $dbResult['payType'] ==StatusCode::$standard ? -1 * $dbResult['totalActualAmount'] : abs($dbResult['totalActualAmount']);
  384. // $result = $this->objMCustomerBalance->addCustomerBalance($dbResult['currentUnitId'], $changedMoney);
  385. // if (!$result->isSuccess()) {
  386. // $this->objDExpenseSingle->rollBack();
  387. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  388. // }
  389. // }
  390. // break;
  391. // case StatusCode::$standard:// 供应商
  392. // $supplierMoney = $this->objMSupplierBalance->getSupplierBalance($dbResult['currentUnitId']);
  393. // if($dbResult['payType'] == StatusCode::$standard){//5收入
  394. // $detailData = [
  395. // 'supplierId' => $dbResult['currentUnitId'],
  396. // 'receiptTime' => $dbResult['createTime'],//'单据日期',
  397. // 'no' => $dbResult['no'],//'单据编号',
  398. // 'financeType' => '费用单',//'财务类型名称',
  399. // 'financeTypeId' => '',//'财务类型id',
  400. // 'sourceNo' => $dbResult['no'],//'源订单销货号',
  401. // 'salesAmount' => $dbResult['totalCollectionAmount'],
  402. // 'discountMoney' => $dbResult['totalPreferentialAmount'],// '优惠金额',
  403. // 'supplierAmount' => $dbResult['totalActualAmount'],//供应商承担金额
  404. // 'shouldPayAmount' => $dbResult['totalActualAmount'],
  405. // 'actualPaidAmount' => $dbResult['totalActualAmount'],//'实际付款金额',
  406. // 'shouldPayBalance' => bcsub($supplierMoney,$dbResult['totalMoney'],2), //'应付款余额' 当前余额 - 付款金额
  407. // 'remark' => '付款单审核通过,本次付给供应商'.$dbResult['totalActualAmount'].'元,优惠'. $dbResult['totalPreferentialAmount'] .'元',//'备注',
  408. // 'createTime' => time(),//'创建日期',
  409. // 'updateTime' => time(),//'修改日期',
  410. // ];
  411. //
  412. // //供应商余额明细
  413. // $result = $this->objMSupplierBalanceDetail->addSupplierBalanceDetail($detailData);
  414. // if (!$result->isSuccess()) {
  415. // $this->objDExpenseSingle->rollBack();
  416. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  417. // }
  418. //
  419. // //供应商余额
  420. // $result = $this->objMSupplierBalance->addSupplierBalance($dbResult['currentUnitId'], -1*$dbResult['totalActualAmount']);
  421. // if (!$result->isSuccess()) {
  422. // $this->objDExpenseSingle->rollBack();
  423. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  424. // }
  425. // }else{
  426. // $detailData = [
  427. // 'supplierId' => $dbResult['currentUnitId'],
  428. // 'receiptTime' => $dbResult['createTime'],//'单据日期',
  429. // 'no' => $dbResult['no'],//'单据编号',
  430. // 'financeType' => '费用单',//'财务类型名称',
  431. // 'financeTypeId' => '',//'财务类型id',
  432. // 'sourceNo' => $dbResult['no'],//'源订单销货号',
  433. // 'salesAmount' => $dbResult['totalCollectionAmount'],
  434. // 'discountMoney' => $dbResult['totalPreferentialAmount'],// '优惠金额',
  435. // 'supplierAmount' => $dbResult['totalActualAmount'],//供应商承担金额
  436. // 'shouldPayAmount' => $dbResult['totalActualAmount'],
  437. // 'actualPaidAmount' => $dbResult['totalActualAmount'],//'实际付款金额',
  438. // 'shouldPayBalance' => bcadd($supplierMoney,$dbResult['totalCollectionAmount'],2), //'应付款余额' 当前余额 - 付款金额
  439. // 'remark' => '付款单审核通过,本次付给供应商'.$dbResult['totalActualAmount'].'元,优惠'. $dbResult['totalPreferentialAmount'] .'元',//'备注',
  440. // 'createTime' => time(),//'创建日期',
  441. // 'updateTime' => time(),//'修改日期',
  442. // ];
  443. //
  444. // //供应商余额明细
  445. // $result = $this->objMSupplierBalanceDetail->addSupplierBalanceDetail($detailData);
  446. // if (!$result->isSuccess()) {
  447. // $this->objDExpenseSingle->rollBack();
  448. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  449. // }
  450. //
  451. // //供应商余额
  452. // $result = $this->objMSupplierBalance->addSupplierBalance($dbResult['currentUnitId'], abs($dbResult['totalActualAmount']));
  453. // if (!$result->isSuccess()) {
  454. // $this->objDExpenseSingle->rollBack();
  455. // return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  456. // }
  457. // }
  458. // }
  459. if($beginTransactionStatus){
  460. $this->objDExpenseSingle->commit();
  461. }
  462. return ResultWrapper::success($updateDbResult);
  463. }
  464. }