| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070 |
- <?php
- /**
- * 初始化逻辑类
- *
- * @author qifan
- * @date 2020-01-05
- */
-
- namespace app\admin\logic;
-
- use app\admin\controller\UpdateSql;
- use think\Db;
- use think\Exception;
-
- class InitializeLogic
- {
- public $log = '操作成功!';
-
- # 值为false时,终止其他方法的操作
- private $status = true;
-
- /**
- * 重置数据
- *
- * @param $param
- * @return bool
- */
- public function update($param)
- {
- # 设置脚本执行时间和内存
- ini_set('max_execution_time', 0);
- ini_set('memory_limit', '256M');
-
- # 重置单个或多个模块
- foreach ($param AS $key => $value) {
- if ($value == 'crm' && $this->status) $this->resetCustomerManagementData(); # 重置客户管理数据
- if ($value == 'taskExamine' && $this->status) $this->resetTaskExamineData(); # 重置任务/审批数据
- if ($value == 'log' && $this->status) $this->resetDailyRecordData(); # 重置日志数据
- if ($value == 'project' && $this->status) $this->resetProjectManagementData(); # 重置项目管理数据
- if ($value == 'calendar' && $this->status) $this->resetCalendarData(); # 重置日历数据
- }
-
- return true;
- }
-
- /**
- * 验证密码
- *
- * @param $userId
- * @param $password
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function verification($userId, $password)
- {
- $userInfo = Db::name('admin_user')->field(['password', 'salt'])->where('id', $userId)->find();
-
- return user_md5($password, $userInfo['salt']) == $userInfo['password'];
- }
-
- /**
- * 重置客户管理数据
- */
- private function resetCustomerManagementData()
- {
- # 表前缀
- $prefix = config('database.prefix');
-
- # 文件数组
- $files = [];
-
- # 启动事务
- Db::startTrans();
- try {
- # ------ 重置产品数据START ------ #
-
- # 获取产品附件ID
- $productFileIds = Db::name('crm_product_file')->column('file_id');
- # 查询产品文件数据
- $productFileInfo = $this->getFileList($productFileIds);
-
- # 获取产品图和产品详情图附件ID
- $productDetailsIds = [];
- $productDetailFiles = Db::name('crm_product')->field(['cover_images', 'details_images'])->select();
- foreach ($productDetailFiles AS $key => $value) {
- if (!empty($value['cover_images'])) $productDetailsIds = array_merge($productDetailsIds, explode(',', $value['cover_images']));
- if (!empty($value['details_images'])) $productDetailsIds = array_merge($productDetailsIds, explode(',', $value['details_images']));
- }
-
- # 合并附件ID数据
- $productFileIds = array_merge($productFileIds, $productDetailsIds);
-
- # 获取产品图和产品详情图文件数据
- $productDetailsFiles = $this->getFileList($productDetailsIds);
-
- # 合并附件数据
- $files = array_merge($files, $productDetailsFiles);
- $files = array_merge($files, $productFileInfo);
-
- # 删除产品分类表
- Db::name('crm_product_category')->where(['category_id' => ['neq', 1]])->delete();
- # 重置产品分类自增ID
- Db::query("ALTER TABLE ".$prefix."crm_product_category AUTO_INCREMENT = 1");
-
- # 清除产品附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_product_file");
-
- # 删除产品附件
- Db::name('admin_file')->whereIn('file_id', $productFileIds)->delete();
-
- # 清除产品表数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_product");
-
- # ------ 重置产品数据 END ------ #
-
-
- # ------ 重置回访数据 START ------ #
-
- # 获取回访附件ID
- $visitFileIds = Db::name('crm_visit_file')->column('file_id');
- # 查询回访文件数据
- $visitFileInfo = $this->getFileList($visitFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $visitFileInfo);
-
- # 清除回访附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_visit_file");
-
- # 删除回访附件
- Db::name('admin_file')->whereIn('file_id', $visitFileIds)->delete();
-
- # 清除回访表数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_visit");
-
- # ------ 重置回访数据 END ------ #
-
-
- # ------ 重置发票数据 START ------ #
-
- # 获取回访附件ID
- $invoiceFileIds = Db::name('crm_invoice_file')->column('file_id');
- # 查询回访文件数据
- $invoiceFileInfo = $this->getFileList($invoiceFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $invoiceFileInfo);
-
- # 清除发票附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_invoice_file");
-
- # 删除发票附件
- Db::name('admin_file')->whereIn('file_id', $invoiceFileIds)->delete();
-
- # 清除发票开户行信息数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_invoice_info");
-
- # 清除发票数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_invoice");
-
- # ------ 重置发票数据 END ------ #
-
-
- # ------ 重置回款数据 START ------ #
-
- # 获取回款附件ID
- $receivablesFileIds = Db::name('crm_receivables_file')->column('file_id');
- # 查询回访文件数据
- $receivablesFileInfo = $this->getFileList($receivablesFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $receivablesFileInfo);
-
- # 清除回款附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_receivables_file");
-
- # 删除回款附件
- Db::name('admin_file')->whereIn('file_id', $receivablesFileIds)->delete();
-
- # 清除回款计划数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_receivables_plan");
-
- # 清除回款数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_receivables");
-
- # ------ 重置回款数据 END ------ #
-
-
- # ------ 重置合同数据 START ------ #
-
- # 获取合同附件ID
- $contractFileIds = Db::name('crm_contract_file')->column('file_id');
- # 查询合同文件数据
- $contractFileInfo = $this->getFileList($contractFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $contractFileInfo);
-
- # 清除合同附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_contract_file");
-
- # 删除合同附件
- Db::name('admin_file')->whereIn('file_id', $contractFileIds)->delete();
-
- # 删除合同产品关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_contract_product");
-
- # 删除合同数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_contract");
-
- # ------ 重置合同数据 END ------ #
-
-
- # ------ 重置商机数据 START ------ #
-
- # 获取商机附件ID
- $businessFileIds = Db::name('crm_business_file')->column('file_id');
- # 查询商机文件数据
- $businessFileInfo = $this->getFileList($businessFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $businessFileInfo);
-
- # 清除商机附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_business_file");
-
- # 删除商机附件
- Db::name('admin_file')->whereIn('file_id', $businessFileIds)->delete();
-
- # 清除商机日志数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_business_log");
-
- # 清除商机产品关系数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_business_product");
-
- # 删除商机状态组类别数据
- Db::name('crm_business_type')->where(['type_id' => ['neq', 1]])->delete();
- # 重置商机状态组类别自增ID
- Db::query("ALTER TABLE ".$prefix."crm_business_type AUTO_INCREMENT = 1");
-
- # 删除商机状态数据
- Db::name('crm_business_status')->where(['type_id' => ['gt', 1]])->delete();
- # 重置商机状态自增ID
- Db::query("ALTER TABLE ".$prefix."crm_business_status AUTO_INCREMENT = 1");
-
- # 删除商机数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_business");
-
- # ------ 重置商机数据 END ------ #
-
-
- # ------ 重置联系人数据 START ------ #
-
- # 获取联系人附件ID
- $contactsFileIds = Db::name('crm_contacts_file')->column('file_id');
- # 查询联系人文件数据
- $contactsFileInfo = $this->getFileList($contactsFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $contactsFileInfo);
-
- # 清除联系人附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_contacts_file");
-
- # 删除联系人附件
- Db::name('admin_file')->whereIn('file_id', $contactsFileIds)->delete();
-
- # 清除联系人商机关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_contacts_business");
-
- # 清除联系人数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_contacts");
-
- # ------ 重置联系人数据 END ------ #
-
-
- # ------ 重置公海数据 START ------ #
-
- # 清除公海主数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_pool");
-
- # 清除公海字段数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_pool_field_setting");
-
- # 清除公海用户自定义字段样式数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_pool_field_style");
-
- # 清除公海操作记录数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_pool_record");
-
- # 清除公海关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_pool_relation");
-
- # 清除公海规则数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_pool_rule");
-
- # 添加公海默认数据
- UpdateSql::addPoolDefaultData();
-
- # ------ 重置公海数据 END ------ #
-
-
- # ------ 重置客户数据 START ------ #
-
- # 获取客户附件ID
- $customerFileIds = Db::name('crm_customer_file')->column('file_id');
- # 查询联系人文件数据
- $customerFileInfo = $this->getFileList($customerFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $customerFileInfo);
-
- # 清除客户附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_file");
-
- # 删除客户附件
- Db::name('admin_file')->whereIn('file_id', $customerFileIds)->delete();
-
- # 清除客户数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer");
-
- # ------ 重置客户数据 END ------ #
-
-
- # ------ 重置线索数据 START ------ #
-
- # 获取线索附件ID
- $leadsFileIds = Db::name('crm_leads_file')->column('file_id');
- # 查询线索文件数据
- $leadsFileInfo = $this->getFileList($leadsFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $leadsFileInfo);
-
- # 清除线索附件关联数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_leads_file");
-
- # 删除线索附件
- Db::name('admin_file')->whereIn('file_id', $leadsFileIds)->delete();
-
- # 清除线索数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_leads");
-
- # ------ 重置线索数据 END ------ #
-
- # ------ 重置附件表自增ID START ------ #
-
- Db::query("ALTER TABLE ".$prefix."admin_file AUTO_INCREMENT = 1");
-
- # ------ 重置附件表自增ID END ------ #
-
-
- # ------ 清除活动记录中关于客户管理模块的数据 START ------ #
-
- # 获取活动附件ID
- $activityFileIds = Db::name('crm_activity_file')->column('file_id');
-
- # 查询活动附件数据
- $activityFileInfo = $this->getFileList($activityFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $activityFileInfo);
-
- # 清除活动关联附件数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_activity_file");
-
- # 清除活动数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."crm_activity");
-
- # ------ 清除活动记录中关于客户管理模块的数据 END ------ #
-
-
- # ------ 清除我的关注数据 START ------ #
- Db::query("TRUNCATE TABLE ".$prefix."crm_star");
- # ------ 清除我的关注数据 END ------ #
-
-
- # ------ 清除数据操作日志数据 START ------ #
- Db::name('admin_operation_log')->where(['module' => ['like', 'crm_%']])->delete();
- # ------ 清除数据操作日志数据 END ------ #
-
-
- # ------ 清除客户配置表(锁定、拥有)数据 START ------ #
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_config");
- # ------ 清除客户配置表(锁定、拥有)数据 END ------ #
-
-
- # ------ 清除导入数据记录表 START ------ #
- Db::name('admin_import_record')->where(['type' => ['like', 'crm_%']])->delete();
- # ------ 清除导入数据记录表 END ------ #
-
-
- # ------ 清除字段操作记录表 START ------ #
- Db::name('admin_action_record')->where(['types' => ['like', 'crm_%']])->delete();
- # ------ 清除字段操作记录表 END ------ #
-
-
- # ------ 清除数据操作记录表 START ------ #
- Db::name('admin_action_log')->where('module_name', 'crm')->delete();
- # ------ 清除数据操作记录表 END ------ #
-
- # ------ 清除有关客户模块的审批记录 START ------ #
- Db::name('admin_examine_record')->where(['types' => ['like', 'crm_%']])->delete();
- # ------ 清除有关客户模块的审批记录 END ------ #
-
-
- # ------ 清除跟客户模块有关的管理数据表 START ------ #
-
- # 清除项目关联客户模块表并重置字段ID
- Db::query("TRUNCATE TABLE ".$prefix."work_relation");
- # 清除任务关联客户模块表并重置字段ID
- Db::query("TRUNCATE TABLE ".$prefix."task_relation");
- # 清除日志关联客户模块表并重置字段ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_log_relation");
- # 清除审批关联客户模块表并重置字段ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine_relation");
- # 清除日程关联客户模块表并重置字段ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_event_relation");
-
- # ------ 清除跟客户模块有关的管理数据表 END ------ #
-
-
- # ------ 重置自动编号数据 START ------ #
- $time = time();
- Db::query("TRUNCATE TABLE ".$prefix."crm_number_sequence");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (1, 1, 1, 'HT', null, null, null, null, ".$time.", 1, null, 0, 1)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (2, 2, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 1)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (3, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 1)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (4, 1, 1, 'HK', null, null, null, null, ".$time.", 1, null, 0, 2)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (5, 2, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 2)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (6, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 2)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (7, 1, 1, 'HF', null, null, null, null, ".$time.", 1, null, 0, 3)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (8, 2, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 3)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (9, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 3)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (10, 1, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 4)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (11, 2, 1, 'FP', null, null, null, null, ".$time.", 1, null, 0, 4)");
- Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (12, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 4)");
- # ------ 重置自动编号数据 END ------ #
-
-
- # ------ 重置扩展数据 START ------ #
- Db::query("TRUNCATE TABLE ".$prefix."crm_leads_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_customer_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_contacts_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_business_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_contract_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_receivables_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_receivables_plan_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_invoice_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_visit_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_product_data");
- # ------ 重置扩展数据 END ------ #
-
-
- # ------ 清除待办事项关联数据 START ------ #
- Db::query("TRUNCATE TABLE ".$prefix."crm_dealt_relation");
- # ------ 清除待办事项关联数据 END ------ #
-
-
- # ------ 设置跟进记录常用语 START ------ #
- $phrase = ['电话无人接听', '客户无意向', '客户意向度适中,后续继续跟进', '客户意向度较强,成交几率较大'];
- $phraseId = db('crm_config')->where('name', 'activity_phrase')->value('id');
- if (!empty($phraseId)) {
- db('crm_config')->where('id', $phraseId)->update([
- 'value' => serialize($phrase)
- ]);
- } else {
- db('crm_config')->insert([
- 'name' => 'activity_phrase',
- 'value' => serialize($phrase),
- 'description' => '跟进记录常用语'
- ]);
- }
- # ------ 设置跟进记录常用语 END ------ #
-
-
- # ------ 清除打印相关数据 START ------ #
- Db::query("TRUNCATE TABLE ".$prefix."admin_printing_data");
- Db::query("TRUNCATE TABLE ".$prefix."crm_printing_record");
- # ------ 清除打印相关数据 END ------ #
-
-
- # ------ 删除审批记录 START ------ #
- Db::name('admin_examine_record')->whereLike('types', 'crm%')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_examine_record AUTO_INCREMENT = 1");
- # ------ 删除审批记录 END ------ #
-
-
- # ------ 清除消息数据 START ------ #
- Db::name('admin_message')->where('module_name', 'crm')->delete();
- # ------ 清除消息数据 END ------ #
-
-
- # ------ 删除附件 START ------ #
-
- if (!empty($files)) {
- foreach ($files AS $key => $value) {
- unlink($value);
- }
- }
-
- # ------ 删除附件 START ------ #
-
- # 提交事务
- Db::commit();
-
- return true;
- } catch (Exception $e) {
- # 回滚事务
- Db::rollback();
-
- # 将状态设置为false,终止其他方法的操作
- $this->status = false;
-
- $this->log = '重置客户管理模块时出错!';
-
- return false;
- }
- }
-
- /**
- * 重置任务审批数据
- */
- private function resetTaskExamineData()
- {
- # 表前缀
- $prefix = config('database.prefix');
-
- # 文件数组
- $files = [];
-
- # 启动事务
- Db::startTrans();
- try {
- # ------ 清除审批数据 START ------ #
-
- # 获取审批下关联的附件ID
- $examineFileIds = Db::name('oa_examine_file')->column('file_id');
-
- # 查询审批附件数据
- $examineFileInfo = $this->getFileList($examineFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $examineFileInfo);
-
- # 清除审批关联的附件信息并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine_file");
-
- # 获取差旅附件ID
- $travelFileId = Db::name('oa_examine_travel_file')->column('file_id');
-
- # 查询差旅附件数据
- $travelFileInfo = $this->getFileList($travelFileId);
-
- # 合并附件数据
- $files = array_merge($files, $travelFileInfo);
-
- # 清除差旅关联的附件信息并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine_travel_file");
-
- # 删除差率和审批的附件
- Db::name('admin_file')->whereIn('file_id', $examineFileIds)->delete();
- Db::name('admin_file')->whereIn('file_id', $travelFileId)->delete();
-
- # 删除差旅数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine_travel");
-
- # 删除审批关联的客户模块下的数据并重置ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine_relation");
-
- # 删除审批数据并重置自增ID
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine");
-
- # ------ 清除审批数据 END ------ #
-
-
- # ------ 重置扩展数据 START ------ #
- Db::query("TRUNCATE TABLE ".$prefix."oa_examine_data");
- # ------ 重置扩展数据 END ------ #
-
-
- # ------ 清除活动中有关审批的数据 START ------ #
-
- # 获取有关审批的活动ID
- $activityIds = Db::name('crm_activity')->where('activity_type', 9)->column('activity_id');
-
- # 获取有关审批的附件ID
- $activityFileIds = Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->column('file_id');
-
- # 查询审批附件数据
- $activityFileInfo = $this->getFileList($activityFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $activityFileInfo);
-
- # 删除有关审批的附件关联记录
- Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity_file AUTO_INCREMENT = 1");
-
- # 删除有关审批的活动记录
- Db::name('crm_activity')->where('activity_type', 9)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity AUTO_INCREMENT = 1");
-
- # ------ 清除活动中有关审批的数据 END ------ #
-
-
- # ------ 清除有关审批的数据操作记录 START ------ #
- Db::name('admin_action_log')->where('module_name', 'oa')->where('controller_name', 'examine')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_action_log AUTO_INCREMENT = 1");
- # ------ 清除活动中有关审批的数据 END ------ #
-
- # ------ 清除有关任务的数据操作记录 START ------ #
- // Db::name('admin_action_log')->where('module_name', 'oa')->where('controller_name', 'task')->delete();
- // Db::query("ALTER TABLE ".$prefix."admin_action_log AUTO_INCREMENT = 1");
- # ------ 清除有关任务的数据操作记录 END ------ #
-
-
- # ------ 清除审批日志 START ------ #
- Db::name('admin_examine_record')->where('types', 'oa_examine')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_examine_record AUTO_INCREMENT = 1");
- # ------ 清除审批日志 END ------ #
-
-
- # ------ 清除任务和审批操作记录 START ------ #
- // Db::name('admin_operation_log')->where('module', 'oa_task')->delete();
- Db::name('admin_operation_log')->where('module', 'oa_examine')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_operation_log AUTO_INCREMENT = 1");
- # ------ 清除任务操作记录 END ------ #
-
-
- # ------ 清除消息数据 START ------ #
- Db::name('admin_message')->where('module_name', 'oa')->where('controller_name', 'examine')->delete();
- # ------ 清除消息数据 END ------ #
-
-
- # ------ 重置附件表自增ID START ------ #
- Db::query("ALTER TABLE ".$prefix."admin_file AUTO_INCREMENT = 1");
- # ------ 重置附件表自增ID END ------ #
-
-
- # ------ 删除附件 START ------ #
- if (!empty($files)) {
- foreach ($files AS $key => $value) {
- unlink($value);
- }
- }
- # ------ 删除附件 START ------ #
-
-
- # 提交事务
- Db::commit();
-
- return true;
- } catch (Exception $e) {
- # 回滚事务
- Db::rollback();
-
- # 将状态设置为false,终止其他方法的操作
- $this->status = false;
-
- $this->log = '重置任务/审批模块时出错!';
-
- return false;
- }
- }
-
- /**
- * 重置日志数据
- */
- private function resetDailyRecordData()
- {
- # 表前缀
- $prefix = config('database.prefix');
-
- # 文件数组
- $files = [];
-
- # 启动事务
- Db::startTrans();
- try {
- # ------ 清除日志数据 START ------ #
-
- # 获取日志附件ID
- $logFileIds = Db::name('oa_log_file')->column('file_id');
-
- # 查询活动附件数据
- $logFileInfo = $this->getFileList($logFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $logFileInfo);
-
- # 清除日志附件关联数据
- Db::query("TRUNCATE TABLE ".$prefix."oa_log_file");
-
- # 清除日志客户管理关联数据
- Db::query("TRUNCATE TABLE ".$prefix."oa_log_relation");
-
- # 清楚日志数据
- Db::query("TRUNCATE TABLE ".$prefix."oa_log");
-
- # ------ 清除日志数据 START ------ #
-
-
- # ------ 清除活动中有关审批的数据 START ------ #
-
- # 获取有关日志的活动ID
- $activityIds = Db::name('crm_activity')->where('activity_type', 8)->column('activity_id');
-
- # 获取有关日志的附件ID
- $activityFileIds = Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->column('file_id');
-
- # 查询日志附件数据
- $activityFileInfo = $this->getFileList($activityFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $activityFileInfo);
-
- # 删除有关日志的附件关联记录
- Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity_file AUTO_INCREMENT = 1");
-
- # 删除有关日志的活动记录
- Db::name('crm_activity')->where('activity_type', 8)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity AUTO_INCREMENT = 1");
-
- # ------ 清除活动中有关审批的数据 END ------ #
-
-
- # ------ 清除日志操作记录表 START ------ #
- Db::name('admin_action_log')->where('module_name', 'oa')->where('controller_name', 'log')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_action_log AUTO_INCREMENT = 1");
- # ------ 清除日志操作记录表 END ------ #
-
-
- # ------ 清除日志操作记录 START ------ #
- Db::name('admin_operation_log')->where('module', 'oa_log')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_operation_log AUTO_INCREMENT = 1");
- # ------ 清除日志操作记录 END ------ #
-
- # ------ 删除消息数据 START ------ #
- Db::name('admin_comment')->where('type', 'oa_log')->delete();
- Db::name('admin_message')->where('module_name', 'oa')->where('controller_name', 'log')->delete();
- # ------ 删除消息数据 END ------ #
-
-
- # ------ 重置附件表自增ID START ------ #
- Db::query("ALTER TABLE ".$prefix."admin_file AUTO_INCREMENT = 1");
- # ------ 重置附件表自增ID END ------ #
-
-
- # ------ 删除附件 START ------ #
- if (!empty($files)) {
- foreach ($files AS $key => $value) {
- unlink($value);
- }
- }
- # ------ 删除附件 START ------ #
-
-
- # 提交事务
- Db::commit();
-
- return true;
- } catch (Exception $e) {
- # 回滚事务
- Db::rollback();
-
- # 将状态设置为false,终止其他方法的操作
- $this->status = false;
-
- $this->log = '重置日志模块时出错!';
-
- return false;
- }
- }
-
- /**
- * 重置项目管理数据
- */
- private function resetProjectManagementData()
- {
- # 表前缀
- $prefix = config('database.prefix');
-
- # 文件数组
- $files = [];
-
- # 启动事务
- Db::startTrans();
- try {
- # ------ 清除项目管理数据 START ------ #
-
- # 获取项目ID
- // $workIds = Db::name('work')->column('work_id');
-
- # 获取任务ID
- // $taskIds = Db::name('task')->whereIn('work_id', $workIds)->column('task_id');
- $taskIds = Db::name('task')->column('task_id');
-
- # 获取关联附件ID
- $workTaskFileIds = Db::name('work_task_file')->whereIn('task_id', $taskIds)->column('file_id');
-
- # 查询项目附件数据
- $workTaskFileInfo = $this->getFileList($workTaskFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $workTaskFileInfo);
-
- # 清除项目中的任务附件关联数据
- Db::name('work_task_file')->whereIn('task_id', $taskIds)->delete();
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."work_task_file AUTO_INCREMENT = 1");
-
- # 清除标签数据
- Db::query("TRUNCATE TABLE ".$prefix."work_task_lable");
-
- # 清除任务日志
- Db::name('work_task_log')->whereIn('task_id', $taskIds)->delete();
- # 重置任务日志自增ID
- Db::query("ALTER TABLE ".$prefix."work_task_log AUTO_INCREMENT = 1");
-
- # 清除项目成员
- Db::query("TRUNCATE TABLE ".$prefix."work_user");
-
- # 清除任务分类
- Db::query("TRUNCATE TABLE ".$prefix."work_task_class");
-
- # 清除任务与客户模块的管理数据
- Db::query("TRUNCATE TABLE ".$prefix."work_relation");
-
- # 清除任务数据
- Db::query("TRUNCATE TABLE ".$prefix."task");
- // Db::name('task')->where('work_id', '<>', 0)->delete();
- // # 重置自增ID
- // Db::query("ALTER TABLE ".$prefix."task AUTO_INCREMENT = 1");
-
- # 清除项目排序数据
- Db::query("TRUNCATE TABLE ".$prefix."work_order");
-
- # 清除标签排序数据
- Db::query("TRUNCATE TABLE ".$prefix."work_lable_order");
-
- # 清除项目数据
- Db::query("TRUNCATE TABLE ".$prefix."work");
-
- # ------ 清除项目管理数据 END ------ #
-
-
- # ------ 清除活动中有关任务的数据 START ------ #
-
- # 获取有关任务的活动ID
- $activityIds = Db::name('crm_activity')->where('activity_type', 11)->whereIn('activity_type_id', $taskIds)->column('activity_id');
-
- # 获取有关任务的附件ID
- $activityFileIds = Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->column('file_id');
-
- # 查询任务附件数据
- $activityFileInfo = $this->getFileList($activityFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $activityFileInfo);
-
- # 删除有关任务的附件关联记录
- Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity_file AUTO_INCREMENT = 1");
-
- # 删除有关任务的活动记录
- Db::name('crm_activity')->where('activity_type', 11)->whereIn('activity_type_id', $taskIds)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity AUTO_INCREMENT = 1");
-
- # ------ 清除活动中有关任务的数据 END ------ #
-
-
- # ------ 清除有关项目的数据操作记录 START ------ #
- Db::name('admin_action_log')->where('module_name', 'work')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_action_log AUTO_INCREMENT = 1");
- # ------ 清除有关项目的数据操作记录 END ------ #
-
- # ------ 清除项目操作记录 START ------ #
- Db::name('admin_operation_log')->where('module', 'work_task')->delete();
- Db::query("ALTER TABLE ".$prefix."admin_operation_log AUTO_INCREMENT = 1");
- # ------ 清除项目操作记录 END ------ #
-
-
- # ------ 清除评论和消息数据 START ------#
- Db::name('admin_comment')->where('type', 'task')->delete();
- Db::name('admin_message')->where('module_name', 'work')->delete();
- Db::name('admin_message')->where('module_name', 'oa')->where('controller_name', 'task')->delete();
- # ------ 清除评论和消息数据 END ------ #
-
-
- # 清除任务关联客户模块表并重置字段ID
- Db::query("TRUNCATE TABLE ".$prefix."task_relation");
-
-
- # ------ 重置附件表自增ID START ------ #
- Db::query("ALTER TABLE ".$prefix."admin_file AUTO_INCREMENT = 1");
- # ------ 重置附件表自增ID END ------ #
-
-
- # ------ 删除附件 START ------ #
- if (!empty($files)) {
- foreach ($files AS $key => $value) {
- unlink($value);
- }
- }
- # ------ 删除附件 START ------ #
-
-
- # 提交事务
- Db::commit();
-
- return true;
- } catch (Exception $e) {
- # 回滚事务
- Db::rollback();
-
- # 将状态设置为false,终止其他方法的操作
- $this->status = false;
-
- $this->log = '重置项目管理模块时出错!';
-
- return false;
- }
- }
-
- /**
- * 重置日历数据
- */
- private function resetCalendarData()
- {
- # 表前缀
- $prefix = config('database.prefix');
-
- # 文件数组
- $files = [];
-
- # 启动事务
- Db::startTrans();
- try {
- # ------ 清除日历数据 START ------ #
-
- # 获取日历ID
- $eventIds = Db::name('oa_event')->column('event_id');
-
- # 删除日历关联的客户数据
- Db::query("TRUNCATE TABLE ".$prefix."oa_event_relation");
-
- # 删除日历的数据操作记录
- Db::name('admin_action_log')->where('module_name', 'oa')->where('controller_name', 'event')->delete();
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."admin_action_log AUTO_INCREMENT = 1");
-
- # 删除日历的字段操作记录
- Db::name('admin_action_record')->where('types', 'oa_event')->delete();
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."admin_action_record AUTO_INCREMENT = 1");
-
- # 删除日历提醒
- Db::query("TRUNCATE TABLE ".$prefix."oa_event_notice");
-
- # 删除日历数据
- Db::query("TRUNCATE TABLE ".$prefix."oa_event");
-
- # ------ 清除日历数据 END ------ #
-
-
- # ------ 删除活动数据 START ------ #
-
- # 获取活动ID
- $activityIds = Db::name('crm_activity')->where('activity_type', 10)->whereIn('activity_type_id', $eventIds)->column('activity_id');
-
- # 获取有关任务的附件ID
- $activityFileIds = Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->column('file_id');
-
- # 查询任务附件数据
- $activityFileInfo = $this->getFileList($activityFileIds);
-
- # 合并附件数据
- $files = array_merge($files, $activityFileInfo);
-
- # 删除有关任务的附件关联记录
- Db::name('crm_activity_file')->whereIn('activity_id', $activityIds)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity_file AUTO_INCREMENT = 1");
-
- # 删除有关任务的活动记录
- Db::name('crm_activity')->where('activity_type', 10)->whereIn('activity_type_id', $eventIds)->delete();
-
- # 重置自增ID
- Db::query("ALTER TABLE ".$prefix."crm_activity AUTO_INCREMENT = 1");
-
- # ------ 删除活动数据 END ------ #
-
- # ------ 删除消息数据 START ------ #
- Db::name('admin_message')->where('module_name', 'oa')->where('controller_name', 'event')->delete();
- # ------ 删除消息数据 END ------ #
-
- # ------ 重置附件表自增ID START ------ #
- Db::query("ALTER TABLE ".$prefix."admin_file AUTO_INCREMENT = 1");
- # ------ 重置附件表自增ID END ------ #
-
-
- # ------ 删除附件 START ------ #
- if (!empty($files)) {
- foreach ($files AS $key => $value) {
- unlink($value);
- }
- }
- # ------ 删除附件 START ------ #
-
-
- # 提交事务
- Db::commit();
-
- return true;
- } catch (Exception $e) {
- # 回滚事务
- Db::rollback();
-
- # 将状态设置为false,终止其他方法的操作
- $this->status = false;
-
- $this->log = '重置日历模块时出错!';
-
- return false;
- }
- }
-
- /**
- * 获取文件列表
- *
- * @param $fileIds
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- private function getFileList($fileIds)
- {
- $result = [];
-
- $list = Db::name('admin_file')->field([
- 'file_path',
- 'file_path_thumb'
- ])->whereIn('file_id', $fileIds)->select();
-
- foreach ($list AS $key => $value) {
- if (!empty($value['file_path'])) $result[] = 'public/uploads/' . $value['file_path'];
- if (!empty($value['file_path_thumb'])) $result[] = 'public/uploads/' . $value['file_path_thumb'];
- }
-
- return $result;
- }
- }
|