| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?php
- namespace addons\SecondaryCard\backend\controllers;
- use addons\CloudStock\common\models\CloudStockDeductionDetail;
- use addons\CloudStock\common\models\CloudStockIncreaseDetail;
- use addons\SecondaryCard\common\enums\SecondaryCardEnum;
- use addons\SecondaryCard\common\models\SecondaryCard;
- use addons\SecondaryCard\common\service\SecondaryCardOrderService;
- use addons\SecondaryCard\common\service\SecondaryCardRedemptionCodeService;
- use addons\SecondaryCard\common\service\SecondaryCardService;
- use addons\SecondaryCard\common\service\SecondaryCardUseLogService;
- use common\enums\ApiStatusEnum;
- use common\enums\DownloadEnum;
- use common\enums\RabbitMqEnum;
- use common\helpers\csv\CsvExportHelper;
- use common\helpers\MiniQrCode;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\SecondaryCard\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 次卡列表
- * @Author:hua
- * @Date:2024-02-28 11:04
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|string|void
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $data = SecondaryCardService::getList($params);
- return $this->success('操作成功', $data);
- }
- }
- return $this->render('index', []);
- }
- /**
- * 次卡编辑
- * @Author:hua
- * @Date:2024-02-28 11:04
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|string|void
- */
- public function actionEdit()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $form = Yii::$app->request->post('form');
- $params = json_decode($form, true);
- $params['mall_id'] = $this->mall_id;
- $params['create_source_type'] = 0;
- $params['create_source_id'] = $this->admin['id'] ?? 0;
- if ($params['reservation_type'] == 1 && $params['reservation_model'] == 1) {
- if (empty($params['reservation_time'])) {
- return $this->error('请填写可预约时间');
- }
- }
- try {
- $params['rule'] = (string)$params['rule'];
- if ($params['reservation_model'] == SecondaryCardEnum::RESERVATION_MODEL_PEOPLE) {
- $params['reservation_service_type'] = 1;
- }
- $data = SecondaryCardService::setData($params);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success('操作成功', $data);
- }
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $data = SecondaryCardService::getOne($params['id'], $this->mall_id);
- return $this->success('操作成功', $data);
- }
- }
- return $this->render('edit', [
- ]);
- }
- /**
- * 操作次卡下架
- * @Author:hua
- * @Date:2024-02-28 11:04
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionChangeIsOnSales()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- try {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['id', 'is_on_sales'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $create_source_type = 0;
- $create_source_id = $this->admin['id'] ?? 0;
- SecondaryCardService::changeIsOnSales($params['id'], $this->mall_id, $params['is_on_sales'],$create_source_id,$create_source_type);
- return $this->success('操作成功');
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- return $this->error();
- }
- public function actionUploadIsOnSales()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- try {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['id', 'is_on_sales'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- SecondaryCardService::uploadIsOnSales($params['id'], $this->mall_id, $params['is_on_sales']);
- return $this->success('操作成功');
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- return $this->error();
- }
- /**
- * 店铺列表
- * @Author:hua
- * @Date:2024-02-28 11:04
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionStoreList()
- {
- if (\Yii::$app->request->isAjax) {
- try {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $list = SecondaryCardService::getStorePageList($params);
- return $this->success('操作成功', $list);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- return $this->error();
- }
- /**
- * 开卡记录
- * @Author:hua
- * @Date:2024-02-29 11:41
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|string|void
- */
- public function actionOrder()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $data = SecondaryCardOrderService::getList($params);
- return $this->success('操作成功', $data, ApiStatusEnum::CODE_SUCCESS, 0);
- }
- if (\Yii::$app->request->isPost) {
- $data = \Yii::$app->request->post();
- $filename = '开卡列表' . '-' . date('YmdHis') . '_' . rand(10000, 99999);
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_SECONDARY_CARD, SecondaryCardOrderService::class, 'exportHandle', $data);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- return $this->render('order', []);
- }
- /**
- *
- * @Author:hua
- * @Date:2024-03-01 10:09
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionChangeOrderStatus()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- try {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['id', 'order_status'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- SecondaryCardOrderService::changeOrderStatus($params['id'], $this->mall_id, $params['order_status']);
- return $this->success('操作成功');
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- }
- /**
- * 兑换码管理
- * @Author:hua
- * @Date:2024-02-29 11:41
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|string|void
- */
- public function actionRedemptionCode()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $data = SecondaryCardRedemptionCodeService::getList($params);
- return $this->success('操作成功', $data, ApiStatusEnum::CODE_SUCCESS, 0);
- }
- if (\Yii::$app->request->isPost) {
- $data = \Yii::$app->request->post();
- $filename = '兑换码列表' . '-' . date('YmdHis') . '_' . rand(10000, 99999);
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_SECONDARY_CARD, SecondaryCardRedemptionCodeService::class, 'exportHandle', $data);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- $id = \Yii::$app->request->get('id');
- $secondary_card = SecondaryCard::findOne(['id' => $id]);
- return $this->render('redemption-code', ['secondary_card_name' => $secondary_card['name']]);
- }
- /**
- * 新建兑换码
- * @Author:hua
- * @Date:2024-02-29 15:34
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionRedemptionCodeAdd()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['secondary_card_id', 'num', 'remarks'], 'required'],
- ['num', function ($attribute) {
- if ($this->$attribute < 0) {
- $this->addError($attribute, '数量必须大于0');
- }
- }],
- [['code_pre'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if(!empty($params['code_pre'])&&strlen($params['code_pre'])!=4){
- return $this->error('您当前兑换码无效,确认并输入正确兑换码');
- }
- $params['mall_id'] = $this->mall_id;
- $secondary_card = SecondaryCard::findOne(['id' => $params['secondary_card_id'], 'mall_id' => $this->mall_id]);
- if (empty($secondary_card)) {
- return $this->error('次卡不存在');
- }
- if ($params['num'] > $secondary_card['max_times']) {
- return $this->error('新建数量不能大于最大开卡数');
- }
- $params['use_type'] = $secondary_card['use_type'];
- $params['create_source_type'] = 0;
- $params['create_source_id'] = $this->admin['id'] ?? 0;
- Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, $params, SecondaryCardRedemptionCodeService::class, 'add');
- return $this->success('操作成功');
- }
- }
- }
- /**
- * 兑换码删除
- * @Author:hua
- * @Date:2024-02-29 15:34
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionRedemptionCodeDel()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['secondary_card_id', 'id'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $data = SecondaryCardRedemptionCodeService::del($params);
- return $this->success('操作成功', $data);
- }
- }
- }
- /**
- * 使用记录
- * @Author:hua
- * @Date:2024-03-07 16:40
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|string|void
- */
- public function actionUseLog()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $data = SecondaryCardUseLogService::getList($params);
- return $this->success('操作成功', $data);
- }
- if (\Yii::$app->request->isPost) {
- $data = \Yii::$app->request->post();
- $filename = '使用记录' . '-' . date('YmdHis') . '_' . rand(10000, 99999);
- $data['mall_id'] = $this->mall_id;
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_SECONDARY_CARD, SecondaryCardUseLogService::class, 'exportHandle', $data);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- return $this->render('use-log', []);
- }
- /**
- * 退款
- * @Author:hua
- * @Date:2024-03-08 11:49
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionOrderRefund()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- try {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['id', 'refund_money'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if ($params['refund_money'] <= 0) {
- return $this->error('退款金额必须大于0');
- }
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = 0;
- SecondaryCardOrderService::orderRefund($params);
- return $this->success('操作成功');
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- }
- public function actionCanClerkStoreList()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- try {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $data = SecondaryCardService::canClerkStoreList($params);
- return $this->success('操作成功', $data);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- return $this->render('index', []);
- }
- public function actionShowMiniPromotionCode()
- {
- $request = \Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $params = \Yii::$app->request->post();
- // 检查提交的参数
- $res = \Yii::$app->services->validate->validate($params, [
- [['id'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $params['mall'] = $this->mall;
- $data = SecondaryCardService::showMiniPromotionCode($params);
- return $this->success('操作成功', $data);
- }
- }
- }
- }
|