liugc 1 год назад
Родитель
Сommit
10c7448975

+ 2 - 2
app/adminapi/lists/BaseAdminDataLists.php

@@ -31,8 +31,8 @@ abstract class BaseAdminDataLists extends BaseDataLists
     public function __construct()
     {
         parent::__construct();
-        $this->adminInfo = $this->request->adminInfo;
-        $this->adminId = $this->request->adminId;
+        $this->adminInfo = $this->request->adminInfo??[];
+        $this->adminId = $this->request->adminId??0;
     }
 
 

+ 130 - 0
app/adminapi/lists/works/ServiceWorkMailLists.php

@@ -0,0 +1,130 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\works;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\goods_category\GoodsCategory;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerInfo;
+use app\common\model\master_worker_credential\MasterWorkerCredentialImages;
+use app\common\model\master_worker_register\MasterWorkerRegister;
+use app\common\model\property\PropertyOrder;
+use app\common\model\works\ServiceWork;
+use app\common\lists\ListsSearchInterface;
+use think\db\Query;
+use think\facade\Log;
+
+
+/**
+ * 导出ServiceWork列表
+ * Class ServiceWorkLists
+ * @package app\adminapi\listsworks
+ */
+class ServiceWorkMailLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+    /**
+     * 设置搜索条件
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['id']
+        ];
+    }
+
+    public function queryWhere(){
+        $where = [];
+        $time = [strtotime(date("Y-m-d")), strtotime(date("Y-m-d 22:59:59"))];
+        $where[] = ['finished_time', 'between', $time];
+        return $where;
+    }
+    /**
+     * 获取列表
+     */
+    public function lists(): array
+    {
+        return ServiceWork::with([
+                'worker'=>function(Query $query) {
+                    $query->field("id,worker_number,real_name,mobile");
+                },
+                'goodsCategory' =>function (Query $query) {
+                    $query->field('id,name');
+                }
+            ])
+            ->where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->where('master_worker_id', '>', 0)
+            ->field(['*'])
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/07/10 15:06
+     */
+    public function count(): int
+    {
+        return 0;
+    }
+
+
+    public function setFileName(): string
+    {
+        return date('Ymd');
+    }
+
+    public function setExcelComplexFields(): array
+    {
+
+        /*序号	工单编号	服务类别 category_type	维修家电类型 goodsCategory.name	领单时间 receive_time	预约上门时间 finally_door_time	结单时间 finished_time
+        工程师 worker.real_name	工程师身份证号 worker.id	   工程师手机号 worker.mobile	 资格证书号 worker.id	获证日期 worker.id
+        客户信息 real_name	客户手机号 mobile	客户地址 address*/
+        $zh_cn_fields = [
+            '序号','工单编号', '服务类别','维修家电类型','领单时间','预约上门时间','结单时间',
+            '工程师','工程师身份证号','工程师手机号','资格证书号','获证日期','客户信息','客户手机号','客户地址'
+        ];
+        $data_fields = [
+            'id','work_sn','category_type',function ($row) { return isset($row['goodsCategory']['name'])?$row['goodsCategory']['name']:''; },function ($row) { return $row['receive_time']?:''; },function ($row) { return isset($row['finally_door_time'])?date('Y-m-d H:i:s',$row['finally_door_time']):''; },function ($row) { return $row['finished_time']?:''; },
+            function ($row) { return isset($row['worker']['real_name'])?$row['worker']['real_name']:''; },function ($row) {
+            return isset($row['worker']['id'])?MasterWorkerInfo::where(['worker_id'=>$row['worker']['id']])->value('id_card'):'';
+            },function ($row) { return isset($row['worker']['mobile'])?$row['worker']['mobile']:''; },function ($row) {
+                if(isset($row['worker']['id'])){
+                    $worker_register_id = MasterWorkerRegister::where(['worker_id'=>$row['worker']['id']])->value('id')?:0;
+                    return MasterWorkerCredentialImages::where(['worker_register_id'=>$worker_register_id])->value('number')?:'';
+                }else{
+                    return '';
+                }
+            },function ($row) {
+                if(isset($row['worker']['id'])){
+                    $worker_register_id = MasterWorkerRegister::where(['worker_id'=>$row['worker']['id']])->value('id')?:0;
+                    return MasterWorkerCredentialImages::where(['worker_register_id'=>$worker_register_id])->value('start_time')?:'';
+                }else{
+                    return '';
+                }
+            },
+            'real_name','mobile','address'
+        ];
+        return [
+            'zh_cn_fields' => $zh_cn_fields,
+            'data_fields' => $data_fields
+        ];
+    }
+}

+ 2 - 2
app/api/controller/BaseApiController.php

@@ -26,8 +26,8 @@ class BaseApiController extends BaseLikeAdminController
     {
         $this->request->source = AdminTerminalEnum::USER;
         if (isset($this->request->userInfo) && $this->request->userInfo) {
-            $this->userInfo = $this->request->userInfo;
-            $this->userId = $this->request->userInfo['user_id'];
+            $this->userInfo = $this->request->userInfo??[];
+            $this->userId = $this->request->userInfo['user_id']??0;
         }
     }
 }

+ 111 - 0
app/common/command/SendBxMail.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\common\command;
+
+use app\adminapi\lists\works\ServiceWorkMailLists;
+use excel\ExcelWriter;
+use PHPMailer\PHPMailer\PHPMailer;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Log;
+
+/**
+ *  发送保险的邮箱
+ * Class SendBxMail
+ * @package app\command
+ */
+class SendBxMail extends Command
+{
+    protected function configure()
+    {
+        $this->setName('send_bx_mail')->setDescription('每天22点定时发送邮箱');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        try {
+            return $this->sendMail();
+        } catch (\Exception $e) {
+            Log::write('SendBxMail:'.$e->getMessage());
+            return false;
+        }
+    }
+
+
+
+    public function sendMail()
+    {
+        // 文件路径 - 替换为你的实际文件路径
+        //$filePath = 'uploads/baoxian/20250327职业责任险投保清单.xlsx';
+        $excelFile = $this->getExcelFile();
+        $filePath = $excelFile[0];
+        $filename = $excelFile[1];
+        if(empty($filePath)) throw new \Exception("邮件发送失败. 错误信息: 路径不存在");
+
+        $mail = new PHPMailer(true);
+
+        try {
+            // 邮件服务器设置
+            $mail->isSMTP();                                            // 使用SMTP发送邮件
+            $mail->Host       = 'smtp.126.com';                     // SMTP服务器地址,替换为你的SMTP服务器
+            $mail->SMTPAuth   = true;                                   // 启用SMTP认证
+            $mail->Username   = 'whkyjl@126.com';               // SMTP用户名,替换为你的邮箱地址
+            $mail->Password   = 'MNpgMjYMYehx3nPi';                        // SMTP密码,替换为你的邮箱密码
+            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;         // 开启加密,默认为无加密,可选`PHPMailer::ENCRYPTION_SMTPS`
+            $mail->Port       = 465;
+
+//            $mail->SMTPDebug = 2;                                       // 启用详细调试输出
+            $mail->CharSet = 'UTF-8';
+            // 发送者和接收者设置
+            $mail->setFrom('whkyjl@126.com', '武汉开源节流科技有限公司');     // 发件人邮箱和名称
+            $mail->addAddress('sujing@ub.chinalife-p.com.cn', '出单业务'); // 收件人邮箱和名称
+            $mail->addAddress('649478907@qq.com', '出单业务'); // 收件人邮箱和名称
+            $mail->addAddress('liliangjie@ub.chinalife-p.com.cn', '出单业务'); // 收件人邮箱和名称
+            $mail->addAddress('fangxuhao@outlook.com', '出单业务'); // 收件人邮箱和名称
+//            $mail->addAddress('1804628603@qq.com', '出单业务'); // 收件人邮箱和名称
+
+            // 设置邮件内容
+            $mail->isHTML(true);                                        // 将邮件正文设置为HTML格式
+            // 设置邮件内容
+            $mail->Subject = mb_convert_encoding('请查收附件中的Excel文件', 'UTF-8', 'auto');
+            $mail->Body    = mb_convert_encoding('<p>你好,<br>请查收附件中的Excel文件。</p>', 'UTF-8', 'auto');
+            $mail->AltBody = mb_convert_encoding('你好,请查收附件中的Excel文件。', 'UTF-8', 'auto');
+            // 添加附件
+            $mail->addAttachment($filePath, $filename); // 添加附件,第二个参数是显示在邮件中的文件名
+
+            $mail->send();
+            return '邮件发送成功';
+        } catch (\Exception $e) {
+            throw new \Exception("邮件发送失败. 错误信息: {$mail->ErrorInfo}");
+        }
+    }
+
+    public function getExcelFile()
+    {
+        try {
+            $downloadObj = new ServiceWorkMailLists();
+            $sheet = new ExcelWriter();
+            $lists = $downloadObj->excelExportList([]);
+            $filename = $downloadObj->setFileName().'职业责任险投保清单';
+            $fields = $downloadObj->setExcelComplexFields();
+            if(!$lists || !$fields){
+                Log::info('ServiceWorkMail:lists或fields不存在');
+                return '';
+            }else{
+                $sheet->generateExcelFile($fields['zh_cn_fields'], $lists,$filename, $fields['data_fields']);
+                return [$sheet->fileUrl(),$filename];
+            }
+        } catch (\Exception $e) {
+            Log::info('ServiceWorkMail:'."生成职业责任险投保清单失败. 错误信息: {$e->getMessage()}");
+            return '';
+        }
+    }
+
+
+
+
+
+
+
+
+}

+ 2 - 0
config/console.php

@@ -13,6 +13,8 @@ return [
         'query_add_agreement' => 'app\common\command\AddAgreementPdf',
         //工程师每日开启接单的通知
         'open_obtain_order' => 'app\common\command\OpenObtainOrder',
+        //发送保险邮箱
+        'send_bx_mail' => 'app\common\command\SendBxMail',
         //工程师自动派单
         'automatic_dispatch' => 'app\common\command\AutomaticDispatch',
         //自动取消超时未领的工单