| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\constants\OptionSetting;
- use app\models\Coupon;
- use app\models\CouponAutoSend;
- use app\models\Event;
- use app\models\EventForm;
- use app\models\EventFormDetail;
- use app\models\EventSetting;
- use app\models\EventSignStaff;
- use app\models\EventUser;
- use app\models\Insurance;
- use app\models\User;
- use app\models\VerifyCard;
- use app\models\VerifyCardAccount;
- use app\modules\admin\models\CardForm;
- use app\modules\admin\models\CouponForm;
- use app\modules\admin\models\TopicTypeForm;
- use app\modules\admin\models\VerifyCardForm;
- use app\modules\admin\models\VerifyCardSaleForm;
- use app\modules\admin\models\RechargeForm;
- use app\modules\admin\models\RechargeSettingForm;
- use app\modules\admin\models\CouponAutoSendForm;
- use app\utils\ShareQrcode;
- use yii\base\BaseObject;
- use app\modules\admin\models\ReOrderForm;
- use Spatie\SimpleExcel\SimpleExcelWriter;
- use Yii;
- use yii\data\Pagination;
- /**
- * Undocumented class
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-08
- * @desc: 营销管理
- */
- class MarketingController extends BaseController
- {
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 优惠券列表
- */
- public function actionCouponList()
- {
- $param = get_params();
- $form = new CouponForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchCoupon());
- }
- /**
- * Undocumented function
- *
- * @desc: 商盟优惠券列表
- */
- public function actionBusinessCouponList()
- {
- $param = get_params();
- $form = new CouponForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- return $this->asJson($form->searchCoupon());
- }
- /**
- * 商盟优惠券状态
- */
- public function actionBusinessCouponStatus()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!in_array($status, [1, 0])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- $coupon = Coupon::findOne($id);
- if (!$coupon) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据不存在'
- ]);
- }
- Coupon::updateAll(['business_status' => $status], ['id' => $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /**
- * 优惠券添加
- * @return \yii\web\Response
- */
- public function actionCouponAdd()
- {
- $param = post_params();
- if (!isset($param['is_business'])) {
- $param['is_business'] = 0;
- }
- if (!isset($param['business_type'])) {
- $param['business_type'] = 0;
- }
- $form = new CouponForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- if (isset($param['begin_time']) && $param['begin_time']) {
- $form->begin_time = strtotime($param['begin_time']);
- }
- if (isset($param['end_time']) && $param['end_time']) {
- $form->end_time = strtotime($param['end_time']);
- }
- return $this->asJson($form->saveCoupon());
- }
- /**
- * 优惠券状态
- * @return \yii\web\Response
- */
- public function actionCouponStatus()
- {
- $id = post_params('id');
- $is_join = post_params('is_join');
- $coupon = Coupon::findOne($id);
- if (!$coupon) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据不存在'
- ]);
- }
- Coupon::updateAll(['is_join' => $is_join], ['id' => $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /**
- * 优惠券批量操作
- * @return \yii\web\Response
- */
- public function actionCouponBatch()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!is_array($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- Coupon::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /**
- * 优惠券自动发放批量操作
- * @return \yii\web\Response
- */
- public function actionCouponAutoSendBatch()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!is_array($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- CouponAutoSend::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /**
- * Undocumented function
- *
- * @Author gwc 756401197@qq.com
- * @DateTime 2021-12-13
- * @desc: 优惠券发放记录
- */
- public function actionCouponSendRecord()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new CouponForm();
- $form->store_id = get_store_id();
- $form->id = $param;
- $res = $form->CouponSendRecord();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author gwc 756401197@qq.com
- * @DateTime 2021-12-13
- * @desc: 小程序二维码
- * @return void
- */
- public function actionGetCouponQrcode()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- try {
- $res = ShareQrcode::wxQrcode('pages/home/home', $param);
- if ($res['code'] == 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $res['response']['errmsg'],
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res['url_path'],
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage(),
- ]);
- }
- // $form = new CouponForm();
- // $form->store_id = get_store_id();
- // $form->id = $param;
- // $res = $form->CouponSendRecord();
- // return $this->asJson($res);
- }
- /**
- * 卡券批量操作
- * @return \yii\web\Response
- */
- /**
- * 优惠券编辑
- * @return \yii\web\Response
- */
- public function actionVerifyCardBatch()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!is_array($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- VerifyCard::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- public function actionCouponEdit()
- {
- $param = post_params();
- $form = new CouponForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- if (isset($param['begin_time']) && $param['begin_time']) {
- $form->begin_time = strtotime($param['begin_time'] . ' 00:00:00');
- }
- if (isset($param['end_time']) && $param['end_time']) {
- $form->end_time = strtotime($param['end_time'] . ' 23:59:59');
- }
- return $this->asJson($form->saveCoupon());
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 优惠券删除
- * @return void
- */
- public function actionCouponDel()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new CouponForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->id = $param;
- $res = $form->delCoupon();
- return $this->asJson($res);
- }
- /**
- * 商盟卡券状态
- */
- public function actionBusinessVerifyStatus()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!in_array($status, [1, 0])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- $verify = VerifyCard::findOne($id);
- if (!$verify || !$verify['is_business']) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据不存在'
- ]);
- }
- if ($status == $verify['business_status']) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '状态相同,无需修改'
- ]);
- }
- VerifyCard::updateAll(['business_status' => $status], ['id' => $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /**
- * Undocumented function
- *
- * @desc: 商盟卡券列表
- */
- public function actionBusinessVerifyList()
- {
- $param = get_params();
- $form = new VerifyCardForm();
- $form->scenario = $form::SCENARIO_LIST;
- $param['is_business'] = 1;
- $form->attributes = $param;
- return $this->asJson($form->searchVerifyCard());
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 获取核销卡
- * @return void
- */
- public function actionVerifyList()
- {
- $param = get_params();
- $form = new VerifyCardForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchVerifyCard());
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 添加核销卡
- * @return void
- */
- public function actionVerifyAdd()
- {
- $param = post_params();
- $form = new VerifyCardForm();
- $form->scenario = $form::SCENARIO_ADD;
- if (!isset($param['is_business'])) {
- $param['is_business'] = 0;
- }
- if (!isset($param['business_type'])) {
- $param['business_type'] = 0;
- }
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $form->share_user_id = post_params('share_user_id', []);
- if ($param['date']) {
- $form->begin_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][0])));
- $form->end_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][1])));
- } else {
- $form->begin_time = 0;
- $form->end_time = 0;
- }
- if (is_array($param['goods_ids']) && !empty($param['goods_ids'])) {
- $form->goods_ids = json_encode($param['goods_ids']);
- } else {
- $form->goods_ids = '';
- }
- if (is_array($param['video_ids']) && !empty($param['video_ids'])) {
- $form->video_ids = json_encode($param['video_ids']);
- } else {
- $form->video_ids = '';
- }
- if (!isset($param['is_business'])) {
- $param['is_business'] = 0;
- }
- if (!isset($param['business_type'])) {
- $param['business_type'] = 0;
- }
- $form->status = 0;
- $form->send_times = $form::SEDN_TIMES_DEFAULT;
- $res = $form->saveVerifyCard();
- return $this->asJson($res);
- }
- public function actionVcAccountSave()
- {
- $param = post_params();
- $form = new VerifyCardForm();
- $form->store_id = get_store_id();
- $res = $form->vcAccountSave($param['list']);
- return $this->asJson($res);
- }
- public function actionVerifyUp()
- {
- $param = post_params();
- $form = new VerifyCardForm();
- $res = $form->changePass($param['id'], $param['password']);
- return $this->asJson($res);
- }
- public function actionVerifyUpload()
- {
- if (\Yii::$app->request->isPost) {
- $form = new VerifyCardForm();
- $form->id = post_params('id');
- $form->store_id = get_store_id();
- $res = $form->upload();
- return $this->asJson($res);
- }
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2022-01-05
- * @desc: 生成卡密信息
- * @return void
- */
- public function actionMakeCardInfo()
- {
- $param = post_params();
- $form = new VerifyCardForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->id = $param['key'];
- $form->store_id = get_store_id();
- $res = $form->generateAccount();
- return $this->asJson($res);
- }
- /**
- * 导出卡券卡密信息.csv
- */
- public function actionExport()
- {
- $id = get_params('key');
- if (!$id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少参数',
- ]);
- }
- $list = VerifyCardAccount::find()
- ->select('account, password, status')
- ->where([
- 'card_id' => $id,
- ])->orderBy('status ASC')->asArray()->all();
- $titles = ['账号', '密码', '状态'];
- $filename = date('YmdHis') . '.csv';
- header('Content-Type: text/csv');
- header("Content-Disposition: attachment;filename={$filename}");
- // $fp = fopen('php://output', 'w');
- $fp = fopen('php://temp/maxmemory:' . (12 * 1024 * 1024), 'r+');
- fwrite($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));
- fputcsv($fp, $titles);
- foreach ($list as $item) {
- $arr = [$item['account'], $item['password'], $item['status'] == 0 ? '未使用' : '已使用'];
- fputcsv($fp, $arr);
- }
- rewind($fp);
- $output = stream_get_contents($fp);
- fclose($fp);
- return $output;
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 编辑核销卡
- * @return void
- */
- public function actionVerifyEdit()
- {
- $param = post_params();
- $form = new VerifyCardForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $form->share_user_id = post_params('share_user_id', []);
- if (isset($param['date']) && $param['date']) {
- $form->begin_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][0])));
- $form->end_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][1])));
- }
- if (is_array($param['goods_ids']) && !empty($param['goods_ids'])) {
- $form->goods_ids = json_encode($param['goods_ids']);
- } else {
- $form->goods_ids = '';
- }
- if (is_array($param['video_ids']) && !empty($param['video_ids'])) {
- $form->video_ids = json_encode($param['video_ids']);
- } else {
- $form->video_ids = '';
- }
- $res = $form->saveVerifyCard();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 删除核销卡
- * @return void
- */
- public function actionVerifyDel()
- {
- //主键id用key标识并进行获取
- $param = get_params();
- $form = new VerifyCardForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->attributes = $param;
- $res = $form->delVerifyCard();
- return $this->asJson($res);
- }
- public function actionVerifyTmp()
- {
- $param = all_params();
- $form = new VerifyCardForm();
- $form->attributes = $param;
- $res = $form->verifyTmp();
- return $this->asJson($res);
- }
- public function actionGetAccountInfo()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new VerifyCardForm();
- $form->id = $param;
- $form->store_id = get_store_id();
- $res = $form->getAccountInfo();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @desc: 卡券信息详情
- * @return array
- */
- public function actionVerifyDetail()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new VerifyCardForm();
- $form->attributes = all_params();
- $form->id = $param;
- $form->store_id = get_store_id();
- $res = $form->verifyDetail();
- return $this->asJson($res);
- }
- public function actionVerifyShare()
- {
- $form = new VerifyCardForm();
- return $this->asJson($form->searchVerifyShareList(get_params('id')));
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-06
- * @desc: 获取核销卡订单
- * @return void
- */
- public function actionVerifySaleList()
- {
- $param = get_params();
- $form = new VerifyCardSaleForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchVerifyCardSale());
- }
-
- //订单赠送卡券记录
- public function actionVerifyCardOrderGetList()
- {
- $param = all_params();
- $form = new VerifyCardForm();
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchVerifyCardOrderGetList());
- }
-
- //核销记录
- public function actionVerifyCardLogList()
- {
- $param = all_params();
- $form = new VerifyCardForm();
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchVerifyCardLogList());
- }
- /* begin 2024/11/16 14:47:38 id1126开发需求:新增储值卡消费记录 WPing丶 */
- public function actionCardPayLogList()
- {
- $param = all_params();
- $form = new VerifyCardForm();
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchCardPayLogList());
- }
- /* end */
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-09
- * @desc: 卡券列表
- * @return void
- */
- public function actionCardCouponList()
- {
- $param = get_params();
- $form = new CardForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchCard());
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-09
- * @desc: 添加卡券
- * @return void
- */
- public function actionCardCouponAdd()
- {
- $param = post_params();
- $form = new CardForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveCard();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-09
- * @desc: 编辑卡券
- * @return void
- */
- public function actionCardCouponEdit()
- {
- $param = post_params();
- $form = new CardForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveCard();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-09
- * @desc: 删除卡券
- * @return void
- */
- public function actionCardCouponDel()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new CardForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->id = $param;
- $res = $form->delCard();
- return $this->asJson($res);
- }
- public function actionRechargeOrder()
- {
- $param = get_params();
- $form = new ReOrderForm();
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- //充值订单申请退款
- // public function actionRechargeOrderRefundMoneyApply()
- // {
- // $form = new ReOrderForm();
- // $form->store_id = get_store_id();
- // $user_id = input_params('user_id', 0);
- // $order_id = input_params('order_id', 0);
- // $desc_user = input_params('desc_user', '');
- // return $this->asJson($form->refundMoneyApply($user_id, $order_id, $desc_user));
- // }
- //充值订单退款列表
- public function actionRechargeOrderRefundMoneyList()
- {
- $param = get_params();
- $form = new ReOrderForm();
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->refundMoneyList());
- }
- //充值订单退款审核
- public function actionRechargeOrderRefundMoneyAudit()
- {
- $form = new ReOrderForm();
- $form->store_id = get_store_id();
- $audit_status = input_params('audit_status', 0);
- $refund_id = input_params('refund_id', 0);
- $desc_admin = input_params('desc_admin', '');
- $refund_price = input_params('refund_price', 0.01);
- $sub_balance = input_params('sub_balance', 0);
- $sub_integral = input_params('sub_integral', 0);
- return $this->asJson($form->refundMoneyAudit($audit_status, $refund_id, $desc_admin, $refund_price, $sub_balance, $sub_integral));
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 充值方案列表
- * @return void
- */
- public function actionRechargeList()
- {
- $param = get_params();
- $form = new RechargeForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchRecharge());
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 充值方案添加
- * @return void
- */
- public function actionRechargeAdd()
- {
- $param = post_params();
- $form = new RechargeForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->assign_member = post_params('assign_member');
- $form->referral_commission = json_encode((post_params('referral_commission')));
- $form->store_id = get_store_id();
- $res = $form->saveRecharge();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 充值方案编辑
- * @return void
- */
- public function actionRechargeEdit()
- {
- $param = post_params();
- $form = new RechargeForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- if (is_array(post_params('assign_member'))) {
- $form->assign_member = json_encode(post_params('assign_member'));
- } else {
- $form->assign_member = post_params('assign_member');
- }
- $form->referral_commission = json_encode(post_params('referral_commission'));
- $form->store_id = get_store_id();
- $res = $form->saveRecharge();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 充值方案删除
- * @return void
- */
- public function actionRechargeDel()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new RechargeForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->id = $param;
- $res = $form->delRecharge();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 充值设置
- * @return void
- */
- public function actionRechargeSetting()
- {
- $param = post_params();
- $form = new RechargeSettingForm();
- // $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveRechargeSetting();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 优惠券自动发放列表
- */
- public function actionCouponAutoSendList()
- {
- $param = get_params();
- $form = new CouponAutoSendForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchCouponAutoSend());
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 优惠券自动发放添加
- * @return void
- */
- public function actionCouponAutoSendAdd()
- {
- $param = post_params();
- if (empty($param['coupon_id'])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请选择优惠券'
- ]);
- }
- $form = new CouponAutoSendForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveCouponAutoSend();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 优惠券自动发放编辑
- * @return void
- */
- public function actionCouponAutoSendEdit()
- {
- $param = post_params();
- $form = new CouponAutoSendForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveCouponAutoSend();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-12
- * @desc: 优惠券自动发放删除
- * @return void
- */
- public function actionCouponAutoSendDel()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new CouponAutoSendForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->id = $param;
- $res = $form->delCouponAutoSend();
- return $this->asJson($res);
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-13
- * @desc: 发放优惠券
- */
- public function actionCouponSendUser()
- {
- $param = post_params();
- $res = CouponForm::userAddCoupon($param['user_id'], $param['coupon_id']);
- return $this->asJson($res);
- }
- /**
- * 优惠券自动发放规则状态
- * @return \yii\web\Response
- */
- public function actionRuleStatus()
- {
- $id = post_params('id');
- $status = intval(post_params('status'));
- $coupon = CouponAutoSend::findOne($id);
- if (!$coupon) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据不存在'
- ]);
- }
- CouponAutoSend::updateAll(['status' => $status], ['id' => $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /* begin 2023/12/08 17:34:12 id958保单信息 WPing丶 */
- /**
- * 模块名:actionInsuranceEdit
- * 代码描述:添加和编辑保单
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/08 17:34:59
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionInsuranceEdit() {
- $post_params = post_params();
- $store_id = get_store_id();
-
-
- $insurance = Insurance::findOne(['id' => post_params('id'), 'is_delete' => 0]);
- if(!$insurance) {
- $insurance = new Insurance();
- }
- $query = Insurance::find()->where(['phone' => $post_params['phone'], 'store_id' => $store_id]);
- if(post_params('id') > 0) {
- $query->andWhere(['<>', 'id', post_params('id')]);
- }
- $exist = $query->exists();
- if($exist) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '手机号不能重复'
- ]);
- }
- $insurance->store_id = $store_id;
- $insurance->name = $post_params['name'];
- $insurance->phone = $post_params['phone'];
- $insurance->address = $post_params['address'];
- $insurance->date = $post_params['date'];
- $insurance->serve = $post_params['serve'];
- $insurance->price = $post_params['price'];
- $insurance->serve_man = $post_params['serve_man'];
- $insurance->live_room_url = $post_params['live_room_url'];
- if($_FILES['insurance_file']) {
- //保单信息
- $insurance_filename = $_FILES['insurance_file']['name'];
- $insurance_tmpname = $_FILES['insurance_file']['tmp_name'];
- $path = \Yii::$app->basePath . '/web/uploads/pdf/store_'.$store_id.'/';
- // 如果目录不存在,则创建目录
- if (!is_dir($path) && !mkdir($path, 0777, true)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '无法创建目录:' . $path
- ]);
- }
- $ext = strtolower(pathinfo($insurance_filename, PATHINFO_EXTENSION));
- if (($ext != 'pdf')) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请上传pdf文件'
- ]);
- }
- $file = time() . $store_id . '_insurance.' . $ext;
- $insurance_uploadfile = $path . $file;
- $insurance_result = move_uploaded_file($insurance_tmpname, $insurance_uploadfile);
- if(!$insurance_result) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '上传保单信息失败'
- ]);
- }
- $insurance_url = \Yii::$app->request->hostInfo . '/web/uploads/pdf/store_'.$store_id.'/' . $file;
- $insurance->insurance = $insurance_url;
- }
- if($_FILES['report_file']) {
- //报告
- $report_filename = $_FILES['report_file']['name'];
- $report_tmpname = $_FILES['report_file']['tmp_name'];
- $path = \Yii::$app->basePath . '/web/uploads/pdf/store_'.$store_id.'/';
- // 如果目录不存在,则创建目录
- if (!is_dir($path) && !mkdir($path, 0777, true)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '无法创建目录:' . $path
- ]);
- }
- $ext = strtolower(pathinfo($report_filename, PATHINFO_EXTENSION));
- if (($ext != 'pdf')) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请上传pdf文件'
- ]);
- }
- $file = time() . $store_id . '_report.' . $ext;
- $report_uploadfile = $path . $file;
- $report_result = move_uploaded_file($report_tmpname, $report_uploadfile);
- if(!$report_result) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '上传报告失败'
- ]);
- }
- $report_url = \Yii::$app->request->hostInfo . '/web/uploads/pdf/store_'.$store_id.'/' . $file;
- $insurance->report = $report_url;
- }
- $insurance->search_num = $post_params['search_num'];
- if(!$insurance->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败',
- 'test' => json_encode($insurance->errors)
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操纵成功'
- ]);
- }
- /**
- * 模块名:actionInsuranceList
- * 代码描述:保单列表
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/11 13:55:29
- */
- public function actionInsuranceList() {
- $get_params = get_params();
- $query = Insurance::find()->where(['is_delete' => 0, 'store_id' => get_store_id()]);
- if($get_params['search_key']) {
- $query->andWhere(['like','name',$get_params['search_key']]);
- }
- $list = $query->orderBy('created_at DESC, id DESC')->asArray()->all();
- $count = count($list);
- $data = array_slice($list, (get_params('pageNo') - 1) * ($get_params['pageSize']?:10), $get_params['pageSize']?:10);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $data,
- 'pageNo' => intval(get_params('pageNo')),
- 'totalCount' => $count,
- ]
- ]);
- }
- /**
- * 模块名:actionInsuranceDel
- * 代码描述:保单删除
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/11 15:27:40
- */
- public function actionInsuranceDel()
- {
- //主键id用key标识并进行获取
- $id = get_params('key');
- $ins = Insurance::findOne(['id' => $id, 'is_delete' => 0]);
- if (!$ins) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '保单不存在或已删除',
- ]);
- }
- $ins->is_delete = 1;
- if (!$ins->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败',
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功',
- ]);
- }
- /**
- * 模块名:actionInsuranceBatch
- * 代码描述:保单批量删除
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/11 15:45:17\
- */
- public function actionInsuranceBatch()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!is_array($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- Insurance::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- /* end */
- /* begin 2025/07/09 16:56:26 id1248 WPing丶 */
- /**
- * 模块名:event-list
- * 代码描述:活动列表
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2025/07/09 16:57:07
- * @param string name 活动名称
- */
- public function actionEventList() {
- $get_params = get_params();
- $status = $get_params['status'];
- $query = Event::find()->where(['is_delete' => 0, 'store_id' => get_store_id()]);
- $now = time();
- if($get_params['search_key']) {
- $query->andWhere(['like','name',$get_params['search_key']]);
- }
- if ($status === 'underway') {
- $query->andWhere(['<=', 'start_time', $now])
- ->andWhere(['>=', 'end_time', $now]);
- } elseif ($status === 'done') {
- $query->andWhere(['<', 'end_time', $now]);
- } elseif ($status === 'not_started') {
- $query->andWhere(['>', 'start_time', $now]);
- }
- // if (isset($get_params['start_time']) && $get_params['start_time']) {
- // $form->start_time = strtotime($get_params['start_time']);
- // }
- // if (isset($get_params['end_time']) && $get_params['end_time']) {
- // $form->end_time = strtotime($get_params['end_time']);
- // }
- $list = $query->orderBy('start_time DESC, id DESC')->asArray()->all();
- foreach($list as &$item) {
- $item['date_array'] = [date('Y-m-d H:i:s', $item['start_time']), date('Y-m-d H:i:s', $item['end_time'])];
- if($item['start_time'] > $now) {
- $item['status_tab'] = '未开始';
- } elseif($item['start_time'] <= $now && $item['end_time'] > $now) {
- $item['status_tab'] = '进行中';
- } elseif($item['end_time'] <= $now) {
- $item['status_tab'] = '已结束';
- } else {
- $item['status_tab'] = '未知';
- }
- }
- $count = count($list);
- $data = array_slice($list, (get_params('pageNo') - 1) * ($get_params['pageSize']?:10), $get_params['pageSize']?:10);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $data,
- 'pageNo' => intval(get_params('pageNo')),
- 'totalCount' => $count,
- ]
- ]);
- }
- /**
- * 模块名:event-edit
- * 代码描述:新增/编辑活动
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2025/07/12 16:28:22
- * @param int id 编辑记录ID
- * @param string name 活动名称
- * @param string address 活动地址
- * @param string date_array 活动时间
- * @param string attendance 活动人数限制(每个公司/机构最多参会人数)
- * @param string company_form_apply 公司申请表单(自定义)
- * @param string institution_form_apply 机构申请表单(自定义)
- * @param string cover_pic 封面图
- */
- public function actionEventEdit()
- {
- $post_params = post_params();
- $store_id = get_store_id();
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $event = Event::findOne(['id' => $post_params['id'], 'is_delete' => 0, 'store_id' => $store_id]);
- if (!$event) {
- $event = new Event();
- $event->store_id = $store_id;
- }
- $event->name = $post_params['name'];
- $event->address = $post_params['address'];
- if (!empty($post_params['date_array'])) {
- list($start, $end) = explode(',', $post_params['date_array']);
- $event->start_time = strtotime($start);
- $event->end_time = strtotime($end);
- }
- $event->attendance = $post_params['attendance'];
- $event->cover_pic = $post_params['cover_pic'];
- if (!$event->save()) {
- throw new \Exception('保存活动失败: ' . json_encode($event->errors, JSON_UNESCAPED_UNICODE));
- }
- // ===================== 公司表单处理 =====================
- $company_form_apply = json_decode($post_params['company_form_apply'], true)['list'] ?? [];
- // if (!empty($company_form_apply)) {
- $company_form_json = json_encode($company_form_apply, JSON_UNESCAPED_UNICODE);
- if($company_form_json != $event->company_form) {
- Event::updateAll(['company_form' => $company_form_json], ['id' => $event->id]);
-
- EventForm::updateAll(['is_delete' => 1], [
- 'store_id' => $store_id,
- 'event_id' => $event->id,
- 'form_type' => EventForm::FORM_TYPE_COMPANY,
- ]);
-
- foreach ($company_form_apply as $key => $item) {
- $event_form = new EventForm();
- $event_form->store_id = $store_id;
- $event_form->event_id = $event->id;
- $event_form->form_type = EventForm::FORM_TYPE_COMPANY;
- $event_form->name = $item['name'];
- $event_form->type = $item['type'];
- $event_form->required = $item['required'] ? EventForm::IS_REQUIRED_TRUE : EventForm::IS_REQUIRED_FALSE;
- $event_form->default = $item['default'] ?? '';
- $event_form->tip = $item['tip'] ?? '';
- $event_form->sort = $key;
- if (!$event_form->save()) {
- throw new \Exception('保存公司自定义表单失败: ' . json_encode($event_form->errors, JSON_UNESCAPED_UNICODE));
- }
- }
- }
- // }
- // ===================== 机构表单处理 =====================
- $institution_form_apply = json_decode($post_params['institution_form_apply'], true)['list'] ?? [];
- // if (!empty($institution_form_apply)) {
- $institution_form_json = json_encode($institution_form_apply, JSON_UNESCAPED_UNICODE);
- if($institution_form_json != $event->institution_form) {
- Event::updateAll(['institution_form' => $institution_form_json], ['id' => $event->id]);
-
- EventForm::updateAll(['is_delete' => 1], [
- 'store_id' => $store_id,
- 'event_id' => $event->id,
- 'form_type' => EventForm::FORM_TYPE_INSTITUTION,
- ]);
-
- foreach ($institution_form_apply as $key => $item) {
- $event_form = new EventForm();
- $event_form->store_id = $store_id;
- $event_form->event_id = $event->id;
- $event_form->form_type = EventForm::FORM_TYPE_INSTITUTION;
- $event_form->name = $item['name'];
- $event_form->type = $item['type'];
- $event_form->required = $item['required'] ? EventForm::IS_REQUIRED_TRUE : EventForm::IS_REQUIRED_FALSE;
- $event_form->default = $item['default'] ?? '';
- $event_form->tip = $item['tip'] ?? '';
- $event_form->sort = $key;
- if (!$event_form->save()) {
- throw new \Exception('保存机构自定义表单失败: ' . json_encode($event_form->errors, JSON_UNESCAPED_UNICODE));
- }
- }
- }
- // }
- // ===================== 提交事务 =====================
- $transaction->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功',
- ]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败',
- 'error' => $e->getMessage()
- ]);
- }
- }
- /**
- * 模块名:event-del
- * 代码描述:删除活动
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2025/07/13 17:12:29
- * @param array key 活动ID数组,兼容批量删除
- */
- public function actionEventDel()
- {
- $ids = get_params('key');
- $store_id = get_store_id();
- if (empty($ids) || !is_array($ids)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少删除的活动ID',
- ]);
- }
- $transaction = Yii::$app->db->beginTransaction();
- try {
- foreach ($ids as $id) {
- $event = Event::find()
- ->where(['id' => $id, 'store_id' => $store_id, 'is_delete' => 0])
- ->one();
- if (!$event) {
- throw new \Exception("活动 ID【{$id}】不存在或已删除");
- }
- // 删除关联数据(软删除)
- EventUser::updateAll(['is_delete' => 1], ['event_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
- EventForm::updateAll(['is_delete' => 1], ['event_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
- EventFormDetail::updateAll(['is_delete' => 1], ['event_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
- // 删除主表记录
- $event->is_delete = 1;
- if (!$event->save()) {
- throw new \Exception("活动 ID【{$id}】删除失败");
- }
- }
- $transaction->commit();
- debug_log('批量删除活动,event_id集合=【' . implode(',', $ids) . '】,并删除所有关联数据', 'event.log');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功',
- ]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败:' . $e->getMessage(),
- ]);
- }
- }
- /**
- * 模块名: event-user-audit-list
- * 代码描述: 活动报名审核列表
- * 作者: WPing丶
- * 请求方式: GET
- * 创建时间:2025/07/14 09:06:39
- * @param string company_name 公司名称
- * @param string phone 手机号
- * @param string real_name 真实姓名
- * @param int event_id 活动ID
- * @param string status 状态:all、wait(待审核)、pass(已通过)、refuse(已拒绝)
- * @param int page
- * @param int limit
- */
- public function actionEventUserAuditList()
- {
- $store_id = get_store_id();
- $company_name = get_params('company_name');
- $phone = get_params('phone');
- $real_name = get_params('real_name');
- $event_id = (int)get_params('event_id');
- $status = get_params('status', 'all');
- $page = (int)get_params('page', 1);
- $limit = (int)get_params('limit', 10);
- $query = EventUser::find()->alias('eu')
- ->leftJoin(['e' => Event::tableName()], 'e.id = eu.event_id')
- ->where(['eu.is_delete' => 0, 'e.is_delete' => 0, 'e.store_id' => $store_id]);
- if ($company_name) {
- $query->andWhere(['like', 'eu.company_name', $company_name]);
- }
- if ($phone) {
- $query->andWhere(['like', 'eu.phone', $phone]);
- }
- if ($real_name) {
- $query->andWhere(['like', 'eu.real_name', $real_name]);
- }
- if ($event_id) {
- $query->andWhere(['eu.event_id' => $event_id]);
- }
- if ($status === 'wait') {
- $query->andWhere(['eu.apply_status' => 0]);
- } elseif ($status === 'pass') {
- $query->andWhere(['eu.apply_status' => 1]);
- } elseif ($status === 'refuse') {
- $query->andWhere(['eu.apply_status' => 2]);
- }
- $count = $query->count();
- $pagination = new Pagination([
- 'totalCount' => $count,
- 'pageSize' => $limit,
- 'page' => $page - 1
- ]);
- $list = $query
- ->select([
- 'eu.id',
- 'eu.event_id',
- 'eu.company_code',
- 'eu.company_name',
- 'eu.company_address',
- 'eu.real_name',
- 'eu.phone',
- 'eu.identity_card',
- 'eu.hotel',
- 'eu.restaurant',
- 'eu.itinerary',
- 'eu.created_at',
- 'eu.apply_status',
- 'eu.user_id',
- 'eu.form_type',
- 'e.name as event_name',
- ])
- ->orderBy('eu.created_at DESC')
- ->offset($pagination->offset)
- ->limit($pagination->limit)
- ->asArray()
- ->all();
- foreach ($list as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['avatar_url'] = User::findOne($item['user_id'])->avatar_url;
- $item['nickname'] = User::findOne($item['user_id'])->nickname;
- $item['form_type'] = (int)$item['form_type'];
- // 酒店、用餐、行程转数组
- $item['hotel'] = $item['hotel'] ? json_decode($item['hotel'], true) : [];
- $item['restaurant'] = $item['restaurant'] ? json_decode($item['restaurant'], true) : [];
- $item['itinerary'] = $item['itinerary'] ? json_decode($item['itinerary'], true) : [];
- // 报名详情自定义表单
- $formDetails = EventFormDetail::find()
- ->where([
- 'event_user_id' => $item['id'],
- 'is_delete' => 0
- ])
- ->asArray()
- ->all();
- $form_data = [];
- foreach ($formDetails as $fd) {
- $form_data[] = [
- 'name' => $fd['key'],
- 'value' => $fd['value'],
- 'type' => $fd['type'],
- ];
- }
- $item['form_detail'] = $form_data;
- }
- // 活动下拉列表(不分页)
- $eventList = Event::find()
- ->where(['is_delete' => 0, 'store_id' => $store_id])
- ->select(['id', 'name'])
- ->orderBy('id DESC')
- ->asArray()
- ->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list,
- 'event_list' => $eventList
- ]
- ]);
- }
- /**
- * 模块名: event-user-review
- * 代码描述: 活动报名审核操作
- * 作者: WPing丶
- * 请求方式: POST
- * 创建时间: 2025/07/15 18:06:07
- *
- * @param int id 报名记录ID
- * @param int apply_status 审核状态(1=通过;2=拒绝)
- * @param string reason_refusal 拒绝原因(可选,仅拒绝时必填)
- */
- public function actionEventUserReview()
- {
- $id = (int)post_params('id');
- $apply_status = (int)post_params('apply_status');
- $reason_refusal = trim(post_params('reason_refusal', ''));
- if (!$id || !in_array($apply_status, [1, 2])) {
- return $this->asJson(['code' => 1, 'msg' => '参数错误']);
- }
- if ($apply_status === 2 && !$reason_refusal) {
- return $this->asJson(['code' => 1, 'msg' => '拒绝原因不能为空']);
- }
- $eventUser = EventUser::findOne(['id' => $id, 'is_delete' => 0]);
- if (!$eventUser) {
- return $this->asJson(['code' => 1, 'msg' => '报名记录不存在']);
- }
- // 如果已经审核过,则不再允许重复审核
- if (in_array($eventUser->apply_status, [1, 2])) {
- return $this->asJson(['code' => 1, 'msg' => '该记录已审核,请勿重复操作']);
- }
- $eventUser->apply_status = $apply_status;
- $eventUser->apply_time = time();
- $eventUser->reason_refusal = ($apply_status === 2) ? $reason_refusal : null;
- if (!$eventUser->save()) {
- return $this->asJson(['code' => 1, 'msg' => '审核失败,请重试']);
- }
- return $this->asJson(['code' => 0, 'msg' => '审核成功']);
- }
- /**
- * 模块名: event-user-save
- * 代码描述: 新增或编辑报名记录
- * 作者: WPing丶
- * 请求方式: POST
- * 创建时间: 2025/07/15 20:05:51
- *
- * @param int id 可选,编辑时填写event_user表的主键ID
- * @param int event_id 活动ID
- * @param int user_id 用户ID
- * @param int form_type 表单类型(1=企业,2=机构)
- * @param string company_name 企业名称
- * @param string company_code 统一社会信息代码
- * @param string company_address 企业地址
- * @param string real_name 真实姓名
- * @param string phone 电话
- * @param string identity_card 身份证号
- * @param array form_data 自定义表单,格式:["字段名" => "值"]
- * @param array hotel 酒店信息
- * @param array restaurant 餐厅信息
- * @param array itinerary 行程信息
- */
- public function actionEventUserSave()
- {
- $store_id = get_store_id();
- $id = (int)post_params('id');
- $user_id = (int)post_params('user_id', 0);
- $event_id = (int)post_params('event_id');
- $form_type = (int)post_params('form_type', 1);
- $company_name = post_params('company_name');
- $company_code = post_params('company_code');
- $company_address = post_params('company_address');
- $real_name = post_params('real_name');
- $phone = post_params('phone');
- $identity_card = post_params('identity_card');
- $form_data = post_params('form_data', []);
- $hotel = post_params('hotel', []);
- $restaurant = post_params('restaurant', []);
- $itinerary = post_params('itinerary', []);
- if (!$event_id || !$company_name || !$real_name || !$phone || !$identity_card || !$company_address || !$form_type || !$company_code) {
- return $this->asJson(['code' => 1, 'msg' => '参数不完整']);
- }
- $event = Event::findOne(['id' => $event_id, 'store_id' => $store_id, 'is_delete' => 0]);
- if (!$event) {
- return $this->asJson(['code' => 1, 'msg' => '活动不存在']);
- }
- if ($event->end_time < time()) {
- return $this->asJson(['code' => 1, 'msg' => '活动报名已结束无法报名']);
- }
- // 查询表单结构
- $formList = EventForm::find()
- ->where([
- 'event_id' => $event_id,
- 'form_type' => $form_type,
- 'is_delete' => 0
- ])->asArray()->all();
- $formMap = [];
- foreach ($formList as $formItem) {
- $formMap[$formItem['name']] = $formItem['type'] ?? 'text';
- }
- $transaction = Yii::$app->db->beginTransaction();
- try {
- if ($id) {
- /* 编辑记录时,不允许修改活动ID 和 UserID */
- $eventUser = EventUser::findOne(['id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
- if (!$eventUser) {
- return $this->asJson(['code' => 1, 'msg' => '报名记录不存在']);
- }
- } else {
- if($user_id > 0) {//2025年7月25日10:47:48 如果用户ID存在的情况下判断是否报过名
- $exist = EventUser::find()->where(['event_id' => $event_id, 'user_id' => $user_id, 'store_id' => $store_id, 'is_delete' => 0])->exists();
- if ($exist) {
- return $this->asJson(['code' => 1, 'msg' => '此用户已报名过当前活动,请勿重复报名']);
- }
- } else {
- $exist = EventUser::find()->where(['event_id' => $event_id, 'phone' => $phone, 'store_id' => $store_id, 'is_delete' => 0])->exists();
- if ($exist) {
- return $this->asJson(['code' => 1, 'msg' => '此手机号已报名过当前活动,请勿重复报名']);
- }
- }
- $eventUser = new EventUser();
- $eventUser->store_id = $store_id;
- $eventUser->user_id = $user_id;
- $eventUser->event_id = $event_id;
- }
- $eventUser->company_name = $company_name;
- $eventUser->company_code = $company_code;
- $eventUser->company_address = $company_address;
- $eventUser->real_name = $real_name;
- $eventUser->phone = $phone;
- $eventUser->identity_card = $identity_card;
- $eventUser->apply_status = 1;
- $eventUser->hotel = $hotel ? json_encode($hotel, JSON_UNESCAPED_UNICODE) : '{"title":"","data":[]}';
- $eventUser->restaurant = $restaurant ? json_encode($restaurant, JSON_UNESCAPED_UNICODE) : '{"title":"","data":[]}';
- $eventUser->itinerary = $itinerary ? json_encode($itinerary, JSON_UNESCAPED_UNICODE) : '{"title":"","data":[]}';
- $eventUser->form_type = $form_type;
- if (!$eventUser->save()) {
- throw new \Exception('保存报名信息失败');
- }
- // 先清除旧的表单数据
- EventFormDetail::updateAll(['is_delete' => 1], [
- 'event_user_id' => $eventUser->id,
- 'is_delete' => 0,
- ]);
- // 插入新的表单数据
- foreach ($form_data as $key => $value) {
- if (!isset($formMap[$key])) continue;
- $detail = new EventFormDetail();
- $detail->store_id = $store_id;
- $detail->user_id = $user_id;
- $detail->event_id = $event_id;
- $detail->event_user_id = $eventUser->id;
- $detail->form_type = $form_type;
- $detail->key = $key;
- $detail->value = $value;
- $detail->type = $formMap[$key];
- $detail->is_delete = 0;
- $detail->save();
- }
- $transaction->commit();
- return $this->asJson(['code' => 0, 'msg' => '保存成功']);
- } catch (\Exception $e) {
- $transaction->rollBack();
- return $this->asJson(['code' => 1, 'msg' => $e->getMessage()]);
- }
- }
- /**
- * 模块名:event-form-list
- * 接口功能: 获取指定活动的自定义表单结构
- * 请求方式: GET
- * 作者: WPing丶
- * 时间: 2025-07-15 19:35:51
- * @param int $event_id 活动ID
- * @param int $user_id 用户ID
- * @param int $form_type 表单类型:1=企业;2=机构;
- */
- public function actionEventFormList()
- {
- $store_id = get_store_id();
- $event_id = (int)get_params('event_id');
- $user_id = (int)get_params('user_id');
- $form_type = (int)get_params('form_type');
- if (!$event_id) {
- return $this->asJson(['code' => 1, 'msg' => '活动ID不能为空']);
- }
- // 查询活动是否存在
- $event = Event::find()
- ->where([
- 'id' => $event_id,
- 'store_id' => $store_id,
- 'is_delete' => 0,
- ])
- ->one();
- if (!$event) {
- return $this->asJson(['code' => 1, 'msg' => '活动不存在']);
- }
- if ($event->end_time <= time()) {
- return $this->asJson(['code' => 1, 'msg' => '活动已经结束无法报名']);
- }
- // 查询该活动所有表单结构
- $form_list = EventForm::find()
- ->where([
- 'event_id' => $event_id,
- 'form_type' => $form_type,
- 'is_delete' => 0
- ])
- ->orderBy('sort ASC')
- ->asArray()
- ->all();
- // 将表单按 form_type 进行分组(1=企业,2=机构)
- $form_group = [];
- foreach ($form_list as &$item) {
- if($user_id > 0) {//2025年7月25日11:45:43 修改兼容没有user_id的情况
- $item['value'] = EventFormDetail::findOne(['user_id' => $user_id, 'event_id' => $event_id, 'key' => $item['name']])->value ?: '';
- }
- $form_group[] = $item;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'event_id' => $event_id,
- 'form' => $form_group
- ]
- ]);
- }
- /**
- * 模块名:sign-staff-list
- * 代码描述:签到员列表
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2025/07/16 11:07:26
- * @param string name 姓名
- * @param string mobile 手机号
- * @param int page
- * @param int limit
- */
- public function actionSignStaffList()
- {
- $store_id = get_store_id();
- $name = get_params('name');
- $mobile = get_params('mobile');
- $page = (int)get_params('page', 1);
- $limit = (int)get_params('limit', 10);
- $query = EventSignStaff::find()->alias('es')
- ->leftJoin(['u' => User::tableName()], 'u.id = es.user_id')
- ->where(['es.store_id' => $store_id, 'es.is_delete' => 0]);
-
- if($name) {
- $query->andWhere(['like','name',$name]);
- }
- if($mobile) {
- $query->andWhere(['like','mobile',$mobile]);
- }
- $count = $query->count();
- $pagination = new Pagination([
- 'totalCount' => $count,
- 'pageSize' => $limit,
- 'page' => $page - 1
- ]);
- $list = $query
- ->select(['es.id', 'es.user_id', 'es.name', 'es.mobile', 'u.avatar_url'])
- ->orderBy('es.created_at DESC')
- ->offset($pagination->offset)
- ->limit($pagination->limit)
- ->asArray()
- ->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list
- ]
- ]);
- }
- /**
- * 模块名:add-sign-staff
- * 代码描述:添加签到员
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2025/07/16 10:55:27
- * @param int user_id
- * @param string mobile 手机号
- * @param string name 签到员姓名
- */
- public function actionAddSignStaff()
- {
- $store_id = get_store_id();
- $user_id = (int)post_params('user_id');
- $mobile = post_params('mobile');
- $name = post_params('name');
- if (!$user_id) {
- return $this->asJson(['code' => 1, 'msg' => '参数错误']);
- }
- $exists = EventSignStaff::findOne(['user_id' => $user_id, 'is_delete' => 0]);
- if ($exists) {
- return $this->asJson(['code' => 1, 'msg' => '该用户已是签到员']);
- }
- $staff = new EventSignStaff();
- $staff->store_id = $store_id;
- $staff->user_id = $user_id;
- $staff->mobile = $mobile;
- $staff->name = $name;
- $staff->created_at = time();
- $staff->updated_at = time();
- $staff->is_delete = 0;
- if ($staff->save()) {
- return $this->asJson(['code' => 0, 'msg' => '添加成功']);
- }
- return $this->asJson(['code' => 1, 'msg' => '添加失败']);
- }
- /**
- * 模块名:del-sign-staff
- * 代码描述:删除签到员
- * 作者:WPing丶
- * 请求方式:POST
- * 创建时间:2025/07/16 11:24:19
- * @param int user_id
- */
- public function actionDelSignStaff()
- {
- $user_id = (int)post_params('user_id');
- if (!$user_id) {
- return $this->asJson(['code' => 1, 'msg' => '参数错误']);
- }
- $staff = EventSignStaff::findOne(['user_id' => $user_id, 'is_delete' => 0]);
- if (!$staff) {
- return $this->asJson(['code' => 1, 'msg' => '签到员不存在']);
- }
- $staff->is_delete = 1;
- $staff->updated_at = time();
- $staff->save();
- return $this->asJson(['code' => 0, 'msg' => '删除成功']);
- }
- /**
- * 模块名:export-event-user
- * 代码描述:活动导出核心逻辑
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2025/07/16 09:22:05
- * @param int event_id 活动ID
- */
- public function actionExportEventUser()
- {
- $store_id = get_store_id();
- $event_id = (int)get_params('event_id');
- if (!$event_id) {
- return $this->asJson(['code' => 1, 'msg' => '缺少活动ID']);
- }
- // 获取活动
- $event = Event::findOne([
- 'id' => $event_id,
- 'store_id' => $store_id,
- 'is_delete' => 0
- ]);
- if (!$event) {
- return $this->asJson(['code' => 1, 'msg' => '活动不存在']);
- }
- // 获取所有报名用户
- $users = EventUser::find()
- ->where([
- 'event_id' => $event_id,
- 'store_id' => $store_id,
- 'is_delete' => 0
- ])
- ->orderBy(['company_code' => SORT_ASC])
- ->asArray()
- ->all();
- $user_ids = array_column($users, 'id');
- // 获取所有自定义字段(按顺序)
- $fields = EventForm::find()
- ->where([
- 'event_id' => $event_id,
- 'is_delete' => 0
- ])
- ->orderBy('sort ASC')
- ->select('name')
- ->column(); // 自定义字段的字段名数组(表头用)
- // 获取所有表单填写内容
- $details = EventFormDetail::find()
- ->where([
- 'event_id' => $event_id,
- 'store_id' => $store_id,
- 'is_delete' => 0,
- 'event_user_id' => $user_ids
- ])
- ->asArray()
- ->all();
- $detail_map = []; // [event_user_id][key] => value
- foreach ($details as $d) {
- $detail_map[$d['event_user_id']][$d['key']] = $d['value'];
- }
- // ===== 动态构造导出表头 =====
- $head = [
- 'ID',
- '是否到场',
- '报名时间',
- '签到时间',
- '公司名称',
- '公司地址',
- '统一社会信息代码',
- '参会人姓名',
- '身份证号',
- '电话',
- ];
- $head = array_merge($head, $fields); // 合并自定义字段
- $rows = [$head];
- // ===== 统计用变量 =====
- $current_code = '';
- $company_total = 0;
- $company_arrived = 0;
- $global_total = 0;
- $global_arrived = 0;
- $company_count = 0;
- foreach ($users as $index => $u) {
- $global_total++;
- if ($u['sign_time']) $global_arrived++;
- // 判断是否是新公司
- if ($u['company_code'] !== $current_code) {
- if ($current_code) {
- // 输出上一家公司小计行
- $rows[] = [
- '', '', '', '', "【{$current_code}】公司小计:共 {$company_total} 人,到场 {$company_arrived} 人"
- ];
- }
- // 初始化当前公司统计
- $current_code = $u['company_code'];
- $company_total = 0;
- $company_arrived = 0;
- $company_count++;
- }
- $company_total++;
- if ($u['sign_time']) $company_arrived++;
- $row = [
- $u['id'],
- $u['sign_time'] > 0 ? '是' : '否',
- $u['created_at'] ? date('Y-m-d H:i:s', $u['created_at']) : '/',
- $u['sign_time'] ? date('Y-m-d H:i:s', $u['sign_time']) : '/',
- $u['company_name'],
- $u['company_address'],
- $u['company_code'],
- $u['real_name'],
- $u['identity_card'],
- $u['phone'],
- ];
- // 拼接自定义字段部分
- foreach ($fields as $f) {
- $row[] = $detail_map[$u['id']][$f] ?? '';
- }
- $rows[] = $row;
- }
- // 最后一个公司小计
- if ($current_code) {
- $rows[] = [
- '', '', '', '', "【{$current_code}】公司小计:共 {$company_total} 人,到场 {$company_arrived} 人"
- ];
- }
- // 全部汇总
- $rows[] = [
- '', '', '', '', "全部报名统计:共 {$global_total} 人,到场 {$global_arrived} 人,参与公司数量:{$company_count}"
- ];
- return $this->exportExcel($rows);
- }
- /**
- * 模块名:export-excel
- * 代码描述:导出相关请求
- * 作者:WPing丶
- * 创建时间:2025/07/16 09:23:36
- * @param int rows
- */
- private function exportExcel($rows)
- {
- \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload('event_export_' . date('Ymd_His') . '.xlsx')
- ->noHeaderRow()
- ->addRows($rows)
- ->toBrowser();
- }
- /**
- * 获取轮播图配置
- * 模块名:event-setting-banner
- * 方法名:actionGetEventBanner
- * 请求方式:GET
- */
- public function actionGetEventBanner()
- {
- $store_id = get_store_id();
- $setting = EventSetting::findOne([
- 'store_id' => $store_id,
- 'is_delete' => 0
- ]);
- if (!$setting || empty($setting->banner)) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => []
- ]);
- }
- $banner = json_decode($setting->banner, true);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $banner
- ]);
- }
- /**
- * 保存轮播图配置
- * 模块名:save-event-banner
- * 方法名:actionSaveEventBanner
- * 请求方式:POST
- * 参数:banner(轮播图数组)
- */
- public function actionSaveEventBanner()
- {
- $store_id = get_store_id();
- $banner = post_params('banner', []);
- if (!is_array($banner)) {
- return $this->asJson(['code' => 1, 'msg' => '参数格式错误,必须是数组']);
- }
- // 转为 JSON 字符串
- $banner_json = json_encode($banner, JSON_UNESCAPED_SLASHES);
- // 查询配置记录
- $setting = EventSetting::findOne([
- 'store_id' => $store_id,
- 'is_delete' => 0
- ]);
- if (!$setting) {
- // 如果不存在则新建一条记录
- $setting = new EventSetting();
- $setting->store_id = $store_id;
- $setting->created_at = time();
- $setting->is_delete = 0;
- }
- // 保存轮播图字段
- $setting->banner = $banner_json;
- $setting->updated_at = time();
- if ($setting->save()) {
- return $this->asJson(['code' => 0, 'msg' => '保存成功']);
- } else {
- return $this->asJson(['code' => 1, 'msg' => '保存失败,请重试']);
- }
- }
- /**
- * 模块名:del-sign-staff
- * 代码描述:删除审核记录
- * 作者:WPing丶
- * 请求方式:POST
- * 创建时间:2025/07/16 11:24:19
- * @param int ids
- */
- public function actionDelEventUser()
- {
- $ids = get_params('ids');
- $store_id = get_store_id();
- if (empty($ids) || !is_array($ids)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少删除的活动ID',
- ]);
- }
- $transaction = Yii::$app->db->beginTransaction();
- try {
- foreach ($ids as $id) {
- $eventUser = EventUser::find()
- ->where(['id' => $id, 'store_id' => $store_id, 'is_delete' => 0])
- ->one();
- if (!$eventUser) {
- throw new \Exception("记录 ID【{$id}】不存在或已删除");
- }
- // 删除关联数据(软删除)
- EventFormDetail::updateAll(['is_delete' => 1], ['event_user_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
- // 删除主表记录
- $eventUser->is_delete = 1;
- if (!$eventUser->save()) {
- throw new \Exception("记录 ID【{$id}】删除失败");
- }
- }
- $transaction->commit();
- debug_log('批量删除活动,event_user_id集合=【' . implode(',', $ids) . '】,并删除所有关联数据', 'event.log');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功',
- ]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败:' . $e->getMessage(),
- ]);
- }
- }
- /* end */
- }
|