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 */ }