PxApplyClass.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace bizHd\px\classes;
  3. use biz\shop\classes\ShopCapitalClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizHd\shop\classes\MainClass;
  6. use bizHd\stat\classes\StatIncomeClass;
  7. use bizHd\stat\classes\StatStudentClass;
  8. use common\components\dict;
  9. use common\components\imgUtil;
  10. use bizHd\base\classes\BaseClass;
  11. use common\components\orderSn;
  12. use common\components\util;
  13. use Yii;
  14. class PxApplyClass extends BaseClass
  15. {
  16. public static $baseFile = '\bizHd\px\models\PxApply';
  17. //待付款
  18. const STATUS_UN_CONFIRM = 0;
  19. //已付款
  20. const STATUS_CONFIRM = 1;
  21. public static function addApply($data, $returnObj = false)
  22. {
  23. $data['orderSn'] = orderSn::getPxApplySn();
  24. return PxApplyClass::add($data, $returnObj);
  25. }
  26. //学员管理 ssh 2021.3.17
  27. public static function getApplyList($where)
  28. {
  29. $data = self::getList('*', $where, 'addTime DESC');
  30. $data['list'] = self::groupInfo($data['list']);
  31. return $data;
  32. }
  33. //组合信息 ssh 2021.3.17
  34. public static function groupInfo($list)
  35. {
  36. if (empty($list)) {
  37. return $list;
  38. }
  39. foreach ($list as $key => $val) {
  40. $list[$key]['customAvatar'] = imgUtil::groupImg($val['customAvatar']);
  41. $isNew = 0;
  42. if ($val['status'] == self::STATUS_CONFIRM) {
  43. if (date("Y-m-d") == date("Y-m-d", strtotime($val['applyTime']))) {
  44. $isNew = 1;
  45. }
  46. } else {
  47. $list[$key]['applyTime'] = '';
  48. }
  49. $list[$key]['isNew'] = $isNew;
  50. }
  51. return $list;
  52. }
  53. //订单完成 ssh 20210523
  54. public static function complete($order, $payWay)
  55. {
  56. if (empty($order)) {
  57. util::fail('没有找到订单');
  58. }
  59. if (isset($order->status) == false || $order->status != self::STATUS_UN_CONFIRM) {
  60. util::fail('订单不是待确认状态');
  61. }
  62. $order->status = self::STATUS_CONFIRM;
  63. $order->payWay = $payWay;
  64. $order->save();
  65. $actPrice = $order->actPrice ?? 0;
  66. $shopId = $order->shopId;
  67. $shop = ShopClass::getLockById($shopId);
  68. if (empty($shop)) {
  69. Yii::info("没有找到门店48 PxApplyClass::complete() orderId:{$order->id}");
  70. util::fail('没有找到门店49');
  71. }
  72. $mainId = $shop->mainId ?? 0;
  73. $main = MainClass::getLockById($mainId);
  74. if (empty($main)) {
  75. util::fail('没有main信息27');
  76. }
  77. $currentTotalIncome = bcadd($main->totalIncome, $actPrice, 2);
  78. $main->totalIncome = $currentTotalIncome;
  79. $main->save();
  80. $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
  81. //客户付款报名的,增加门店余额
  82. if (isset($order->customId) && !empty($order->customId)) {
  83. ShopClass::customKdAddBalance($main, $shop, $actPrice, $order, $capitalType);
  84. }
  85. $sjId = $order->sjId ?? 0;
  86. $shopId = $order->shopId ?? 0;
  87. $event = '学员报名';
  88. $capitalData = [
  89. 'capitalType' => $capitalType,
  90. 'io' => 1,
  91. 'totalIncome' => $currentTotalIncome,
  92. 'payWay' => $payWay,
  93. 'amount' => $actPrice,
  94. 'sjId' => $sjId,
  95. 'shopId' => $shopId,
  96. 'event' => $event,
  97. 'mainId' => $mainId,
  98. ];
  99. ShopCapitalClass::addCapital($capitalData);
  100. //增加新学员数量
  101. //StatStudentClass::addStudent($shop);
  102. //每天和每月收入
  103. StatIncomeClass::updateOrInsert($main, $shop, $order->actPrice);
  104. }
  105. }