DebtController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace pt\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use bizGhs\order\classes\OrderClass;
  6. use common\components\wxUtil;
  7. use Yii;
  8. class DebtController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. // ./yii debt/init
  12. public function actionInit()
  13. {
  14. $list = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  15. if (!empty($list)) {
  16. foreach ($list as $shop) {
  17. $shopId = $shop->id ?? 0;
  18. $mainId = $shop->mainId ?? 0;
  19. $shopName = $shop->shopName ?? '';
  20. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', null, true);
  21. $customDebt = 0;
  22. if (!empty($customList)) {
  23. foreach ($customList as $custom) {
  24. $debtAmount = $custom->debtAmount ?? 0;
  25. $customDebt = bcadd($customDebt, $debtAmount, 2);
  26. }
  27. }
  28. $orderDebt = 0;
  29. $orderList = OrderClass::getAllByCondition(['shopId' => $shopId], null, '*', null, true);
  30. if (!empty($orderList)) {
  31. foreach ($orderList as $order) {
  32. $remainDebtPrice = $order->remainDebtPrice ?? 0;
  33. $orderDebt = bcadd($remainDebtPrice, $orderDebt, 2);
  34. }
  35. }
  36. if (floatval($customDebt) != floatval($orderDebt)) {
  37. echo "门店:{$shopName} 订单和客户欠款不一致 \n";
  38. }
  39. //$lsShopId = $shop->lsShopId ?? 0;
  40. }
  41. }
  42. }
  43. }