| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace bizHd\px\classes;
- use biz\shop\classes\ShopCapitalClass;
- use biz\shop\classes\ShopClass;
- use bizHd\shop\classes\MainClass;
- use bizHd\stat\classes\StatIncomeClass;
- use bizHd\stat\classes\StatStudentClass;
- use common\components\dict;
- use common\components\imgUtil;
- use bizHd\base\classes\BaseClass;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- class PxApplyClass extends BaseClass
- {
- public static $baseFile = '\bizHd\px\models\PxApply';
- //待付款
- const STATUS_UN_CONFIRM = 0;
- //已付款
- const STATUS_CONFIRM = 1;
- public static function addApply($data, $returnObj = false)
- {
- $data['orderSn'] = orderSn::getPxApplySn();
- return PxApplyClass::add($data, $returnObj);
- }
- //学员管理 ssh 2021.3.17
- public static function getApplyList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- $data['list'] = self::groupInfo($data['list']);
- return $data;
- }
- //组合信息 ssh 2021.3.17
- public static function groupInfo($list)
- {
- if (empty($list)) {
- return $list;
- }
- foreach ($list as $key => $val) {
- $list[$key]['customAvatar'] = imgUtil::groupImg($val['customAvatar']);
- $isNew = 0;
- if ($val['status'] == self::STATUS_CONFIRM) {
- if (date("Y-m-d") == date("Y-m-d", strtotime($val['applyTime']))) {
- $isNew = 1;
- }
- } else {
- $list[$key]['applyTime'] = '';
- }
- $list[$key]['isNew'] = $isNew;
- }
- return $list;
- }
- //订单完成 ssh 20210523
- public static function complete($order, $payWay)
- {
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if (isset($order->status) == false || $order->status != self::STATUS_UN_CONFIRM) {
- util::fail('订单不是待确认状态');
- }
- $order->status = self::STATUS_CONFIRM;
- $order->payWay = $payWay;
- $order->save();
- $actPrice = $order->actPrice ?? 0;
- $shopId = $order->shopId;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- Yii::info("没有找到门店48 PxApplyClass::complete() orderId:{$order->id}");
- util::fail('没有找到门店49');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息27');
- }
- $currentTotalIncome = bcadd($main->totalIncome, $actPrice, 2);
- $main->totalIncome = $currentTotalIncome;
- $main->save();
- $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
- //客户付款报名的,增加门店余额
- if (isset($order->customId) && !empty($order->customId)) {
- ShopClass::customKdAddBalance($main, $shop, $actPrice, $order, $capitalType);
- }
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $event = '学员报名';
- $capitalData = [
- 'capitalType' => $capitalType,
- 'io' => 1,
- 'totalIncome' => $currentTotalIncome,
- 'payWay' => $payWay,
- 'amount' => $actPrice,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'event' => $event,
- 'mainId' => $mainId,
- ];
- ShopCapitalClass::addCapital($capitalData);
- //增加新学员数量
- //StatStudentClass::addStudent($shop);
- //每天和每月收入
- StatIncomeClass::updateOrInsert($main, $shop, $order->actPrice);
- }
- }
|