| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\models\AccountLog;
- use app\models\VerifyCard;
- use app\models\VerifyCardAccount;
- use app\models\VerifyCardSale;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\VerifyIndexForm;
- class VerifyController extends BaseController
- {
- /**
- * 我的核销卡列表
- */
- public function actionIndex()
- {
- /**
- * 有效卡数量
- * 核销卡id
- * 核销卡名称
- * 剩余次数
- * 有效期
- */
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->search());
- }
- /**
- * 核销卡详情页
- */
- public function actionVerifyDetail(){
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->detail());
- }
- /**
- * 修改密码
- */
- public function actionVerifyChangePass(){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '暂不支持修改',
- ]);
- $form = new VerifyIndexForm();
- $form->attributes = post_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->changePass());
- }
- /**
- * 核销卡使用记录页
- */
- public function actionVerifyLog(){
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->log());
- }
- /**
- * 核销卡核销详情页
- */
- public function actionVerifyOrder(){
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->order());
- }
- /**
- * 添加新卡
- */
- public function actionVerifyAdd() {
- $form = new VerifyIndexForm();
- $form->attributes = post_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->add());
- }
- /**
- * 兑换详情
- */
- public function actionVerifyExchangeDetail() {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->exchangeDetail());
- }
- /**
- * 卡券兑换
- */
- public function actionVerifyExchange() {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->exchange());
- }
- /**
- * 卡券领取
- */
- public function actionReceive() {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->receive());
- }
- /**
- * 视频状态更新
- */
- public function actionVideo() {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->videoUpdate());
- }
- /**
- * 删除个人卡券
- */
- public function actionDel() {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->delVerifyCard());
- }
- /**
- * 获取核销记录
- */
- public function actionVerifyMdLog()
- {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->getVerifyLog());
- }
- public function actionList()
- {
- $form = new VerifyIndexForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $this->asJson($form->v_list());
- }
- public function actionDetail($id = null){
- $verify_card_info = VerifyCard::findOne($id);
- $verify_card_info->begin_time = $verify_card_info->begin_time? date("Y-m-d H:i:s",$verify_card_info->begin_time) : '';
- $verify_card_info->end_time = $verify_card_info->end_time? date("Y-m-d H:i:s",$verify_card_info->end_time): '';
- $verify_card_info->num = $verify_card_info->num - $verify_card_info->send_times;
- return $this->asJson([
- 'code' => 0,
- 'data' => $verify_card_info,
- 'msg' => 'success',
- ]);
- }
- public function actionAddReceive(){
- $form = new VerifyIndexForm();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- $form->share_user_id = \Yii::$app->request->get('share_user_id');
- $form->verify_card_id = \Yii::$app->request->get('id');
- return $this->asJson($form->add_receive());
- }
- /**
- * 模块名:actionVerifyForCash
- * 代码描述:礼品卡折现
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2024/03/14 11:43:29
- * @param int account_id 卡券id
- */
- public function actionVerifyForCash() {
- $account_id = get_params('account_id', 0);
- $user_id = get_user_id();
- $store_id = get_store_id();
- $card = VerifyCardSale::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'account_id' => $account_id, 'is_delete' => 0, 'status' => 0]);
- if(!$card) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '礼品卡不存在或已使用',
- ]);
- }
- $account = VerifyCardAccount::findOne($account_id);
- $VerifyCard = VerifyCard::findOne($account->card_id);
- if(!$VerifyCard) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '礼品卡不存在',
- ]);
- }
- /* begin 2025/07/26 17:15:52 修复礼品卡折现为0可以折现的BUG WPing丶 */
- if(!$VerifyCard->for_cash) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '此卡券不能折现',
- ]);
- }
- /* end */
-
- $card->status = VerifyCardSale::STATUS_USED;
- $card->left_num = 0;
- $card->is_cash = 1;
- if(!$card->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '修改礼品卡状态失败',
- ]);
- } else {
- $res = AccountLog::saveLog($user_id,$VerifyCard->for_cash,AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME,0,0,"礼品卡:".$account->account."折现");
- if($res) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '折现成功',
- ]);
- }
- }
- }
- }
|