| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- namespace hd\controllers;
- use biz\wx\classes\WxMessageClass;
- use bizGhs\notify\classes\NotifyClass;
- use bizGhs\order\classes\RefundOrderClass;
- use bizHd\cg\classes\CgRefundClass;
- use bizHd\cg\classes\CgRefundItemClass;
- use bizHd\cg\services\CgRefundService;
- use bizHd\ghs\classes\GhsClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\shop\classes\ShopClass;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use Yii;
- use common\components\util;
- class CgRefundController extends BaseController
- {
- public $guestAccess = ['list', 'get-refund-data'];
- //取消退款申请 ssh 20230808
- public function actionCancelRefund()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $refund = CgRefundClass::getById($id, true);
- if (empty($refund)) {
- util::fail('没有找到退款单');
- }
- if ($refund->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- CgRefundService::cancelRefundApply($refund);
- $transaction->commit();
- util::complete('取消成功');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("取消出错了,报错信息:" . $exception->getMessage());
- util::fail('取消失败');
- }
- }
- //申请退款 ssh 20230807
- public function actionCreateRefund()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $cg = PurchaseClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到采购单');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- if (in_array($cg->debt, [0, 2]) && $cg->addTime < '2023-10-17 00:00:00') {
- util::fail('10月17日前订单无法申请退款');
- }
- $ghsId = $cg->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有供货商信息');
- }
- $ghsShopId = $ghs->shopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- if (isset($ghsShop->afterSale) && $ghsShop->afterSale == 0) {
- util::fail('售后功能未开通');
- }
- if ($cg->status == PurchaseClass::STATUS_UN_PAY) {
- util::fail("待付款订单,不能申请售后");
- }
- if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
- util::fail("待发货订单,不能申请售后");
- }
- if ($cg->status == PurchaseClass::STATUS_SENDING) {
- util::fail("订单配送中,不能申请售后");
- }
- if ($cg->status == PurchaseClass::STATUS_CANCEL) {
- util::fail("订单已取消,不能申请售后");
- }
- if (isset($cg->clearId) && !empty($cg->clearId)) {
- util::fail('订单已结,不能再申请售后');
- }
- $payTime = $cg->payTime;
- $currentTime = strtotime($payTime);
- $now = time();
- $saleHour = $ghsShop->saleHour;
- $saleHour = ceil($saleHour);
- if ($saleHour > 0) {
- $changeTime = $saleHour * 3600;
- $newTime = bcadd($currentTime, $changeTime);
- if ($now > $newTime) {
- util::fail('超时订单,请联系门店售后');
- }
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //退款类型 1退货并退款 2 仅退款
- $refundType = $post['refundType'] ?? 1;
- if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
- //花材列表结构
- // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
- $productJson = $post['product'] ?? '';
- if (empty($productJson)) {
- util::fail('请选择要退款的花材');
- }
- $productList = json_decode($productJson, true);
- if (!is_array($productList)) {
- util::fail('请选择要退款的花材哦!');
- }
- $post['product'] = $productList;
- } else {
- //仅退款花材直接设置为空
- $post['product'] = [];
- }
- $post['price'] = $post['price'] ?? 0;
- if ($post['price'] <= 0) {
- util::fail("退款金额不能小于0");
- }
- if (bccomp($post['price'], $cg->realPrice, 2) == 1) {
- util::fail("退款金额超过订单金额");
- }
- $post['shopId'] = $this->shopId;
- $post['sjId'] = $this->sjId;
- $post['shopAdminId'] = $this->shopAdminId;
- $post['mainId'] = $this->mainId;
- $shopAdmin = $this->shopAdmin;
- $adminName = $shopAdmin['name'] ?? '';
- $post['shopAdminName'] = $adminName;
- $respond = CgRefundService::createOrder($post, $cg);
- $transaction->commit();
- RefundOrderClass::printRefund($respond);
- $saleRefundId = $respond->saleRefundId ?? 0;
- $saleRefund = RefundOrderClass::getById($saleRefundId, true);
- if (!empty($saleRefund)) {
- NotifyClass::addRefundApplyNotify($saleRefund);
- $saleShopId = $saleRefund->shopId ?? 0;
- $saleShop = Shopclass::getById($saleShopId, true);
- if (!empty($saleShop)) {
- WxMessageClass::ghsHasNewRefundApplyInform($saleShop, $saleRefund);
- }
- }
- util::success($respond);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("申请出错了,报错信息:" . $exception->getMessage());
- util::fail('申请失败');
- }
- }
- //列表
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $cgId = $get['cgId'] ?? 0;
- if (!empty($cgId)) {
- $where['cgId'] = $cgId;
- }
- $list = CgRefundClass::getRefundList($where);
- util::success($list);
- }
- //根据采购单查退款信息 ssh 20210908
- public function actionGetRefundData()
- {
- $id = Yii::$app->request->get('id', 0);
- $refund = CgRefundClass::getById($id);
- if (empty($refund)) {
- util::fail('没有找到退款信息');
- }
- $imgString = $refund['imgList'] ?? '';
- if (!empty($imgString)) {
- $imgArr = json_decode($imgString, true);
- $smallImgList = [];
- $bigImgList = [];
- if (!empty($imgArr)) {
- foreach ($imgArr as $image) {
- $smallImg = imgUtil::groupImg($image) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $bigImg = imgUtil::groupImg($image) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $smallImgList[] = $smallImg;
- $bigImgList[] = $bigImg;
- }
- }
- $refund['imgList'] = $imgArr;
- $refund['smallImgList'] = $smallImgList;
- $refund['bigImgList'] = $bigImgList;
- }
- //未登录用户也需要查看,暂时先注释
- //CgRefundClass::valid($refund, $this->mainId);
- $cgId = $refund['cgId'] ?? 0;
- $cg = PurchaseClass::getById($cgId);
- if (empty($refund)) {
- util::fail('没有退款信息');
- }
- $orderSn = $refund['orderSn'] ?? '';
- $cgItemList = CgRefundItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($cgItemList)) {
- foreach ($cgItemList as $key => $item) {
- $cover = $item['cover'] ?? '';
- $shortCover = $cover;
- $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $cgItemList[$key]['cover'] = $cover;
- $cgItemList[$key]['bigCover'] = $bigCover;
- $cgItemList[$key]['shortCover'] = $shortCover;
- $cgItemList[$key]['itemNum'] = isset($item['itemNum']) ? floatval($item['itemNum']) : 0;
- }
- }
- util::success(['info' => $refund, 'itemList' => $cgItemList, 'cgInfo' => $cg]);
- }
- //根据退款id查退款信息 ssh 20210809
- public function actionGetInfo()
- {
- $id = Yii::$app->request->get('id', 0);
- }
- }
|