MarketingController.php 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\constants\OptionSetting;
  9. use app\models\Coupon;
  10. use app\models\CouponAutoSend;
  11. use app\models\Event;
  12. use app\models\EventForm;
  13. use app\models\EventFormDetail;
  14. use app\models\EventSetting;
  15. use app\models\EventSignStaff;
  16. use app\models\EventUser;
  17. use app\models\Insurance;
  18. use app\models\User;
  19. use app\models\VerifyCard;
  20. use app\models\VerifyCardAccount;
  21. use app\modules\admin\models\CardForm;
  22. use app\modules\admin\models\CouponForm;
  23. use app\modules\admin\models\TopicTypeForm;
  24. use app\modules\admin\models\VerifyCardForm;
  25. use app\modules\admin\models\VerifyCardSaleForm;
  26. use app\modules\admin\models\RechargeForm;
  27. use app\modules\admin\models\RechargeSettingForm;
  28. use app\modules\admin\models\CouponAutoSendForm;
  29. use app\utils\ShareQrcode;
  30. use yii\base\BaseObject;
  31. use app\modules\admin\models\ReOrderForm;
  32. use Spatie\SimpleExcel\SimpleExcelWriter;
  33. use Yii;
  34. use yii\data\Pagination;
  35. /**
  36. * Undocumented class
  37. *
  38. * @Author LGL 24963@qq.com
  39. * @DateTime 2021-01-08
  40. * @desc: 营销管理
  41. */
  42. class MarketingController extends BaseController
  43. {
  44. /**
  45. * Undocumented function
  46. *
  47. * @Author LGL 24963@qq.com
  48. * @DateTime 2021-01-06
  49. * @desc: 优惠券列表
  50. */
  51. public function actionCouponList()
  52. {
  53. $param = get_params();
  54. $form = new CouponForm();
  55. $form->scenario = $form::SCENARIO_LIST;
  56. $form->attributes = $param;
  57. $form->store_id = get_store_id();
  58. return $this->asJson($form->searchCoupon());
  59. }
  60. /**
  61. * Undocumented function
  62. *
  63. * @desc: 商盟优惠券列表
  64. */
  65. public function actionBusinessCouponList()
  66. {
  67. $param = get_params();
  68. $form = new CouponForm();
  69. $form->scenario = $form::SCENARIO_LIST;
  70. $form->attributes = $param;
  71. return $this->asJson($form->searchCoupon());
  72. }
  73. /**
  74. * 商盟优惠券状态
  75. */
  76. public function actionBusinessCouponStatus()
  77. {
  78. $id = post_params('id');
  79. $status = post_params('status');
  80. if (!in_array($status, [1, 0])) {
  81. return $this->asJson([
  82. 'code' => 1,
  83. 'msg' => '参数不正确'
  84. ]);
  85. }
  86. $coupon = Coupon::findOne($id);
  87. if (!$coupon) {
  88. return $this->asJson([
  89. 'code' => 1,
  90. 'msg' => '数据不存在'
  91. ]);
  92. }
  93. Coupon::updateAll(['business_status' => $status], ['id' => $id]);
  94. return $this->asJson([
  95. 'code' => 0,
  96. 'msg' => '更新成功'
  97. ]);
  98. }
  99. /**
  100. * 优惠券添加
  101. * @return \yii\web\Response
  102. */
  103. public function actionCouponAdd()
  104. {
  105. $param = post_params();
  106. if (!isset($param['is_business'])) {
  107. $param['is_business'] = 0;
  108. }
  109. if (!isset($param['business_type'])) {
  110. $param['business_type'] = 0;
  111. }
  112. $form = new CouponForm();
  113. $form->scenario = $form::SCENARIO_ADD;
  114. $form->attributes = $param;
  115. $form->store_id = get_store_id();
  116. if (isset($param['begin_time']) && $param['begin_time']) {
  117. $form->begin_time = strtotime($param['begin_time']);
  118. }
  119. if (isset($param['end_time']) && $param['end_time']) {
  120. $form->end_time = strtotime($param['end_time']);
  121. }
  122. return $this->asJson($form->saveCoupon());
  123. }
  124. /**
  125. * 优惠券状态
  126. * @return \yii\web\Response
  127. */
  128. public function actionCouponStatus()
  129. {
  130. $id = post_params('id');
  131. $is_join = post_params('is_join');
  132. $coupon = Coupon::findOne($id);
  133. if (!$coupon) {
  134. return $this->asJson([
  135. 'code' => 1,
  136. 'msg' => '数据不存在'
  137. ]);
  138. }
  139. Coupon::updateAll(['is_join' => $is_join], ['id' => $id]);
  140. return $this->asJson([
  141. 'code' => 0,
  142. 'msg' => '更新成功'
  143. ]);
  144. }
  145. /**
  146. * 优惠券批量操作
  147. * @return \yii\web\Response
  148. */
  149. public function actionCouponBatch()
  150. {
  151. $id = post_params('id');
  152. $status = post_params('status');
  153. if (!is_array($id)) {
  154. return $this->asJson([
  155. 'code' => 1,
  156. 'msg' => '参数不正确'
  157. ]);
  158. }
  159. Coupon::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
  160. return $this->asJson([
  161. 'code' => 0,
  162. 'msg' => '更新成功'
  163. ]);
  164. }
  165. /**
  166. * 优惠券自动发放批量操作
  167. * @return \yii\web\Response
  168. */
  169. public function actionCouponAutoSendBatch()
  170. {
  171. $id = post_params('id');
  172. $status = post_params('status');
  173. if (!is_array($id)) {
  174. return $this->asJson([
  175. 'code' => 1,
  176. 'msg' => '参数不正确'
  177. ]);
  178. }
  179. CouponAutoSend::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
  180. return $this->asJson([
  181. 'code' => 0,
  182. 'msg' => '更新成功'
  183. ]);
  184. }
  185. /**
  186. * Undocumented function
  187. *
  188. * @Author gwc 756401197@qq.com
  189. * @DateTime 2021-12-13
  190. * @desc: 优惠券发放记录
  191. */
  192. public function actionCouponSendRecord()
  193. {
  194. //主键id用key标识并进行获取
  195. $param = get_params('key');
  196. $form = new CouponForm();
  197. $form->store_id = get_store_id();
  198. $form->id = $param;
  199. $res = $form->CouponSendRecord();
  200. return $this->asJson($res);
  201. }
  202. /**
  203. * Undocumented function
  204. *
  205. * @Author gwc 756401197@qq.com
  206. * @DateTime 2021-12-13
  207. * @desc: 小程序二维码
  208. * @return void
  209. */
  210. public function actionGetCouponQrcode()
  211. {
  212. //主键id用key标识并进行获取
  213. $param = get_params('key');
  214. try {
  215. $res = ShareQrcode::wxQrcode('pages/home/home', $param);
  216. if ($res['code'] == 1) {
  217. return $this->asJson([
  218. 'code' => 1,
  219. 'msg' => $res['response']['errmsg'],
  220. ]);
  221. }
  222. return $this->asJson([
  223. 'code' => 0,
  224. 'msg' => 'success',
  225. 'data' => $res['url_path'],
  226. ]);
  227. } catch (\Exception $e) {
  228. return $this->asJson([
  229. 'code' => 1,
  230. 'msg' => $e->getMessage(),
  231. ]);
  232. }
  233. // $form = new CouponForm();
  234. // $form->store_id = get_store_id();
  235. // $form->id = $param;
  236. // $res = $form->CouponSendRecord();
  237. // return $this->asJson($res);
  238. }
  239. /**
  240. * 卡券批量操作
  241. * @return \yii\web\Response
  242. */
  243. /**
  244. * 优惠券编辑
  245. * @return \yii\web\Response
  246. */
  247. public function actionVerifyCardBatch()
  248. {
  249. $id = post_params('id');
  250. $status = post_params('status');
  251. if (!is_array($id)) {
  252. return $this->asJson([
  253. 'code' => 1,
  254. 'msg' => '参数不正确'
  255. ]);
  256. }
  257. VerifyCard::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
  258. return $this->asJson([
  259. 'code' => 0,
  260. 'msg' => '更新成功'
  261. ]);
  262. }
  263. public function actionCouponEdit()
  264. {
  265. $param = post_params();
  266. $form = new CouponForm();
  267. $form->scenario = $form::SCENARIO_EDIT;
  268. $form->attributes = $param;
  269. $form->store_id = get_store_id();
  270. if (isset($param['begin_time']) && $param['begin_time']) {
  271. $form->begin_time = strtotime($param['begin_time'] . ' 00:00:00');
  272. }
  273. if (isset($param['end_time']) && $param['end_time']) {
  274. $form->end_time = strtotime($param['end_time'] . ' 23:59:59');
  275. }
  276. return $this->asJson($form->saveCoupon());
  277. }
  278. /**
  279. * Undocumented function
  280. *
  281. * @Author LGL 24963@qq.com
  282. * @DateTime 2021-01-06
  283. * @desc: 优惠券删除
  284. * @return void
  285. */
  286. public function actionCouponDel()
  287. {
  288. //主键id用key标识并进行获取
  289. $param = get_params('key');
  290. $form = new CouponForm();
  291. $form->scenario = $form::SCENARIO_DEL;
  292. $form->id = $param;
  293. $res = $form->delCoupon();
  294. return $this->asJson($res);
  295. }
  296. /**
  297. * 商盟卡券状态
  298. */
  299. public function actionBusinessVerifyStatus()
  300. {
  301. $id = post_params('id');
  302. $status = post_params('status');
  303. if (!in_array($status, [1, 0])) {
  304. return $this->asJson([
  305. 'code' => 1,
  306. 'msg' => '参数不正确'
  307. ]);
  308. }
  309. $verify = VerifyCard::findOne($id);
  310. if (!$verify || !$verify['is_business']) {
  311. return $this->asJson([
  312. 'code' => 1,
  313. 'msg' => '数据不存在'
  314. ]);
  315. }
  316. if ($status == $verify['business_status']) {
  317. return $this->asJson([
  318. 'code' => 1,
  319. 'msg' => '状态相同,无需修改'
  320. ]);
  321. }
  322. VerifyCard::updateAll(['business_status' => $status], ['id' => $id]);
  323. return $this->asJson([
  324. 'code' => 0,
  325. 'msg' => '更新成功'
  326. ]);
  327. }
  328. /**
  329. * Undocumented function
  330. *
  331. * @desc: 商盟卡券列表
  332. */
  333. public function actionBusinessVerifyList()
  334. {
  335. $param = get_params();
  336. $form = new VerifyCardForm();
  337. $form->scenario = $form::SCENARIO_LIST;
  338. $param['is_business'] = 1;
  339. $form->attributes = $param;
  340. return $this->asJson($form->searchVerifyCard());
  341. }
  342. /**
  343. * Undocumented function
  344. *
  345. * @Author LGL 24963@qq.com
  346. * @DateTime 2021-01-06
  347. * @desc: 获取核销卡
  348. * @return void
  349. */
  350. public function actionVerifyList()
  351. {
  352. $param = get_params();
  353. $form = new VerifyCardForm();
  354. $form->scenario = $form::SCENARIO_LIST;
  355. $form->attributes = $param;
  356. $form->store_id = get_store_id();
  357. return $this->asJson($form->searchVerifyCard());
  358. }
  359. /**
  360. * Undocumented function
  361. *
  362. * @Author LGL 24963@qq.com
  363. * @DateTime 2021-01-06
  364. * @desc: 添加核销卡
  365. * @return void
  366. */
  367. public function actionVerifyAdd()
  368. {
  369. $param = post_params();
  370. $form = new VerifyCardForm();
  371. $form->scenario = $form::SCENARIO_ADD;
  372. if (!isset($param['is_business'])) {
  373. $param['is_business'] = 0;
  374. }
  375. if (!isset($param['business_type'])) {
  376. $param['business_type'] = 0;
  377. }
  378. $form->attributes = $param;
  379. $form->store_id = get_store_id();
  380. $form->share_user_id = post_params('share_user_id', []);
  381. if ($param['date']) {
  382. $form->begin_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][0])));
  383. $form->end_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][1])));
  384. } else {
  385. $form->begin_time = 0;
  386. $form->end_time = 0;
  387. }
  388. if (is_array($param['goods_ids']) && !empty($param['goods_ids'])) {
  389. $form->goods_ids = json_encode($param['goods_ids']);
  390. } else {
  391. $form->goods_ids = '';
  392. }
  393. if (is_array($param['video_ids']) && !empty($param['video_ids'])) {
  394. $form->video_ids = json_encode($param['video_ids']);
  395. } else {
  396. $form->video_ids = '';
  397. }
  398. if (!isset($param['is_business'])) {
  399. $param['is_business'] = 0;
  400. }
  401. if (!isset($param['business_type'])) {
  402. $param['business_type'] = 0;
  403. }
  404. $form->status = 0;
  405. $form->send_times = $form::SEDN_TIMES_DEFAULT;
  406. $res = $form->saveVerifyCard();
  407. return $this->asJson($res);
  408. }
  409. public function actionVcAccountSave()
  410. {
  411. $param = post_params();
  412. $form = new VerifyCardForm();
  413. $form->store_id = get_store_id();
  414. $res = $form->vcAccountSave($param['list']);
  415. return $this->asJson($res);
  416. }
  417. public function actionVerifyUp()
  418. {
  419. $param = post_params();
  420. $form = new VerifyCardForm();
  421. $res = $form->changePass($param['id'], $param['password']);
  422. return $this->asJson($res);
  423. }
  424. public function actionVerifyUpload()
  425. {
  426. if (\Yii::$app->request->isPost) {
  427. $form = new VerifyCardForm();
  428. $form->id = post_params('id');
  429. $form->store_id = get_store_id();
  430. $res = $form->upload();
  431. return $this->asJson($res);
  432. }
  433. }
  434. /**
  435. * Undocumented function
  436. *
  437. * @Author LGL 24963@qq.com
  438. * @DateTime 2022-01-05
  439. * @desc: 生成卡密信息
  440. * @return void
  441. */
  442. public function actionMakeCardInfo()
  443. {
  444. $param = post_params();
  445. $form = new VerifyCardForm();
  446. $form->scenario = $form::SCENARIO_ADD;
  447. $form->attributes = $param;
  448. $form->id = $param['key'];
  449. $form->store_id = get_store_id();
  450. $res = $form->generateAccount();
  451. return $this->asJson($res);
  452. }
  453. /**
  454. * 导出卡券卡密信息.csv
  455. */
  456. public function actionExport()
  457. {
  458. $id = get_params('key');
  459. if (!$id) {
  460. return $this->asJson([
  461. 'code' => 1,
  462. 'msg' => '缺少参数',
  463. ]);
  464. }
  465. $list = VerifyCardAccount::find()
  466. ->select('account, password, status')
  467. ->where([
  468. 'card_id' => $id,
  469. ])->orderBy('status ASC')->asArray()->all();
  470. $titles = ['账号', '密码', '状态'];
  471. $filename = date('YmdHis') . '.csv';
  472. header('Content-Type: text/csv');
  473. header("Content-Disposition: attachment;filename={$filename}");
  474. // $fp = fopen('php://output', 'w');
  475. $fp = fopen('php://temp/maxmemory:' . (12 * 1024 * 1024), 'r+');
  476. fwrite($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));
  477. fputcsv($fp, $titles);
  478. foreach ($list as $item) {
  479. $arr = [$item['account'], $item['password'], $item['status'] == 0 ? '未使用' : '已使用'];
  480. fputcsv($fp, $arr);
  481. }
  482. rewind($fp);
  483. $output = stream_get_contents($fp);
  484. fclose($fp);
  485. return $output;
  486. }
  487. /**
  488. * Undocumented function
  489. *
  490. * @Author LGL 24963@qq.com
  491. * @DateTime 2021-01-06
  492. * @desc: 编辑核销卡
  493. * @return void
  494. */
  495. public function actionVerifyEdit()
  496. {
  497. $param = post_params();
  498. $form = new VerifyCardForm();
  499. $form->scenario = $form::SCENARIO_EDIT;
  500. $form->attributes = $param;
  501. $form->store_id = get_store_id();
  502. $form->share_user_id = post_params('share_user_id', []);
  503. if (isset($param['date']) && $param['date']) {
  504. $form->begin_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][0])));
  505. $form->end_time = strtotime(date('Y-m-d H:i:s', strtotime($param['date'][1])));
  506. }
  507. if (is_array($param['goods_ids']) && !empty($param['goods_ids'])) {
  508. $form->goods_ids = json_encode($param['goods_ids']);
  509. } else {
  510. $form->goods_ids = '';
  511. }
  512. if (is_array($param['video_ids']) && !empty($param['video_ids'])) {
  513. $form->video_ids = json_encode($param['video_ids']);
  514. } else {
  515. $form->video_ids = '';
  516. }
  517. $res = $form->saveVerifyCard();
  518. return $this->asJson($res);
  519. }
  520. /**
  521. * Undocumented function
  522. *
  523. * @Author LGL 24963@qq.com
  524. * @DateTime 2021-01-06
  525. * @desc: 删除核销卡
  526. * @return void
  527. */
  528. public function actionVerifyDel()
  529. {
  530. //主键id用key标识并进行获取
  531. $param = get_params();
  532. $form = new VerifyCardForm();
  533. $form->scenario = $form::SCENARIO_DEL;
  534. $form->attributes = $param;
  535. $res = $form->delVerifyCard();
  536. return $this->asJson($res);
  537. }
  538. public function actionVerifyTmp()
  539. {
  540. $param = all_params();
  541. $form = new VerifyCardForm();
  542. $form->attributes = $param;
  543. $res = $form->verifyTmp();
  544. return $this->asJson($res);
  545. }
  546. public function actionGetAccountInfo()
  547. {
  548. //主键id用key标识并进行获取
  549. $param = get_params('key');
  550. $form = new VerifyCardForm();
  551. $form->id = $param;
  552. $form->store_id = get_store_id();
  553. $res = $form->getAccountInfo();
  554. return $this->asJson($res);
  555. }
  556. /**
  557. * Undocumented function
  558. *
  559. * @desc: 卡券信息详情
  560. * @return array
  561. */
  562. public function actionVerifyDetail()
  563. {
  564. //主键id用key标识并进行获取
  565. $param = get_params('key');
  566. $form = new VerifyCardForm();
  567. $form->attributes = all_params();
  568. $form->id = $param;
  569. $form->store_id = get_store_id();
  570. $res = $form->verifyDetail();
  571. return $this->asJson($res);
  572. }
  573. public function actionVerifyShare()
  574. {
  575. $form = new VerifyCardForm();
  576. return $this->asJson($form->searchVerifyShareList(get_params('id')));
  577. }
  578. /**
  579. * Undocumented function
  580. *
  581. * @Author LGL 24963@qq.com
  582. * @DateTime 2021-01-06
  583. * @desc: 获取核销卡订单
  584. * @return void
  585. */
  586. public function actionVerifySaleList()
  587. {
  588. $param = get_params();
  589. $form = new VerifyCardSaleForm();
  590. $form->scenario = $form::SCENARIO_LIST;
  591. $form->attributes = $param;
  592. $form->store_id = get_store_id();
  593. return $this->asJson($form->searchVerifyCardSale());
  594. }
  595. //订单赠送卡券记录
  596. public function actionVerifyCardOrderGetList()
  597. {
  598. $param = all_params();
  599. $form = new VerifyCardForm();
  600. $form->attributes = $param;
  601. $form->store_id = get_store_id();
  602. return $this->asJson($form->searchVerifyCardOrderGetList());
  603. }
  604. //核销记录
  605. public function actionVerifyCardLogList()
  606. {
  607. $param = all_params();
  608. $form = new VerifyCardForm();
  609. $form->attributes = $param;
  610. $form->store_id = get_store_id();
  611. return $this->asJson($form->searchVerifyCardLogList());
  612. }
  613. /* begin 2024/11/16 14:47:38 id1126开发需求:新增储值卡消费记录 WPing丶 */
  614. public function actionCardPayLogList()
  615. {
  616. $param = all_params();
  617. $form = new VerifyCardForm();
  618. $form->attributes = $param;
  619. $form->store_id = get_store_id();
  620. return $this->asJson($form->searchCardPayLogList());
  621. }
  622. /* end */
  623. /**
  624. * Undocumented function
  625. *
  626. * @Author LGL 24963@qq.com
  627. * @DateTime 2021-01-09
  628. * @desc: 卡券列表
  629. * @return void
  630. */
  631. public function actionCardCouponList()
  632. {
  633. $param = get_params();
  634. $form = new CardForm();
  635. $form->scenario = $form::SCENARIO_LIST;
  636. $form->attributes = $param;
  637. $form->store_id = get_store_id();
  638. return $this->asJson($form->searchCard());
  639. }
  640. /**
  641. * Undocumented function
  642. *
  643. * @Author LGL 24963@qq.com
  644. * @DateTime 2021-01-09
  645. * @desc: 添加卡券
  646. * @return void
  647. */
  648. public function actionCardCouponAdd()
  649. {
  650. $param = post_params();
  651. $form = new CardForm();
  652. $form->scenario = $form::SCENARIO_ADD;
  653. $form->attributes = $param;
  654. $form->store_id = get_store_id();
  655. $res = $form->saveCard();
  656. return $this->asJson($res);
  657. }
  658. /**
  659. * Undocumented function
  660. *
  661. * @Author LGL 24963@qq.com
  662. * @DateTime 2021-01-09
  663. * @desc: 编辑卡券
  664. * @return void
  665. */
  666. public function actionCardCouponEdit()
  667. {
  668. $param = post_params();
  669. $form = new CardForm();
  670. $form->scenario = $form::SCENARIO_EDIT;
  671. $form->attributes = $param;
  672. $form->store_id = get_store_id();
  673. $res = $form->saveCard();
  674. return $this->asJson($res);
  675. }
  676. /**
  677. * Undocumented function
  678. *
  679. * @Author LGL 24963@qq.com
  680. * @DateTime 2021-01-09
  681. * @desc: 删除卡券
  682. * @return void
  683. */
  684. public function actionCardCouponDel()
  685. {
  686. //主键id用key标识并进行获取
  687. $param = get_params('key');
  688. $form = new CardForm();
  689. $form->scenario = $form::SCENARIO_DEL;
  690. $form->id = $param;
  691. $res = $form->delCard();
  692. return $this->asJson($res);
  693. }
  694. public function actionRechargeOrder()
  695. {
  696. $param = get_params();
  697. $form = new ReOrderForm();
  698. $form->attributes = $param;
  699. $form->store_id = get_store_id();
  700. return $this->asJson($form->search());
  701. }
  702. //充值订单申请退款
  703. // public function actionRechargeOrderRefundMoneyApply()
  704. // {
  705. // $form = new ReOrderForm();
  706. // $form->store_id = get_store_id();
  707. // $user_id = input_params('user_id', 0);
  708. // $order_id = input_params('order_id', 0);
  709. // $desc_user = input_params('desc_user', '');
  710. // return $this->asJson($form->refundMoneyApply($user_id, $order_id, $desc_user));
  711. // }
  712. //充值订单退款列表
  713. public function actionRechargeOrderRefundMoneyList()
  714. {
  715. $param = get_params();
  716. $form = new ReOrderForm();
  717. $form->attributes = $param;
  718. $form->store_id = get_store_id();
  719. return $this->asJson($form->refundMoneyList());
  720. }
  721. //充值订单退款审核
  722. public function actionRechargeOrderRefundMoneyAudit()
  723. {
  724. $form = new ReOrderForm();
  725. $form->store_id = get_store_id();
  726. $audit_status = input_params('audit_status', 0);
  727. $refund_id = input_params('refund_id', 0);
  728. $desc_admin = input_params('desc_admin', '');
  729. $refund_price = input_params('refund_price', 0.01);
  730. $sub_balance = input_params('sub_balance', 0);
  731. $sub_integral = input_params('sub_integral', 0);
  732. return $this->asJson($form->refundMoneyAudit($audit_status, $refund_id, $desc_admin, $refund_price, $sub_balance, $sub_integral));
  733. }
  734. /**
  735. * Undocumented function
  736. *
  737. * @Author LGL 24963@qq.com
  738. * @DateTime 2021-01-12
  739. * @desc: 充值方案列表
  740. * @return void
  741. */
  742. public function actionRechargeList()
  743. {
  744. $param = get_params();
  745. $form = new RechargeForm();
  746. $form->scenario = $form::SCENARIO_LIST;
  747. $form->attributes = $param;
  748. $form->store_id = get_store_id();
  749. return $this->asJson($form->searchRecharge());
  750. }
  751. /**
  752. * Undocumented function
  753. *
  754. * @Author LGL 24963@qq.com
  755. * @DateTime 2021-01-12
  756. * @desc: 充值方案添加
  757. * @return void
  758. */
  759. public function actionRechargeAdd()
  760. {
  761. $param = post_params();
  762. $form = new RechargeForm();
  763. $form->scenario = $form::SCENARIO_ADD;
  764. $form->attributes = $param;
  765. $form->assign_member = post_params('assign_member');
  766. $form->referral_commission = json_encode((post_params('referral_commission')));
  767. $form->store_id = get_store_id();
  768. $res = $form->saveRecharge();
  769. return $this->asJson($res);
  770. }
  771. /**
  772. * Undocumented function
  773. *
  774. * @Author LGL 24963@qq.com
  775. * @DateTime 2021-01-12
  776. * @desc: 充值方案编辑
  777. * @return void
  778. */
  779. public function actionRechargeEdit()
  780. {
  781. $param = post_params();
  782. $form = new RechargeForm();
  783. $form->scenario = $form::SCENARIO_EDIT;
  784. $form->attributes = $param;
  785. if (is_array(post_params('assign_member'))) {
  786. $form->assign_member = json_encode(post_params('assign_member'));
  787. } else {
  788. $form->assign_member = post_params('assign_member');
  789. }
  790. $form->referral_commission = json_encode(post_params('referral_commission'));
  791. $form->store_id = get_store_id();
  792. $res = $form->saveRecharge();
  793. return $this->asJson($res);
  794. }
  795. /**
  796. * Undocumented function
  797. *
  798. * @Author LGL 24963@qq.com
  799. * @DateTime 2021-01-12
  800. * @desc: 充值方案删除
  801. * @return void
  802. */
  803. public function actionRechargeDel()
  804. {
  805. //主键id用key标识并进行获取
  806. $param = get_params('key');
  807. $form = new RechargeForm();
  808. $form->scenario = $form::SCENARIO_DEL;
  809. $form->id = $param;
  810. $res = $form->delRecharge();
  811. return $this->asJson($res);
  812. }
  813. /**
  814. * Undocumented function
  815. *
  816. * @Author LGL 24963@qq.com
  817. * @DateTime 2021-01-12
  818. * @desc: 充值设置
  819. * @return void
  820. */
  821. public function actionRechargeSetting()
  822. {
  823. $param = post_params();
  824. $form = new RechargeSettingForm();
  825. // $form->scenario = $form::SCENARIO_EDIT;
  826. $form->attributes = $param;
  827. $form->store_id = get_store_id();
  828. $res = $form->saveRechargeSetting();
  829. return $this->asJson($res);
  830. }
  831. /**
  832. * Undocumented function
  833. *
  834. * @Author LGL 24963@qq.com
  835. * @DateTime 2021-01-12
  836. * @desc: 优惠券自动发放列表
  837. */
  838. public function actionCouponAutoSendList()
  839. {
  840. $param = get_params();
  841. $form = new CouponAutoSendForm();
  842. $form->scenario = $form::SCENARIO_LIST;
  843. $form->attributes = $param;
  844. $form->store_id = get_store_id();
  845. return $this->asJson($form->searchCouponAutoSend());
  846. }
  847. /**
  848. * Undocumented function
  849. *
  850. * @Author LGL 24963@qq.com
  851. * @DateTime 2021-01-12
  852. * @desc: 优惠券自动发放添加
  853. * @return void
  854. */
  855. public function actionCouponAutoSendAdd()
  856. {
  857. $param = post_params();
  858. if (empty($param['coupon_id'])) {
  859. return $this->asJson([
  860. 'code' => 1,
  861. 'msg' => '请选择优惠券'
  862. ]);
  863. }
  864. $form = new CouponAutoSendForm();
  865. $form->scenario = $form::SCENARIO_ADD;
  866. $form->attributes = $param;
  867. $form->store_id = get_store_id();
  868. $res = $form->saveCouponAutoSend();
  869. return $this->asJson($res);
  870. }
  871. /**
  872. * Undocumented function
  873. *
  874. * @Author LGL 24963@qq.com
  875. * @DateTime 2021-01-12
  876. * @desc: 优惠券自动发放编辑
  877. * @return void
  878. */
  879. public function actionCouponAutoSendEdit()
  880. {
  881. $param = post_params();
  882. $form = new CouponAutoSendForm();
  883. $form->scenario = $form::SCENARIO_EDIT;
  884. $form->attributes = $param;
  885. $form->store_id = get_store_id();
  886. $res = $form->saveCouponAutoSend();
  887. return $this->asJson($res);
  888. }
  889. /**
  890. * Undocumented function
  891. *
  892. * @Author LGL 24963@qq.com
  893. * @DateTime 2021-01-12
  894. * @desc: 优惠券自动发放删除
  895. * @return void
  896. */
  897. public function actionCouponAutoSendDel()
  898. {
  899. //主键id用key标识并进行获取
  900. $param = get_params('key');
  901. $form = new CouponAutoSendForm();
  902. $form->scenario = $form::SCENARIO_DEL;
  903. $form->id = $param;
  904. $res = $form->delCouponAutoSend();
  905. return $this->asJson($res);
  906. }
  907. /**
  908. * Undocumented function
  909. *
  910. * @Author LGL 24963@qq.com
  911. * @DateTime 2021-01-13
  912. * @desc: 发放优惠券
  913. */
  914. public function actionCouponSendUser()
  915. {
  916. $param = post_params();
  917. $res = CouponForm::userAddCoupon($param['user_id'], $param['coupon_id']);
  918. return $this->asJson($res);
  919. }
  920. /**
  921. * 优惠券自动发放规则状态
  922. * @return \yii\web\Response
  923. */
  924. public function actionRuleStatus()
  925. {
  926. $id = post_params('id');
  927. $status = intval(post_params('status'));
  928. $coupon = CouponAutoSend::findOne($id);
  929. if (!$coupon) {
  930. return $this->asJson([
  931. 'code' => 1,
  932. 'msg' => '数据不存在'
  933. ]);
  934. }
  935. CouponAutoSend::updateAll(['status' => $status], ['id' => $id]);
  936. return $this->asJson([
  937. 'code' => 0,
  938. 'msg' => '更新成功'
  939. ]);
  940. }
  941. /* begin 2023/12/08 17:34:12 id958保单信息 WPing丶 */
  942. /**
  943. * 模块名:actionInsuranceEdit
  944. * 代码描述:添加和编辑保单
  945. * 作者:WPing丶
  946. * 请求方式:GET
  947. * 创建时间:2023/12/08 17:34:59
  948. * @param int id
  949. * @param string str
  950. * @param bool bool
  951. */
  952. public function actionInsuranceEdit() {
  953. $post_params = post_params();
  954. $store_id = get_store_id();
  955. $insurance = Insurance::findOne(['id' => post_params('id'), 'is_delete' => 0]);
  956. if(!$insurance) {
  957. $insurance = new Insurance();
  958. }
  959. $query = Insurance::find()->where(['phone' => $post_params['phone'], 'store_id' => $store_id]);
  960. if(post_params('id') > 0) {
  961. $query->andWhere(['<>', 'id', post_params('id')]);
  962. }
  963. $exist = $query->exists();
  964. if($exist) {
  965. return $this->asJson([
  966. 'code' => 1,
  967. 'msg' => '手机号不能重复'
  968. ]);
  969. }
  970. $insurance->store_id = $store_id;
  971. $insurance->name = $post_params['name'];
  972. $insurance->phone = $post_params['phone'];
  973. $insurance->address = $post_params['address'];
  974. $insurance->date = $post_params['date'];
  975. $insurance->serve = $post_params['serve'];
  976. $insurance->price = $post_params['price'];
  977. $insurance->serve_man = $post_params['serve_man'];
  978. $insurance->live_room_url = $post_params['live_room_url'];
  979. if($_FILES['insurance_file']) {
  980. //保单信息
  981. $insurance_filename = $_FILES['insurance_file']['name'];
  982. $insurance_tmpname = $_FILES['insurance_file']['tmp_name'];
  983. $path = \Yii::$app->basePath . '/web/uploads/pdf/store_'.$store_id.'/';
  984. // 如果目录不存在,则创建目录
  985. if (!is_dir($path) && !mkdir($path, 0777, true)) {
  986. return $this->asJson([
  987. 'code' => 1,
  988. 'msg' => '无法创建目录:' . $path
  989. ]);
  990. }
  991. $ext = strtolower(pathinfo($insurance_filename, PATHINFO_EXTENSION));
  992. if (($ext != 'pdf')) {
  993. return $this->asJson([
  994. 'code' => 1,
  995. 'msg' => '请上传pdf文件'
  996. ]);
  997. }
  998. $file = time() . $store_id . '_insurance.' . $ext;
  999. $insurance_uploadfile = $path . $file;
  1000. $insurance_result = move_uploaded_file($insurance_tmpname, $insurance_uploadfile);
  1001. if(!$insurance_result) {
  1002. return $this->asJson([
  1003. 'code' => 1,
  1004. 'msg' => '上传保单信息失败'
  1005. ]);
  1006. }
  1007. $insurance_url = \Yii::$app->request->hostInfo . '/web/uploads/pdf/store_'.$store_id.'/' . $file;
  1008. $insurance->insurance = $insurance_url;
  1009. }
  1010. if($_FILES['report_file']) {
  1011. //报告
  1012. $report_filename = $_FILES['report_file']['name'];
  1013. $report_tmpname = $_FILES['report_file']['tmp_name'];
  1014. $path = \Yii::$app->basePath . '/web/uploads/pdf/store_'.$store_id.'/';
  1015. // 如果目录不存在,则创建目录
  1016. if (!is_dir($path) && !mkdir($path, 0777, true)) {
  1017. return $this->asJson([
  1018. 'code' => 1,
  1019. 'msg' => '无法创建目录:' . $path
  1020. ]);
  1021. }
  1022. $ext = strtolower(pathinfo($report_filename, PATHINFO_EXTENSION));
  1023. if (($ext != 'pdf')) {
  1024. return $this->asJson([
  1025. 'code' => 1,
  1026. 'msg' => '请上传pdf文件'
  1027. ]);
  1028. }
  1029. $file = time() . $store_id . '_report.' . $ext;
  1030. $report_uploadfile = $path . $file;
  1031. $report_result = move_uploaded_file($report_tmpname, $report_uploadfile);
  1032. if(!$report_result) {
  1033. return $this->asJson([
  1034. 'code' => 1,
  1035. 'msg' => '上传报告失败'
  1036. ]);
  1037. }
  1038. $report_url = \Yii::$app->request->hostInfo . '/web/uploads/pdf/store_'.$store_id.'/' . $file;
  1039. $insurance->report = $report_url;
  1040. }
  1041. $insurance->search_num = $post_params['search_num'];
  1042. if(!$insurance->save()) {
  1043. return $this->asJson([
  1044. 'code' => 1,
  1045. 'msg' => '操作失败',
  1046. 'test' => json_encode($insurance->errors)
  1047. ]);
  1048. }
  1049. return $this->asJson([
  1050. 'code' => 0,
  1051. 'msg' => '操纵成功'
  1052. ]);
  1053. }
  1054. /**
  1055. * 模块名:actionInsuranceList
  1056. * 代码描述:保单列表
  1057. * 作者:WPing丶
  1058. * 请求方式:GET
  1059. * 创建时间:2023/12/11 13:55:29
  1060. */
  1061. public function actionInsuranceList() {
  1062. $get_params = get_params();
  1063. $query = Insurance::find()->where(['is_delete' => 0, 'store_id' => get_store_id()]);
  1064. if($get_params['search_key']) {
  1065. $query->andWhere(['like','name',$get_params['search_key']]);
  1066. }
  1067. $list = $query->orderBy('created_at DESC, id DESC')->asArray()->all();
  1068. $count = count($list);
  1069. $data = array_slice($list, (get_params('pageNo') - 1) * ($get_params['pageSize']?:10), $get_params['pageSize']?:10);
  1070. return $this->asJson([
  1071. 'code' => 0,
  1072. 'msg' => 'success',
  1073. 'data' => [
  1074. 'data' => $data,
  1075. 'pageNo' => intval(get_params('pageNo')),
  1076. 'totalCount' => $count,
  1077. ]
  1078. ]);
  1079. }
  1080. /**
  1081. * 模块名:actionInsuranceDel
  1082. * 代码描述:保单删除
  1083. * 作者:WPing丶
  1084. * 请求方式:GET
  1085. * 创建时间:2023/12/11 15:27:40
  1086. */
  1087. public function actionInsuranceDel()
  1088. {
  1089. //主键id用key标识并进行获取
  1090. $id = get_params('key');
  1091. $ins = Insurance::findOne(['id' => $id, 'is_delete' => 0]);
  1092. if (!$ins) {
  1093. return $this->asJson([
  1094. 'code' => 1,
  1095. 'msg' => '保单不存在或已删除',
  1096. ]);
  1097. }
  1098. $ins->is_delete = 1;
  1099. if (!$ins->save()) {
  1100. return $this->asJson([
  1101. 'code' => 1,
  1102. 'msg' => '删除失败',
  1103. ]);
  1104. }
  1105. return $this->asJson([
  1106. 'code' => 0,
  1107. 'msg' => '删除成功',
  1108. ]);
  1109. }
  1110. /**
  1111. * 模块名:actionInsuranceBatch
  1112. * 代码描述:保单批量删除
  1113. * 作者:WPing丶
  1114. * 请求方式:GET
  1115. * 创建时间:2023/12/11 15:45:17\
  1116. */
  1117. public function actionInsuranceBatch()
  1118. {
  1119. $id = post_params('id');
  1120. $status = post_params('status');
  1121. if (!is_array($id)) {
  1122. return $this->asJson([
  1123. 'code' => 1,
  1124. 'msg' => '参数不正确'
  1125. ]);
  1126. }
  1127. Insurance::updateAll(['is_delete' => intval($status)], ['in', 'id', $id]);
  1128. return $this->asJson([
  1129. 'code' => 0,
  1130. 'msg' => '更新成功'
  1131. ]);
  1132. }
  1133. /* end */
  1134. /* begin 2025/07/09 16:56:26 id1248 WPing丶 */
  1135. /**
  1136. * 模块名:event-list
  1137. * 代码描述:活动列表
  1138. * 作者:WPing丶
  1139. * 请求方式:GET
  1140. * 创建时间:2025/07/09 16:57:07
  1141. * @param string name 活动名称
  1142. */
  1143. public function actionEventList() {
  1144. $get_params = get_params();
  1145. $status = $get_params['status'];
  1146. $query = Event::find()->where(['is_delete' => 0, 'store_id' => get_store_id()]);
  1147. $now = time();
  1148. if($get_params['search_key']) {
  1149. $query->andWhere(['like','name',$get_params['search_key']]);
  1150. }
  1151. if ($status === 'underway') {
  1152. $query->andWhere(['<=', 'start_time', $now])
  1153. ->andWhere(['>=', 'end_time', $now]);
  1154. } elseif ($status === 'done') {
  1155. $query->andWhere(['<', 'end_time', $now]);
  1156. } elseif ($status === 'not_started') {
  1157. $query->andWhere(['>', 'start_time', $now]);
  1158. }
  1159. // if (isset($get_params['start_time']) && $get_params['start_time']) {
  1160. // $form->start_time = strtotime($get_params['start_time']);
  1161. // }
  1162. // if (isset($get_params['end_time']) && $get_params['end_time']) {
  1163. // $form->end_time = strtotime($get_params['end_time']);
  1164. // }
  1165. $list = $query->orderBy('start_time DESC, id DESC')->asArray()->all();
  1166. foreach($list as &$item) {
  1167. $item['date_array'] = [date('Y-m-d H:i:s', $item['start_time']), date('Y-m-d H:i:s', $item['end_time'])];
  1168. if($item['start_time'] > $now) {
  1169. $item['status_tab'] = '未开始';
  1170. } elseif($item['start_time'] <= $now && $item['end_time'] > $now) {
  1171. $item['status_tab'] = '进行中';
  1172. } elseif($item['end_time'] <= $now) {
  1173. $item['status_tab'] = '已结束';
  1174. } else {
  1175. $item['status_tab'] = '未知';
  1176. }
  1177. }
  1178. $count = count($list);
  1179. $data = array_slice($list, (get_params('pageNo') - 1) * ($get_params['pageSize']?:10), $get_params['pageSize']?:10);
  1180. return $this->asJson([
  1181. 'code' => 0,
  1182. 'msg' => 'success',
  1183. 'data' => [
  1184. 'data' => $data,
  1185. 'pageNo' => intval(get_params('pageNo')),
  1186. 'totalCount' => $count,
  1187. ]
  1188. ]);
  1189. }
  1190. /**
  1191. * 模块名:event-edit
  1192. * 代码描述:新增/编辑活动
  1193. * 作者:WPing丶
  1194. * 请求方式:GET
  1195. * 创建时间:2025/07/12 16:28:22
  1196. * @param int id 编辑记录ID
  1197. * @param string name 活动名称
  1198. * @param string address 活动地址
  1199. * @param string date_array 活动时间
  1200. * @param string attendance 活动人数限制(每个公司/机构最多参会人数)
  1201. * @param string company_form_apply 公司申请表单(自定义)
  1202. * @param string institution_form_apply 机构申请表单(自定义)
  1203. * @param string cover_pic 封面图
  1204. */
  1205. public function actionEventEdit()
  1206. {
  1207. $post_params = post_params();
  1208. $store_id = get_store_id();
  1209. $transaction = Yii::$app->db->beginTransaction();
  1210. try {
  1211. $event = Event::findOne(['id' => $post_params['id'], 'is_delete' => 0, 'store_id' => $store_id]);
  1212. if (!$event) {
  1213. $event = new Event();
  1214. $event->store_id = $store_id;
  1215. }
  1216. $event->name = $post_params['name'];
  1217. $event->address = $post_params['address'];
  1218. if (!empty($post_params['date_array'])) {
  1219. list($start, $end) = explode(',', $post_params['date_array']);
  1220. $event->start_time = strtotime($start);
  1221. $event->end_time = strtotime($end);
  1222. }
  1223. $event->attendance = $post_params['attendance'];
  1224. $event->cover_pic = $post_params['cover_pic'];
  1225. if (!$event->save()) {
  1226. throw new \Exception('保存活动失败: ' . json_encode($event->errors, JSON_UNESCAPED_UNICODE));
  1227. }
  1228. // ===================== 公司表单处理 =====================
  1229. $company_form_apply = json_decode($post_params['company_form_apply'], true)['list'] ?? [];
  1230. // if (!empty($company_form_apply)) {
  1231. $company_form_json = json_encode($company_form_apply, JSON_UNESCAPED_UNICODE);
  1232. if($company_form_json != $event->company_form) {
  1233. Event::updateAll(['company_form' => $company_form_json], ['id' => $event->id]);
  1234. EventForm::updateAll(['is_delete' => 1], [
  1235. 'store_id' => $store_id,
  1236. 'event_id' => $event->id,
  1237. 'form_type' => EventForm::FORM_TYPE_COMPANY,
  1238. ]);
  1239. foreach ($company_form_apply as $key => $item) {
  1240. $event_form = new EventForm();
  1241. $event_form->store_id = $store_id;
  1242. $event_form->event_id = $event->id;
  1243. $event_form->form_type = EventForm::FORM_TYPE_COMPANY;
  1244. $event_form->name = $item['name'];
  1245. $event_form->type = $item['type'];
  1246. $event_form->required = $item['required'] ? EventForm::IS_REQUIRED_TRUE : EventForm::IS_REQUIRED_FALSE;
  1247. $event_form->default = $item['default'] ?? '';
  1248. $event_form->tip = $item['tip'] ?? '';
  1249. $event_form->sort = $key;
  1250. if (!$event_form->save()) {
  1251. throw new \Exception('保存公司自定义表单失败: ' . json_encode($event_form->errors, JSON_UNESCAPED_UNICODE));
  1252. }
  1253. }
  1254. }
  1255. // }
  1256. // ===================== 机构表单处理 =====================
  1257. $institution_form_apply = json_decode($post_params['institution_form_apply'], true)['list'] ?? [];
  1258. // if (!empty($institution_form_apply)) {
  1259. $institution_form_json = json_encode($institution_form_apply, JSON_UNESCAPED_UNICODE);
  1260. if($institution_form_json != $event->institution_form) {
  1261. Event::updateAll(['institution_form' => $institution_form_json], ['id' => $event->id]);
  1262. EventForm::updateAll(['is_delete' => 1], [
  1263. 'store_id' => $store_id,
  1264. 'event_id' => $event->id,
  1265. 'form_type' => EventForm::FORM_TYPE_INSTITUTION,
  1266. ]);
  1267. foreach ($institution_form_apply as $key => $item) {
  1268. $event_form = new EventForm();
  1269. $event_form->store_id = $store_id;
  1270. $event_form->event_id = $event->id;
  1271. $event_form->form_type = EventForm::FORM_TYPE_INSTITUTION;
  1272. $event_form->name = $item['name'];
  1273. $event_form->type = $item['type'];
  1274. $event_form->required = $item['required'] ? EventForm::IS_REQUIRED_TRUE : EventForm::IS_REQUIRED_FALSE;
  1275. $event_form->default = $item['default'] ?? '';
  1276. $event_form->tip = $item['tip'] ?? '';
  1277. $event_form->sort = $key;
  1278. if (!$event_form->save()) {
  1279. throw new \Exception('保存机构自定义表单失败: ' . json_encode($event_form->errors, JSON_UNESCAPED_UNICODE));
  1280. }
  1281. }
  1282. }
  1283. // }
  1284. // ===================== 提交事务 =====================
  1285. $transaction->commit();
  1286. return $this->asJson([
  1287. 'code' => 0,
  1288. 'msg' => '操作成功',
  1289. ]);
  1290. } catch (\Exception $e) {
  1291. $transaction->rollBack();
  1292. return $this->asJson([
  1293. 'code' => 1,
  1294. 'msg' => '操作失败',
  1295. 'error' => $e->getMessage()
  1296. ]);
  1297. }
  1298. }
  1299. /**
  1300. * 模块名:event-del
  1301. * 代码描述:删除活动
  1302. * 作者:WPing丶
  1303. * 请求方式:GET
  1304. * 创建时间:2025/07/13 17:12:29
  1305. * @param array key 活动ID数组,兼容批量删除
  1306. */
  1307. public function actionEventDel()
  1308. {
  1309. $ids = get_params('key');
  1310. $store_id = get_store_id();
  1311. if (empty($ids) || !is_array($ids)) {
  1312. return $this->asJson([
  1313. 'code' => 1,
  1314. 'msg' => '缺少删除的活动ID',
  1315. ]);
  1316. }
  1317. $transaction = Yii::$app->db->beginTransaction();
  1318. try {
  1319. foreach ($ids as $id) {
  1320. $event = Event::find()
  1321. ->where(['id' => $id, 'store_id' => $store_id, 'is_delete' => 0])
  1322. ->one();
  1323. if (!$event) {
  1324. throw new \Exception("活动 ID【{$id}】不存在或已删除");
  1325. }
  1326. // 删除关联数据(软删除)
  1327. EventUser::updateAll(['is_delete' => 1], ['event_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
  1328. EventForm::updateAll(['is_delete' => 1], ['event_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
  1329. EventFormDetail::updateAll(['is_delete' => 1], ['event_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
  1330. // 删除主表记录
  1331. $event->is_delete = 1;
  1332. if (!$event->save()) {
  1333. throw new \Exception("活动 ID【{$id}】删除失败");
  1334. }
  1335. }
  1336. $transaction->commit();
  1337. debug_log('批量删除活动,event_id集合=【' . implode(',', $ids) . '】,并删除所有关联数据', 'event.log');
  1338. return $this->asJson([
  1339. 'code' => 0,
  1340. 'msg' => '删除成功',
  1341. ]);
  1342. } catch (\Exception $e) {
  1343. $transaction->rollBack();
  1344. return $this->asJson([
  1345. 'code' => 1,
  1346. 'msg' => '删除失败:' . $e->getMessage(),
  1347. ]);
  1348. }
  1349. }
  1350. /**
  1351. * 模块名: event-user-audit-list
  1352. * 代码描述: 活动报名审核列表
  1353. * 作者: WPing丶
  1354. * 请求方式: GET
  1355. * 创建时间:2025/07/14 09:06:39
  1356. * @param string company_name 公司名称
  1357. * @param string phone 手机号
  1358. * @param string real_name 真实姓名
  1359. * @param int event_id 活动ID
  1360. * @param string status 状态:all、wait(待审核)、pass(已通过)、refuse(已拒绝)
  1361. * @param int page
  1362. * @param int limit
  1363. */
  1364. public function actionEventUserAuditList()
  1365. {
  1366. $store_id = get_store_id();
  1367. $company_name = get_params('company_name');
  1368. $phone = get_params('phone');
  1369. $real_name = get_params('real_name');
  1370. $event_id = (int)get_params('event_id');
  1371. $status = get_params('status', 'all');
  1372. $page = (int)get_params('page', 1);
  1373. $limit = (int)get_params('limit', 10);
  1374. $query = EventUser::find()->alias('eu')
  1375. ->leftJoin(['e' => Event::tableName()], 'e.id = eu.event_id')
  1376. ->where(['eu.is_delete' => 0, 'e.is_delete' => 0, 'e.store_id' => $store_id]);
  1377. if ($company_name) {
  1378. $query->andWhere(['like', 'eu.company_name', $company_name]);
  1379. }
  1380. if ($phone) {
  1381. $query->andWhere(['like', 'eu.phone', $phone]);
  1382. }
  1383. if ($real_name) {
  1384. $query->andWhere(['like', 'eu.real_name', $real_name]);
  1385. }
  1386. if ($event_id) {
  1387. $query->andWhere(['eu.event_id' => $event_id]);
  1388. }
  1389. if ($status === 'wait') {
  1390. $query->andWhere(['eu.apply_status' => 0]);
  1391. } elseif ($status === 'pass') {
  1392. $query->andWhere(['eu.apply_status' => 1]);
  1393. } elseif ($status === 'refuse') {
  1394. $query->andWhere(['eu.apply_status' => 2]);
  1395. }
  1396. $count = $query->count();
  1397. $pagination = new Pagination([
  1398. 'totalCount' => $count,
  1399. 'pageSize' => $limit,
  1400. 'page' => $page - 1
  1401. ]);
  1402. $list = $query
  1403. ->select([
  1404. 'eu.id',
  1405. 'eu.event_id',
  1406. 'eu.company_code',
  1407. 'eu.company_name',
  1408. 'eu.company_address',
  1409. 'eu.real_name',
  1410. 'eu.phone',
  1411. 'eu.identity_card',
  1412. 'eu.hotel',
  1413. 'eu.restaurant',
  1414. 'eu.itinerary',
  1415. 'eu.created_at',
  1416. 'eu.apply_status',
  1417. 'eu.user_id',
  1418. 'eu.form_type',
  1419. 'e.name as event_name',
  1420. ])
  1421. ->orderBy('eu.created_at DESC')
  1422. ->offset($pagination->offset)
  1423. ->limit($pagination->limit)
  1424. ->asArray()
  1425. ->all();
  1426. foreach ($list as &$item) {
  1427. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  1428. $item['avatar_url'] = User::findOne($item['user_id'])->avatar_url;
  1429. $item['nickname'] = User::findOne($item['user_id'])->nickname;
  1430. $item['form_type'] = (int)$item['form_type'];
  1431. // 酒店、用餐、行程转数组
  1432. $item['hotel'] = $item['hotel'] ? json_decode($item['hotel'], true) : [];
  1433. $item['restaurant'] = $item['restaurant'] ? json_decode($item['restaurant'], true) : [];
  1434. $item['itinerary'] = $item['itinerary'] ? json_decode($item['itinerary'], true) : [];
  1435. // 报名详情自定义表单
  1436. $formDetails = EventFormDetail::find()
  1437. ->where([
  1438. 'event_user_id' => $item['id'],
  1439. 'is_delete' => 0
  1440. ])
  1441. ->asArray()
  1442. ->all();
  1443. $form_data = [];
  1444. foreach ($formDetails as $fd) {
  1445. $form_data[] = [
  1446. 'name' => $fd['key'],
  1447. 'value' => $fd['value'],
  1448. 'type' => $fd['type'],
  1449. ];
  1450. }
  1451. $item['form_detail'] = $form_data;
  1452. }
  1453. // 活动下拉列表(不分页)
  1454. $eventList = Event::find()
  1455. ->where(['is_delete' => 0, 'store_id' => $store_id])
  1456. ->select(['id', 'name'])
  1457. ->orderBy('id DESC')
  1458. ->asArray()
  1459. ->all();
  1460. return $this->asJson([
  1461. 'code' => 0,
  1462. 'msg' => 'success',
  1463. 'data' => [
  1464. 'row_count' => $count,
  1465. 'page_count' => $pagination->pageCount,
  1466. 'list' => $list,
  1467. 'event_list' => $eventList
  1468. ]
  1469. ]);
  1470. }
  1471. /**
  1472. * 模块名: event-user-review
  1473. * 代码描述: 活动报名审核操作
  1474. * 作者: WPing丶
  1475. * 请求方式: POST
  1476. * 创建时间: 2025/07/15 18:06:07
  1477. *
  1478. * @param int id 报名记录ID
  1479. * @param int apply_status 审核状态(1=通过;2=拒绝)
  1480. * @param string reason_refusal 拒绝原因(可选,仅拒绝时必填)
  1481. */
  1482. public function actionEventUserReview()
  1483. {
  1484. $id = (int)post_params('id');
  1485. $apply_status = (int)post_params('apply_status');
  1486. $reason_refusal = trim(post_params('reason_refusal', ''));
  1487. if (!$id || !in_array($apply_status, [1, 2])) {
  1488. return $this->asJson(['code' => 1, 'msg' => '参数错误']);
  1489. }
  1490. if ($apply_status === 2 && !$reason_refusal) {
  1491. return $this->asJson(['code' => 1, 'msg' => '拒绝原因不能为空']);
  1492. }
  1493. $eventUser = EventUser::findOne(['id' => $id, 'is_delete' => 0]);
  1494. if (!$eventUser) {
  1495. return $this->asJson(['code' => 1, 'msg' => '报名记录不存在']);
  1496. }
  1497. // 如果已经审核过,则不再允许重复审核
  1498. if (in_array($eventUser->apply_status, [1, 2])) {
  1499. return $this->asJson(['code' => 1, 'msg' => '该记录已审核,请勿重复操作']);
  1500. }
  1501. $eventUser->apply_status = $apply_status;
  1502. $eventUser->apply_time = time();
  1503. $eventUser->reason_refusal = ($apply_status === 2) ? $reason_refusal : null;
  1504. if (!$eventUser->save()) {
  1505. return $this->asJson(['code' => 1, 'msg' => '审核失败,请重试']);
  1506. }
  1507. return $this->asJson(['code' => 0, 'msg' => '审核成功']);
  1508. }
  1509. /**
  1510. * 模块名: event-user-save
  1511. * 代码描述: 新增或编辑报名记录
  1512. * 作者: WPing丶
  1513. * 请求方式: POST
  1514. * 创建时间: 2025/07/15 20:05:51
  1515. *
  1516. * @param int id 可选,编辑时填写event_user表的主键ID
  1517. * @param int event_id 活动ID
  1518. * @param int user_id 用户ID
  1519. * @param int form_type 表单类型(1=企业,2=机构)
  1520. * @param string company_name 企业名称
  1521. * @param string company_code 统一社会信息代码
  1522. * @param string company_address 企业地址
  1523. * @param string real_name 真实姓名
  1524. * @param string phone 电话
  1525. * @param string identity_card 身份证号
  1526. * @param array form_data 自定义表单,格式:["字段名" => "值"]
  1527. * @param array hotel 酒店信息
  1528. * @param array restaurant 餐厅信息
  1529. * @param array itinerary 行程信息
  1530. */
  1531. public function actionEventUserSave()
  1532. {
  1533. $store_id = get_store_id();
  1534. $id = (int)post_params('id');
  1535. $user_id = (int)post_params('user_id', 0);
  1536. $event_id = (int)post_params('event_id');
  1537. $form_type = (int)post_params('form_type', 1);
  1538. $company_name = post_params('company_name');
  1539. $company_code = post_params('company_code');
  1540. $company_address = post_params('company_address');
  1541. $real_name = post_params('real_name');
  1542. $phone = post_params('phone');
  1543. $identity_card = post_params('identity_card');
  1544. $form_data = post_params('form_data', []);
  1545. $hotel = post_params('hotel', []);
  1546. $restaurant = post_params('restaurant', []);
  1547. $itinerary = post_params('itinerary', []);
  1548. if (!$event_id || !$company_name || !$real_name || !$phone || !$identity_card || !$company_address || !$form_type || !$company_code) {
  1549. return $this->asJson(['code' => 1, 'msg' => '参数不完整']);
  1550. }
  1551. $event = Event::findOne(['id' => $event_id, 'store_id' => $store_id, 'is_delete' => 0]);
  1552. if (!$event) {
  1553. return $this->asJson(['code' => 1, 'msg' => '活动不存在']);
  1554. }
  1555. if ($event->end_time < time()) {
  1556. return $this->asJson(['code' => 1, 'msg' => '活动报名已结束无法报名']);
  1557. }
  1558. // 查询表单结构
  1559. $formList = EventForm::find()
  1560. ->where([
  1561. 'event_id' => $event_id,
  1562. 'form_type' => $form_type,
  1563. 'is_delete' => 0
  1564. ])->asArray()->all();
  1565. $formMap = [];
  1566. foreach ($formList as $formItem) {
  1567. $formMap[$formItem['name']] = $formItem['type'] ?? 'text';
  1568. }
  1569. $transaction = Yii::$app->db->beginTransaction();
  1570. try {
  1571. if ($id) {
  1572. /* 编辑记录时,不允许修改活动ID 和 UserID */
  1573. $eventUser = EventUser::findOne(['id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
  1574. if (!$eventUser) {
  1575. return $this->asJson(['code' => 1, 'msg' => '报名记录不存在']);
  1576. }
  1577. } else {
  1578. if($user_id > 0) {//2025年7月25日10:47:48 如果用户ID存在的情况下判断是否报过名
  1579. $exist = EventUser::find()->where(['event_id' => $event_id, 'user_id' => $user_id, 'store_id' => $store_id, 'is_delete' => 0])->exists();
  1580. if ($exist) {
  1581. return $this->asJson(['code' => 1, 'msg' => '此用户已报名过当前活动,请勿重复报名']);
  1582. }
  1583. } else {
  1584. $exist = EventUser::find()->where(['event_id' => $event_id, 'phone' => $phone, 'store_id' => $store_id, 'is_delete' => 0])->exists();
  1585. if ($exist) {
  1586. return $this->asJson(['code' => 1, 'msg' => '此手机号已报名过当前活动,请勿重复报名']);
  1587. }
  1588. }
  1589. $eventUser = new EventUser();
  1590. $eventUser->store_id = $store_id;
  1591. $eventUser->user_id = $user_id;
  1592. $eventUser->event_id = $event_id;
  1593. }
  1594. $eventUser->company_name = $company_name;
  1595. $eventUser->company_code = $company_code;
  1596. $eventUser->company_address = $company_address;
  1597. $eventUser->real_name = $real_name;
  1598. $eventUser->phone = $phone;
  1599. $eventUser->identity_card = $identity_card;
  1600. $eventUser->apply_status = 1;
  1601. $eventUser->hotel = $hotel ? json_encode($hotel, JSON_UNESCAPED_UNICODE) : '{"title":"","data":[]}';
  1602. $eventUser->restaurant = $restaurant ? json_encode($restaurant, JSON_UNESCAPED_UNICODE) : '{"title":"","data":[]}';
  1603. $eventUser->itinerary = $itinerary ? json_encode($itinerary, JSON_UNESCAPED_UNICODE) : '{"title":"","data":[]}';
  1604. $eventUser->form_type = $form_type;
  1605. if (!$eventUser->save()) {
  1606. throw new \Exception('保存报名信息失败');
  1607. }
  1608. // 先清除旧的表单数据
  1609. EventFormDetail::updateAll(['is_delete' => 1], [
  1610. 'event_user_id' => $eventUser->id,
  1611. 'is_delete' => 0,
  1612. ]);
  1613. // 插入新的表单数据
  1614. foreach ($form_data as $key => $value) {
  1615. if (!isset($formMap[$key])) continue;
  1616. $detail = new EventFormDetail();
  1617. $detail->store_id = $store_id;
  1618. $detail->user_id = $user_id;
  1619. $detail->event_id = $event_id;
  1620. $detail->event_user_id = $eventUser->id;
  1621. $detail->form_type = $form_type;
  1622. $detail->key = $key;
  1623. $detail->value = $value;
  1624. $detail->type = $formMap[$key];
  1625. $detail->is_delete = 0;
  1626. $detail->save();
  1627. }
  1628. $transaction->commit();
  1629. return $this->asJson(['code' => 0, 'msg' => '保存成功']);
  1630. } catch (\Exception $e) {
  1631. $transaction->rollBack();
  1632. return $this->asJson(['code' => 1, 'msg' => $e->getMessage()]);
  1633. }
  1634. }
  1635. /**
  1636. * 模块名:event-form-list
  1637. * 接口功能: 获取指定活动的自定义表单结构
  1638. * 请求方式: GET
  1639. * 作者: WPing丶
  1640. * 时间: 2025-07-15 19:35:51
  1641. * @param int $event_id 活动ID
  1642. * @param int $user_id 用户ID
  1643. * @param int $form_type 表单类型:1=企业;2=机构;
  1644. */
  1645. public function actionEventFormList()
  1646. {
  1647. $store_id = get_store_id();
  1648. $event_id = (int)get_params('event_id');
  1649. $user_id = (int)get_params('user_id');
  1650. $form_type = (int)get_params('form_type');
  1651. if (!$event_id) {
  1652. return $this->asJson(['code' => 1, 'msg' => '活动ID不能为空']);
  1653. }
  1654. // 查询活动是否存在
  1655. $event = Event::find()
  1656. ->where([
  1657. 'id' => $event_id,
  1658. 'store_id' => $store_id,
  1659. 'is_delete' => 0,
  1660. ])
  1661. ->one();
  1662. if (!$event) {
  1663. return $this->asJson(['code' => 1, 'msg' => '活动不存在']);
  1664. }
  1665. if ($event->end_time <= time()) {
  1666. return $this->asJson(['code' => 1, 'msg' => '活动已经结束无法报名']);
  1667. }
  1668. // 查询该活动所有表单结构
  1669. $form_list = EventForm::find()
  1670. ->where([
  1671. 'event_id' => $event_id,
  1672. 'form_type' => $form_type,
  1673. 'is_delete' => 0
  1674. ])
  1675. ->orderBy('sort ASC')
  1676. ->asArray()
  1677. ->all();
  1678. // 将表单按 form_type 进行分组(1=企业,2=机构)
  1679. $form_group = [];
  1680. foreach ($form_list as &$item) {
  1681. if($user_id > 0) {//2025年7月25日11:45:43 修改兼容没有user_id的情况
  1682. $item['value'] = EventFormDetail::findOne(['user_id' => $user_id, 'event_id' => $event_id, 'key' => $item['name']])->value ?: '';
  1683. }
  1684. $form_group[] = $item;
  1685. }
  1686. return $this->asJson([
  1687. 'code' => 0,
  1688. 'msg' => 'success',
  1689. 'data' => [
  1690. 'event_id' => $event_id,
  1691. 'form' => $form_group
  1692. ]
  1693. ]);
  1694. }
  1695. /**
  1696. * 模块名:sign-staff-list
  1697. * 代码描述:签到员列表
  1698. * 作者:WPing丶
  1699. * 请求方式:GET
  1700. * 创建时间:2025/07/16 11:07:26
  1701. * @param string name 姓名
  1702. * @param string mobile 手机号
  1703. * @param int page
  1704. * @param int limit
  1705. */
  1706. public function actionSignStaffList()
  1707. {
  1708. $store_id = get_store_id();
  1709. $name = get_params('name');
  1710. $mobile = get_params('mobile');
  1711. $page = (int)get_params('page', 1);
  1712. $limit = (int)get_params('limit', 10);
  1713. $query = EventSignStaff::find()->alias('es')
  1714. ->leftJoin(['u' => User::tableName()], 'u.id = es.user_id')
  1715. ->where(['es.store_id' => $store_id, 'es.is_delete' => 0]);
  1716. if($name) {
  1717. $query->andWhere(['like','name',$name]);
  1718. }
  1719. if($mobile) {
  1720. $query->andWhere(['like','mobile',$mobile]);
  1721. }
  1722. $count = $query->count();
  1723. $pagination = new Pagination([
  1724. 'totalCount' => $count,
  1725. 'pageSize' => $limit,
  1726. 'page' => $page - 1
  1727. ]);
  1728. $list = $query
  1729. ->select(['es.id', 'es.user_id', 'es.name', 'es.mobile', 'u.avatar_url'])
  1730. ->orderBy('es.created_at DESC')
  1731. ->offset($pagination->offset)
  1732. ->limit($pagination->limit)
  1733. ->asArray()
  1734. ->all();
  1735. return $this->asJson([
  1736. 'code' => 0,
  1737. 'msg' => 'success',
  1738. 'data' => [
  1739. 'row_count' => $count,
  1740. 'page_count' => $pagination->pageCount,
  1741. 'list' => $list
  1742. ]
  1743. ]);
  1744. }
  1745. /**
  1746. * 模块名:add-sign-staff
  1747. * 代码描述:添加签到员
  1748. * 作者:WPing丶
  1749. * 请求方式:GET
  1750. * 创建时间:2025/07/16 10:55:27
  1751. * @param int user_id
  1752. * @param string mobile 手机号
  1753. * @param string name 签到员姓名
  1754. */
  1755. public function actionAddSignStaff()
  1756. {
  1757. $store_id = get_store_id();
  1758. $user_id = (int)post_params('user_id');
  1759. $mobile = post_params('mobile');
  1760. $name = post_params('name');
  1761. if (!$user_id) {
  1762. return $this->asJson(['code' => 1, 'msg' => '参数错误']);
  1763. }
  1764. $exists = EventSignStaff::findOne(['user_id' => $user_id, 'is_delete' => 0]);
  1765. if ($exists) {
  1766. return $this->asJson(['code' => 1, 'msg' => '该用户已是签到员']);
  1767. }
  1768. $staff = new EventSignStaff();
  1769. $staff->store_id = $store_id;
  1770. $staff->user_id = $user_id;
  1771. $staff->mobile = $mobile;
  1772. $staff->name = $name;
  1773. $staff->created_at = time();
  1774. $staff->updated_at = time();
  1775. $staff->is_delete = 0;
  1776. if ($staff->save()) {
  1777. return $this->asJson(['code' => 0, 'msg' => '添加成功']);
  1778. }
  1779. return $this->asJson(['code' => 1, 'msg' => '添加失败']);
  1780. }
  1781. /**
  1782. * 模块名:del-sign-staff
  1783. * 代码描述:删除签到员
  1784. * 作者:WPing丶
  1785. * 请求方式:POST
  1786. * 创建时间:2025/07/16 11:24:19
  1787. * @param int user_id
  1788. */
  1789. public function actionDelSignStaff()
  1790. {
  1791. $user_id = (int)post_params('user_id');
  1792. if (!$user_id) {
  1793. return $this->asJson(['code' => 1, 'msg' => '参数错误']);
  1794. }
  1795. $staff = EventSignStaff::findOne(['user_id' => $user_id, 'is_delete' => 0]);
  1796. if (!$staff) {
  1797. return $this->asJson(['code' => 1, 'msg' => '签到员不存在']);
  1798. }
  1799. $staff->is_delete = 1;
  1800. $staff->updated_at = time();
  1801. $staff->save();
  1802. return $this->asJson(['code' => 0, 'msg' => '删除成功']);
  1803. }
  1804. /**
  1805. * 模块名:export-event-user
  1806. * 代码描述:活动导出核心逻辑
  1807. * 作者:WPing丶
  1808. * 请求方式:GET
  1809. * 创建时间:2025/07/16 09:22:05
  1810. * @param int event_id 活动ID
  1811. */
  1812. public function actionExportEventUser()
  1813. {
  1814. $store_id = get_store_id();
  1815. $event_id = (int)get_params('event_id');
  1816. if (!$event_id) {
  1817. return $this->asJson(['code' => 1, 'msg' => '缺少活动ID']);
  1818. }
  1819. // 获取活动
  1820. $event = Event::findOne([
  1821. 'id' => $event_id,
  1822. 'store_id' => $store_id,
  1823. 'is_delete' => 0
  1824. ]);
  1825. if (!$event) {
  1826. return $this->asJson(['code' => 1, 'msg' => '活动不存在']);
  1827. }
  1828. // 获取所有报名用户
  1829. $users = EventUser::find()
  1830. ->where([
  1831. 'event_id' => $event_id,
  1832. 'store_id' => $store_id,
  1833. 'is_delete' => 0
  1834. ])
  1835. ->orderBy(['company_code' => SORT_ASC])
  1836. ->asArray()
  1837. ->all();
  1838. $user_ids = array_column($users, 'id');
  1839. // 获取所有自定义字段(按顺序)
  1840. $fields = EventForm::find()
  1841. ->where([
  1842. 'event_id' => $event_id,
  1843. 'is_delete' => 0
  1844. ])
  1845. ->orderBy('sort ASC')
  1846. ->select('name')
  1847. ->column(); // 自定义字段的字段名数组(表头用)
  1848. // 获取所有表单填写内容
  1849. $details = EventFormDetail::find()
  1850. ->where([
  1851. 'event_id' => $event_id,
  1852. 'store_id' => $store_id,
  1853. 'is_delete' => 0,
  1854. 'event_user_id' => $user_ids
  1855. ])
  1856. ->asArray()
  1857. ->all();
  1858. $detail_map = []; // [event_user_id][key] => value
  1859. foreach ($details as $d) {
  1860. $detail_map[$d['event_user_id']][$d['key']] = $d['value'];
  1861. }
  1862. // ===== 动态构造导出表头 =====
  1863. $head = [
  1864. 'ID',
  1865. '是否到场',
  1866. '报名时间',
  1867. '签到时间',
  1868. '公司名称',
  1869. '公司地址',
  1870. '统一社会信息代码',
  1871. '参会人姓名',
  1872. '身份证号',
  1873. '电话',
  1874. ];
  1875. $head = array_merge($head, $fields); // 合并自定义字段
  1876. $rows = [$head];
  1877. // ===== 统计用变量 =====
  1878. $current_code = '';
  1879. $company_total = 0;
  1880. $company_arrived = 0;
  1881. $global_total = 0;
  1882. $global_arrived = 0;
  1883. $company_count = 0;
  1884. foreach ($users as $index => $u) {
  1885. $global_total++;
  1886. if ($u['sign_time']) $global_arrived++;
  1887. // 判断是否是新公司
  1888. if ($u['company_code'] !== $current_code) {
  1889. if ($current_code) {
  1890. // 输出上一家公司小计行
  1891. $rows[] = [
  1892. '', '', '', '', "【{$current_code}】公司小计:共 {$company_total} 人,到场 {$company_arrived} 人"
  1893. ];
  1894. }
  1895. // 初始化当前公司统计
  1896. $current_code = $u['company_code'];
  1897. $company_total = 0;
  1898. $company_arrived = 0;
  1899. $company_count++;
  1900. }
  1901. $company_total++;
  1902. if ($u['sign_time']) $company_arrived++;
  1903. $row = [
  1904. $u['id'],
  1905. $u['sign_time'] > 0 ? '是' : '否',
  1906. $u['created_at'] ? date('Y-m-d H:i:s', $u['created_at']) : '/',
  1907. $u['sign_time'] ? date('Y-m-d H:i:s', $u['sign_time']) : '/',
  1908. $u['company_name'],
  1909. $u['company_address'],
  1910. $u['company_code'],
  1911. $u['real_name'],
  1912. $u['identity_card'],
  1913. $u['phone'],
  1914. ];
  1915. // 拼接自定义字段部分
  1916. foreach ($fields as $f) {
  1917. $row[] = $detail_map[$u['id']][$f] ?? '';
  1918. }
  1919. $rows[] = $row;
  1920. }
  1921. // 最后一个公司小计
  1922. if ($current_code) {
  1923. $rows[] = [
  1924. '', '', '', '', "【{$current_code}】公司小计:共 {$company_total} 人,到场 {$company_arrived} 人"
  1925. ];
  1926. }
  1927. // 全部汇总
  1928. $rows[] = [
  1929. '', '', '', '', "全部报名统计:共 {$global_total} 人,到场 {$global_arrived} 人,参与公司数量:{$company_count}"
  1930. ];
  1931. return $this->exportExcel($rows);
  1932. }
  1933. /**
  1934. * 模块名:export-excel
  1935. * 代码描述:导出相关请求
  1936. * 作者:WPing丶
  1937. * 创建时间:2025/07/16 09:23:36
  1938. * @param int rows
  1939. */
  1940. private function exportExcel($rows)
  1941. {
  1942. \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload('event_export_' . date('Ymd_His') . '.xlsx')
  1943. ->noHeaderRow()
  1944. ->addRows($rows)
  1945. ->toBrowser();
  1946. }
  1947. /**
  1948. * 获取轮播图配置
  1949. * 模块名:event-setting-banner
  1950. * 方法名:actionGetEventBanner
  1951. * 请求方式:GET
  1952. */
  1953. public function actionGetEventBanner()
  1954. {
  1955. $store_id = get_store_id();
  1956. $setting = EventSetting::findOne([
  1957. 'store_id' => $store_id,
  1958. 'is_delete' => 0
  1959. ]);
  1960. if (!$setting || empty($setting->banner)) {
  1961. return $this->asJson([
  1962. 'code' => 0,
  1963. 'msg' => 'success',
  1964. 'data' => []
  1965. ]);
  1966. }
  1967. $banner = json_decode($setting->banner, true);
  1968. return $this->asJson([
  1969. 'code' => 0,
  1970. 'msg' => 'success',
  1971. 'data' => $banner
  1972. ]);
  1973. }
  1974. /**
  1975. * 保存轮播图配置
  1976. * 模块名:save-event-banner
  1977. * 方法名:actionSaveEventBanner
  1978. * 请求方式:POST
  1979. * 参数:banner(轮播图数组)
  1980. */
  1981. public function actionSaveEventBanner()
  1982. {
  1983. $store_id = get_store_id();
  1984. $banner = post_params('banner', []);
  1985. if (!is_array($banner)) {
  1986. return $this->asJson(['code' => 1, 'msg' => '参数格式错误,必须是数组']);
  1987. }
  1988. // 转为 JSON 字符串
  1989. $banner_json = json_encode($banner, JSON_UNESCAPED_SLASHES);
  1990. // 查询配置记录
  1991. $setting = EventSetting::findOne([
  1992. 'store_id' => $store_id,
  1993. 'is_delete' => 0
  1994. ]);
  1995. if (!$setting) {
  1996. // 如果不存在则新建一条记录
  1997. $setting = new EventSetting();
  1998. $setting->store_id = $store_id;
  1999. $setting->created_at = time();
  2000. $setting->is_delete = 0;
  2001. }
  2002. // 保存轮播图字段
  2003. $setting->banner = $banner_json;
  2004. $setting->updated_at = time();
  2005. if ($setting->save()) {
  2006. return $this->asJson(['code' => 0, 'msg' => '保存成功']);
  2007. } else {
  2008. return $this->asJson(['code' => 1, 'msg' => '保存失败,请重试']);
  2009. }
  2010. }
  2011. /**
  2012. * 模块名:del-sign-staff
  2013. * 代码描述:删除审核记录
  2014. * 作者:WPing丶
  2015. * 请求方式:POST
  2016. * 创建时间:2025/07/16 11:24:19
  2017. * @param int ids
  2018. */
  2019. public function actionDelEventUser()
  2020. {
  2021. $ids = get_params('ids');
  2022. $store_id = get_store_id();
  2023. if (empty($ids) || !is_array($ids)) {
  2024. return $this->asJson([
  2025. 'code' => 1,
  2026. 'msg' => '缺少删除的活动ID',
  2027. ]);
  2028. }
  2029. $transaction = Yii::$app->db->beginTransaction();
  2030. try {
  2031. foreach ($ids as $id) {
  2032. $eventUser = EventUser::find()
  2033. ->where(['id' => $id, 'store_id' => $store_id, 'is_delete' => 0])
  2034. ->one();
  2035. if (!$eventUser) {
  2036. throw new \Exception("记录 ID【{$id}】不存在或已删除");
  2037. }
  2038. // 删除关联数据(软删除)
  2039. EventFormDetail::updateAll(['is_delete' => 1], ['event_user_id' => $id, 'store_id' => $store_id, 'is_delete' => 0]);
  2040. // 删除主表记录
  2041. $eventUser->is_delete = 1;
  2042. if (!$eventUser->save()) {
  2043. throw new \Exception("记录 ID【{$id}】删除失败");
  2044. }
  2045. }
  2046. $transaction->commit();
  2047. debug_log('批量删除活动,event_user_id集合=【' . implode(',', $ids) . '】,并删除所有关联数据', 'event.log');
  2048. return $this->asJson([
  2049. 'code' => 0,
  2050. 'msg' => '删除成功',
  2051. ]);
  2052. } catch (\Exception $e) {
  2053. $transaction->rollBack();
  2054. return $this->asJson([
  2055. 'code' => 1,
  2056. 'msg' => '删除失败:' . $e->getMessage(),
  2057. ]);
  2058. }
  2059. }
  2060. /* end */
  2061. }