VerifyController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\models\AccountLog;
  9. use app\models\VerifyCard;
  10. use app\models\VerifyCardAccount;
  11. use app\models\VerifyCardSale;
  12. use app\modules\client\controllers\BaseController;
  13. use app\modules\client\models\v1\VerifyIndexForm;
  14. class VerifyController extends BaseController
  15. {
  16. /**
  17. * 我的核销卡列表
  18. */
  19. public function actionIndex()
  20. {
  21. /**
  22. * 有效卡数量
  23. * 核销卡id
  24. * 核销卡名称
  25. * 剩余次数
  26. * 有效期
  27. */
  28. $form = new VerifyIndexForm();
  29. $form->attributes = get_params();
  30. $form->store_id = get_store_id();
  31. $form->user_id = get_user_id();
  32. return $this->asJson($form->search());
  33. }
  34. /**
  35. * 核销卡详情页
  36. */
  37. public function actionVerifyDetail(){
  38. $form = new VerifyIndexForm();
  39. $form->attributes = get_params();
  40. $form->store_id = get_store_id();
  41. $form->user_id = get_user_id();
  42. return $this->asJson($form->detail());
  43. }
  44. /**
  45. * 修改密码
  46. */
  47. public function actionVerifyChangePass(){
  48. return $this->asJson([
  49. 'code' => 1,
  50. 'msg' => '暂不支持修改',
  51. ]);
  52. $form = new VerifyIndexForm();
  53. $form->attributes = post_params();
  54. $form->store_id = get_store_id();
  55. $form->user_id = get_user_id();
  56. return $this->asJson($form->changePass());
  57. }
  58. /**
  59. * 核销卡使用记录页
  60. */
  61. public function actionVerifyLog(){
  62. $form = new VerifyIndexForm();
  63. $form->attributes = get_params();
  64. $form->store_id = get_store_id();
  65. $form->user_id = get_user_id();
  66. return $this->asJson($form->log());
  67. }
  68. /**
  69. * 核销卡核销详情页
  70. */
  71. public function actionVerifyOrder(){
  72. $form = new VerifyIndexForm();
  73. $form->attributes = get_params();
  74. $form->store_id = get_store_id();
  75. $form->user_id = get_user_id();
  76. return $this->asJson($form->order());
  77. }
  78. /**
  79. * 添加新卡
  80. */
  81. public function actionVerifyAdd() {
  82. $form = new VerifyIndexForm();
  83. $form->attributes = post_params();
  84. $form->store_id = get_store_id();
  85. $form->user_id = get_user_id();
  86. return $this->asJson($form->add());
  87. }
  88. /**
  89. * 兑换详情
  90. */
  91. public function actionVerifyExchangeDetail() {
  92. $form = new VerifyIndexForm();
  93. $form->attributes = get_params();
  94. $form->store_id = get_store_id();
  95. $form->user_id = get_user_id();
  96. return $this->asJson($form->exchangeDetail());
  97. }
  98. /**
  99. * 卡券兑换
  100. */
  101. public function actionVerifyExchange() {
  102. $form = new VerifyIndexForm();
  103. $form->attributes = get_params();
  104. $form->store_id = get_store_id();
  105. $form->user_id = get_user_id();
  106. return $this->asJson($form->exchange());
  107. }
  108. /**
  109. * 卡券领取
  110. */
  111. public function actionReceive() {
  112. $form = new VerifyIndexForm();
  113. $form->attributes = get_params();
  114. $form->store_id = get_store_id();
  115. $form->user_id = get_user_id();
  116. return $this->asJson($form->receive());
  117. }
  118. /**
  119. * 视频状态更新
  120. */
  121. public function actionVideo() {
  122. $form = new VerifyIndexForm();
  123. $form->attributes = get_params();
  124. $form->store_id = get_store_id();
  125. $form->user_id = get_user_id();
  126. return $this->asJson($form->videoUpdate());
  127. }
  128. /**
  129. * 删除个人卡券
  130. */
  131. public function actionDel() {
  132. $form = new VerifyIndexForm();
  133. $form->attributes = get_params();
  134. $form->store_id = get_store_id();
  135. $form->user_id = get_user_id();
  136. return $this->asJson($form->delVerifyCard());
  137. }
  138. /**
  139. * 获取核销记录
  140. */
  141. public function actionVerifyMdLog()
  142. {
  143. $form = new VerifyIndexForm();
  144. $form->attributes = get_params();
  145. $form->store_id = get_store_id();
  146. $form->user_id = get_user_id();
  147. return $this->asJson($form->getVerifyLog());
  148. }
  149. public function actionList()
  150. {
  151. $form = new VerifyIndexForm();
  152. $form->attributes = get_params();
  153. $form->store_id = get_store_id();
  154. $form->user_id = get_user_id();
  155. return $this->asJson($form->v_list());
  156. }
  157. public function actionDetail($id = null){
  158. $verify_card_info = VerifyCard::findOne($id);
  159. $verify_card_info->begin_time = $verify_card_info->begin_time? date("Y-m-d H:i:s",$verify_card_info->begin_time) : '';
  160. $verify_card_info->end_time = $verify_card_info->end_time? date("Y-m-d H:i:s",$verify_card_info->end_time): '';
  161. $verify_card_info->num = $verify_card_info->num - $verify_card_info->send_times;
  162. return $this->asJson([
  163. 'code' => 0,
  164. 'data' => $verify_card_info,
  165. 'msg' => 'success',
  166. ]);
  167. }
  168. public function actionAddReceive(){
  169. $form = new VerifyIndexForm();
  170. $form->store_id = get_store_id();
  171. $form->user_id = get_user_id();
  172. $form->share_user_id = \Yii::$app->request->get('share_user_id');
  173. $form->verify_card_id = \Yii::$app->request->get('id');
  174. return $this->asJson($form->add_receive());
  175. }
  176. /**
  177. * 模块名:actionVerifyForCash
  178. * 代码描述:礼品卡折现
  179. * 作者:WPing丶
  180. * 请求方式:GET
  181. * 创建时间:2024/03/14 11:43:29
  182. * @param int account_id 卡券id
  183. */
  184. public function actionVerifyForCash() {
  185. $account_id = get_params('account_id', 0);
  186. $user_id = get_user_id();
  187. $store_id = get_store_id();
  188. $card = VerifyCardSale::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'account_id' => $account_id, 'is_delete' => 0, 'status' => 0]);
  189. if(!$card) {
  190. return $this->asJson([
  191. 'code' => 1,
  192. 'msg' => '礼品卡不存在或已使用',
  193. ]);
  194. }
  195. $account = VerifyCardAccount::findOne($account_id);
  196. $VerifyCard = VerifyCard::findOne($account->card_id);
  197. if(!$VerifyCard) {
  198. return $this->asJson([
  199. 'code' => 1,
  200. 'msg' => '礼品卡不存在',
  201. ]);
  202. }
  203. /* begin 2025/07/26 17:15:52 修复礼品卡折现为0可以折现的BUG WPing丶 */
  204. if(!$VerifyCard->for_cash) {
  205. return $this->asJson([
  206. 'code' => 1,
  207. 'msg' => '此卡券不能折现',
  208. ]);
  209. }
  210. /* end */
  211. $card->status = VerifyCardSale::STATUS_USED;
  212. $card->left_num = 0;
  213. $card->is_cash = 1;
  214. if(!$card->save()) {
  215. return $this->asJson([
  216. 'code' => 1,
  217. 'msg' => '修改礼品卡状态失败',
  218. ]);
  219. } else {
  220. $res = AccountLog::saveLog($user_id,$VerifyCard->for_cash,AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME,0,0,"礼品卡:".$account->account."折现");
  221. if($res) {
  222. return $this->asJson([
  223. 'code' => 0,
  224. 'msg' => '折现成功',
  225. ]);
  226. }
  227. }
  228. }
  229. }