WIN-2308041133\Administrator 11 小时之前
父节点
当前提交
177c72bbb4

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/muyinjie.iml" filepath="$PROJECT_DIR$/.idea/muyinjie.iml" />
+    </modules>
+  </component>
+</project>

+ 67 - 0
.idea/muyinjie.iml

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" packagePrefix="app\" />
+      <sourceFolder url="file://$MODULE_DIR$/extend" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/library" isTestSource="false" packagePrefix="library\" />
+      <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/ralouphie/getallheaders" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/wechatpay/wechatpay-guzzle-middleware" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/wechatpay/wechatpay" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/adbario/php-dot-notation" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/firebase/php-jwt" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation-contracts" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-dumper" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/process" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/alipaysdk/easysdk" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-helper" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-captcha" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/mtdowling/jmespath.php" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-queue" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-view" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-template" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/framework" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-image" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/songshenzong/support" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-trace" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-orm" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-multi-app" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/simple-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-message" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/phpoffice/phpexcel" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-client" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/qiniu/php-sdk" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/psr7" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/uri-template" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/lustre/php-dfa-sensitive" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/promises" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/guzzle" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/danielstjules/stringy" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/clagiordano/weblibs-configmanager" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/league/mime-type-detection" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/alibabacloud/tea-fileform" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/league/flysystem-cached-adapter" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/alibabacloud/tea" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/league/flysystem" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/alibabacloud/sdk" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/nesbot/carbon" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/alibabacloud/client" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/pimple/pimple" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/xin/container" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/xin/helper" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/dh2y/think-qrcode" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 77 - 0
.idea/php.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="MessDetectorOptionsConfiguration">
+    <option name="transferred" value="true" />
+  </component>
+  <component name="PHPCSFixerOptionsConfiguration">
+    <option name="transferred" value="true" />
+  </component>
+  <component name="PHPCodeSnifferOptionsConfiguration">
+    <option name="highlightLevel" value="WARNING" />
+    <option name="transferred" value="true" />
+  </component>
+  <component name="PhpIncludePathManager">
+    <include_path>
+      <path value="$PROJECT_DIR$/vendor/composer" />
+      <path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
+      <path value="$PROJECT_DIR$/vendor/wechatpay/wechatpay-guzzle-middleware" />
+      <path value="$PROJECT_DIR$/vendor/wechatpay/wechatpay" />
+      <path value="$PROJECT_DIR$/vendor/adbario/php-dot-notation" />
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
+      <path value="$PROJECT_DIR$/vendor/firebase/php-jwt" />
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
+      <path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
+      <path value="$PROJECT_DIR$/vendor/symfony/var-dumper" />
+      <path value="$PROJECT_DIR$/vendor/symfony/translation" />
+      <path value="$PROJECT_DIR$/vendor/symfony/process" />
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
+      <path value="$PROJECT_DIR$/vendor/alipaysdk/easysdk" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-helper" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-captcha" />
+      <path value="$PROJECT_DIR$/vendor/mtdowling/jmespath.php" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-queue" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-view" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-template" />
+      <path value="$PROJECT_DIR$/vendor/topthink/framework" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-image" />
+      <path value="$PROJECT_DIR$/vendor/songshenzong/support" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-trace" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-orm" />
+      <path value="$PROJECT_DIR$/vendor/topthink/think-multi-app" />
+      <path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
+      <path value="$PROJECT_DIR$/vendor/psr/cache" />
+      <path value="$PROJECT_DIR$/vendor/psr/http-message" />
+      <path value="$PROJECT_DIR$/vendor/phpoffice/phpexcel" />
+      <path value="$PROJECT_DIR$/vendor/psr/container" />
+      <path value="$PROJECT_DIR$/vendor/psr/log" />
+      <path value="$PROJECT_DIR$/vendor/psr/http-client" />
+      <path value="$PROJECT_DIR$/vendor/qiniu/php-sdk" />
+      <path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" />
+      <path value="$PROJECT_DIR$/vendor/guzzlehttp/uri-template" />
+      <path value="$PROJECT_DIR$/vendor/lustre/php-dfa-sensitive" />
+      <path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" />
+      <path value="$PROJECT_DIR$/vendor/guzzlehttp/guzzle" />
+      <path value="$PROJECT_DIR$/vendor/danielstjules/stringy" />
+      <path value="$PROJECT_DIR$/vendor/clagiordano/weblibs-configmanager" />
+      <path value="$PROJECT_DIR$/vendor/league/mime-type-detection" />
+      <path value="$PROJECT_DIR$/vendor/alibabacloud/tea-fileform" />
+      <path value="$PROJECT_DIR$/vendor/league/flysystem-cached-adapter" />
+      <path value="$PROJECT_DIR$/vendor/alibabacloud/tea" />
+      <path value="$PROJECT_DIR$/vendor/league/flysystem" />
+      <path value="$PROJECT_DIR$/vendor/alibabacloud/sdk" />
+      <path value="$PROJECT_DIR$/vendor/nesbot/carbon" />
+      <path value="$PROJECT_DIR$/vendor/alibabacloud/client" />
+      <path value="$PROJECT_DIR$/vendor/pimple/pimple" />
+      <path value="$PROJECT_DIR$/vendor/xin/container" />
+      <path value="$PROJECT_DIR$/vendor/xin/helper" />
+      <path value="$PROJECT_DIR$/vendor/dh2y/think-qrcode" />
+    </include_path>
+  </component>
+  <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
+  <component name="PhpStanOptionsConfiguration">
+    <option name="transferred" value="true" />
+  </component>
+  <component name="PsalmOptionsConfiguration">
+    <option name="transferred" value="true" />
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 261 - 0
app/api/controller/User.php

@@ -14,6 +14,8 @@ namespace app\api\controller;
 
 use app\BaseController;
 
+use app\model\api\ContractComment as ContractCommentModel;
+use app\model\api\ContractRecord as UserContractRecordModel;
 use app\model\api\User as UserModel;
 use app\model\api\UserDetail as UserDetailModel;
 use app\model\api\ServiceType as ServiceTypeModel;
@@ -1110,5 +1112,264 @@ class User extends BaseController
         ];
     }
 
+    /**
+     * 合约列表
+     * @param \app\Request $request
+     * @return mixed
+     */
+    public function getContractList(\think\Request $request)
+    {
+//        $pageSize = 50;
+//        $post =  UtilService::getMore([
+//            ['page',1],
+//            ['pageSize',50],
+//            ['nickname',''],
+////            ['uid',''],
+//            ['parent_uid',''],
+//            ['mobile',''],
+//            ['status',''],
+//            ['time',[]],
+//        ],$request);
+////        $post['uid']=$request->user["uid"];
+//        $data = (new UserModel)->getDataList($post,"*",1);
+//        return app('json')->success([
+//            'list'      => $data["list"],
+//            'pageCount' => $data["totalCount"],
+//            'pageSize'  => $data["pageSize"],
+//            'page'      => $data["page"],
+//        ]);
+        $post = UtilService::getMore([
+            ['page', 1],
+            ['pageSize', 50],
+            ['status',-2] //1未签约 2已签约 3已解约
+        ], $request);
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0 ? 1 : (int)$post["page"];
+        $where=[];
+        $where[]=["uid","=",$request->user["uid"]];
+        $totalCount = (new UserContractRecordModel)->where($where)->count();
+        if ($post["status"]!=-2){
+            $where[]=['status','=',$post["status"]];
+        }
+        $data=null;
+        if($totalCount>0){
+            $data = (new UserContractRecordModel)
+//                ->field("")
+//                ->alias("ut")
+//                ->join("show_template t", "t.id = show_template_id","left")
+                ->where($where)
+                ->order("is_default", "desc")
+                ->order("id", "desc")
+                ->page($post["page"], $post["pageSize"])
+                ->select();
+            foreach($data as $k=>$v){
+                $data[$k]["is_use"]      = 1;//是否已经购买或者可以使用
+                switch ($data[$k]["status"]){
+                    case 0:
+                        $data[$k]["status_name"] = "未签约";
+                        break;
+                    case 1:
+                        $data[$k]["status_name"] = "已签约";
+                        break;
+                    case -1:
+                        $data[$k]["status_name"] = "已解约";
+                        break;
+                }
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
+    }
+
+    /**
+     * 甲方创建合约
+     */
+    public function form_save(Request $request){
+        $post = UtilService::getMore([
+            ['uid','0'],  //甲方uid
+            ['phone',''],  //甲方手机号
+            ['address',''], //甲方地址
+            ['card',''], //甲方身份证号
+            ['to_uid','0'], //员工uid
+            ['price',0],  //服务费
+            ['deposit',0], // 定金
+            ['balance',0], //余款
+            ['period',0], // 周期天数
+            ['start_time',''], // 开始时间
+            ['end_time',''], // 结束时间
+
+//            ['uid_img','']  //甲方签名图片路径
+//            ['to_phone',''].
+//            ['to_address',''],
+//            ['to_card',''],
+//            ['data',[]],
+//            ['year',''],
+//            ['month',''],
+//            ['day',''],
+
+        ],$request);
+        $id = (int)$post["id"];
+
+        $uid = (int)$post["uid"];
+        if(empty($uid)){
+            return app('json')->fail("参数错误");
+        }
+//        $year = $post['year'];
+//        $month = $post['month'];
+//        $day = $post['day'];
+//
+//// 检查年月日是否为空
+//        if (empty($year) || empty($month) || empty($day)) {
+//            return app('json')->fail("日期参数错误");
+//        }
+//
+//// 创建 DateTime 对象
+//        $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
+//
+//// 检查日期是否有效
+//        if (!$date || $date->format('Y-m-d') !== "$year-$month-$day") {
+//            return app('json')->fail("无效的日期");
+//        }
+//        unset($post['year']);
+//        unset($post['month']);
+//        unset($post['day']);
+//// 转换为时间戳
+//        $timestamp = $date->getTimestamp();
+//
+//        $post['create_time'] = $timestamp;
+        //用户信息
+//        if(!empty($post["uid_img"])){
+//            $post['status'] = 2;
+//        }else{
+        $post['status'] = 0;
+//        }
+        if (empty($id)){
+            $post['contract_no'] = makeOrderId($post['uid'],"CR");
+            $r = (new UserContractRecordModel)->save($post);
+        }else{
+            $r = (new UserContractRecordModel)->where("id",$id)->update($post);
+        }
+
+        return app('json')->success("数据保存成功");
+    }
+    /**
+     * 甲方签约合约
+     */
+    public function check(Request $request){
+        $post = UtilService::getMore([
+            ['id',0],  //合约id
+            ['uid_img',''],  //甲方签名图片路径
+            ['check_time','']//签约时间
+//            ['to_phone',''].
+//            ['to_address',''],
+//            ['to_card',''],
+//            ['data',[]],
+//            ['year',''],
+//            ['month',''],
+//            ['day',''],
 
+        ],$request);
+        $info = (new UserContractRecordModel)->where("id",$post["id"])->find();
+        if(empty($info)){
+            return app('json')->fail("合约不存在");
+        }
+
+        // 检查签约时间是否为空
+        if (empty($post['uid_img'])) {
+            return app('json')->fail("签字错误");
+        }
+// 检查签约时间是否为空
+        if (empty($post['check_time'])) {
+            return app('json')->fail("日期参数错误");
+        }
+
+//        $post['status'] = 1;
+        $post['from_check'] = 1;
+        if ($info['to_check']==1){
+            $post['status']==1;
+        }
+
+//        $post['contract_no'] = makeOrderId($post['uid'],"CR");
+        $r = (new UserContractRecordModel)->where("id",$post["id"])->update($post);
+        return app('json')->success("数据保存成功");
+    }
+//    乙方确认
+    public function to_check(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],  //
+            ['to_uid_img',''],  //乙方签名图片路径
+            ['to_phone',''], //乙方手机号
+            ['to_address',''], //乙方地址
+            ['to_card',''], //乙方身份证号
+            ['to_check_time','']//签约时间
+        ],$request);
+        $info = (new UserContractRecordModel)->where("id",$post["id"])->find();
+        if(empty($info)){
+            return app('json')->fail("合约不存在");
+        }
+        // 检查签约时间是否为空
+        if (empty($post['to_uid_img'])) {
+            return app('json')->fail("签字错误");
+        }
+// 检查签约时间是否为空
+        if (empty($post['to_check_time'])) {
+            return app('json')->fail("日期参数错误");
+        }
+        $post['to_check'] = 1;
+        if ($info['from_check']==1){
+            $post['status']==1;
+        }
+        $r = (new UserContractRecordModel)->where("id",$post["id"])->update($post);
+        return app('json')->success("数据保存成功");
+    }
+//    员工签到
+    public function clock_in(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],  //合约id
+            ['longitude',''],  //经度
+            ['latitude',''],  //纬度
+
+        ],$request);
+        $uid = (int)$post["uid"];
+        // 检查签约时间是否为空
+        if (empty($post['id'])) {
+            return app('json')->fail("签字错误");
+        }
+        $nickname=\app\model\api\User::where('uid',$uid)->value('nickname');
+        $r = (new UserContractRecordModel)->where("id",$post["id"])->save([
+            'uid'=>$uid,
+            'nickname' => $nickname,
+            'longitude'=>$post['longitude'],
+            'latitude'=>$post['latitude'],
+            'contract_id'=>$post['id'],
+            'create_time'=>time()
+        ]);
+        return app('json')->success("数据保存成功");
+    }
+//  添加客户评论
+    public function comment(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],  //合约id
+            ['content',''],  //评论内容
+        ],$request);
+        $uid = (int)$post["uid"];
+        $info = (new UserContractRecordModel)->where("id",$post["id"])->find();
+        if(empty($info)){
+            return app('json')->fail("合约不存在");
+        }
+        if ($info['status']!=1){
+            return app('json')->fail("只能在签约期间才能发表评论");
+        }
+        // 检查签约时间是否为空
+        if (empty($post['id'])) {
+            return app('json')->fail("签字错误");
+        }
+        $r = (new ContractCommentModel)->save([
+            'uid'=>$uid,
+            'contract_id'=>$post['id'],
+            'content'=>$post['content'],
+            'create_time'=>time()
+        ]);
+        return app('json')->success("数据保存成功");
+    }
 }

+ 13 - 2
app/api/route/user.php

@@ -53,8 +53,19 @@ Route::group('user', function () {
     Route::rule('qiniuUpload', 'User/qiniuUpload');
     //获取小程序邀请码
     Route::rule('getWxmpInviteQrcode', 'User/getWxmpInviteQrcode');
-    
-    
+
+    //合约列表
+    Route::rule('getContractList', 'User/getContractList');
+    //甲方创建合约
+    Route::rule('form_save', 'User/form_save');
+    //甲方签约合约
+    Route::rule('check', 'User/check');
+    //乙方确认
+    Route::rule('to_check', 'User/to_check');
+    //员工签到
+    Route::rule('clock_in', 'User/clock_in');
+    //添加客户评论
+    Route::rule('comment', 'User/comment');
     
 
     

+ 14 - 0
app/model/api/ContractComment.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ContractComment extends Model
+{
+    //
+}

+ 42 - 0
app/model/api/ContractRecord.php

@@ -0,0 +1,42 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ContractRecord extends Model
+{
+    //合约列表
+    public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
+        $data =  $this
+//            ->field("p.*,ap.cate_name,ap.json")
+//            ->alias("p")
+//            ->join("adver_page ap",'ap.id=p.page_id')
+            ->when(!empty($where),function ($query) use($where){
+                if(!empty($where['uid'])) {
+                    $query->where('uid',$where['uid']);
+                }
+                if(!empty($where['title'])) {
+                    $query->wherelike('p.title','%' . $where['title'] . '%');
+                }
+
+                if(isset($where['sassid'])) {
+                    $query->where('p.sassid',$where['sassid']);
+                }
+            })
+            ->order($desc)
+            ->paginate(['list_rows'=>$pageCount,'page'=>$page])
+            ->toArray();
+        foreach ($data['data'] as $k=>$v) {
+            $data['data'][$k]['time'] = date('Y-m-d',$v['time']);
+            $data['data'][$k]['jsonAr'] =  json_decode($v['data'],true);
+        }
+        //echo $this->getLastSql();
+        return [$data['total'],$data['data']];
+    }
+
+}

+ 14 - 0
app/model/api/UserClock.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserClock extends Model
+{
+    //
+}

+ 610 - 0
app/system/controller/Contract.php

@@ -0,0 +1,610 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller;
+
+
+use app\BaseController;
+use app\lib\OrderLib;
+use app\model\api\ArticleModel;
+use app\model\api\InfoAudit;
+use app\model\api\PayTrade;
+use library\utils\WxpayV2 as wxpayApi;
+use app\model\api\User as UserModel;
+use app\model\api\ContractRecord as UserContractRecordModel;
+use app\model\api\UserClock as UserClockModel;
+use app\model\api\ContractComment as ContractCommentModel;
+use app\model\api\UserDetail as UserDetailModel;
+use app\model\api\UserScoreDetail as UserScoreDetailModel;
+use app\model\api\UserShowTemplate;
+use library\services\UtilService;
+use app\Request;
+use think\facade\Db;
+
+class Contract extends BaseController
+{
+    /**
+     * 合同列表
+     * @param Request $request
+     * @return
+     */
+    public function UserClockList(Request $request)
+    {
+        $pageSize = 50;
+        $post = UtilService::getMore(
+            [
+                ['page', 1],
+                ['phone',0],  //甲方uid或者电话
+                ['to_phone',''], //乙方uid或者电话
+                ['contract_no', ''],
+                ['status',''],
+                ['time',[]],
+            ], $request
+        );
+        $where = [];
+        if(!empty($post['phone'])){
+            $where[]=["phone","=",$post['phone']];
+        }
+//        else
+//            if(!empty($post['mobile'])){
+//            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+//            if(!empty($m)) {
+//                $where[]=["o.uid","=",$m['uid']];
+//            }
+//        }
+        if(!empty($post['to_phone'])){
+            $where[]=["to_phone","=",$post['to_phone']];
+        }
+        if(!empty($post['contract_no'])){
+            $where[]=["contract_no","=",$post['contract_no']];
+        }
+        if(!empty($post['status'])){
+            $where[]=["status","=",$post['status']];
+        }
+
+//        if(in_array((string)$post['status'],["0","1","-1"])){
+//            $where[]=["status","=",(int)$post['status']];
+//        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["check_time","between","{$startTime},{$endTime}"];
+        }
+        $order = new UserContractRecordModel();
+
+        $data  = $order
+//            ->alias("o")
+//            ->field("*,u1.mobile,u1.nickname,a.title as show_template_title,a.imgs as show_template_imgs")
+//            ->leftJoin("user u1","u1.uid = uid")
+//            ->leftJoin("show_template a","a.id = show_template_id")
+            ->field('*')
+            ->where($where)
+            ->page((int)$post["page"], $pageSize)
+            ->order("id","desc")
+            ->select()
+            ->toArray();
+        $pageCount = $order->where($where)->count();
+
+        $result = UtilService::getParam([
+            "id",
+            "contract_no",
+            "uid",
+            "phone",
+            "address",
+            "card",
+            "to_uid",
+            "to_phone",
+            "to_address",
+            "to_card",
+            "status",
+            "from_check",
+            "to_check",
+            "uid_img",
+            "to_uid_img",
+            "price",
+            "deposit",
+            "balance",
+            "content",
+            "period",
+//            "template_id",
+            ['start_time', 'start_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['end_time', 'end_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['create_time', 'create_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['delete_time', 'delete_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['check_time', 'check_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 合约详细
+     * @param Request $request
+     * @return mixed
+     */
+    public function getContractInfo(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id','','empty','参数错误']
+        ],$request,true);
+        $adminInfo = UserContractRecordModel::get(compact('id'));
+        return app('json')->success([
+            'id' => $id,
+            'contract_no' =>$adminInfo['contract_no'],
+            'uid' => $adminInfo['uid'],
+            'phone' => $adminInfo['phone'],
+            'address' => $adminInfo['address'],
+            'card' =>$adminInfo['card'],
+            'to_uid' => $adminInfo['to_uid'],
+            'to_phone' => $adminInfo['to_phone'],
+            'to_address' => $adminInfo['to_address'],
+            'to_card' => $adminInfo['to_card'],
+            'status' => $adminInfo['status'],
+            'from_check' => $adminInfo['from_check'],
+            'to_check' => $adminInfo['to_check'],
+            'uid_img' => $adminInfo['uid_img'],
+            'to_uid_img' => $adminInfo['to_uid_img'],
+            'price' => $adminInfo['price'],
+            'deposit' => $adminInfo['deposit'],
+            'balance' => $adminInfo['balance'],
+            'content' => $adminInfo['content'],
+            'period' => $adminInfo['period'],
+            'start_time' => date('Y-m-d H:i:s', $adminInfo['start_time']),
+            'end_time' => date('Y-m-d H:i:s', $adminInfo['end_time']),
+            'create_time' => date('Y-m-d H:i:s', $adminInfo['create_time']),
+            'delete_time' => date('Y-m-d H:i:s', $adminInfo['delete_time']),
+            'check_time' => date('Y-m-d H:i:s', $adminInfo['check_time']),
+//            'template_id' => $adminInfo['template_id'],
+
+        ]);
+    }
+    /**
+     * 签约列表
+     * @param Request $request
+     */
+    public function ContractRecordList(Request $request)
+    {
+        $pageSize = 50;
+        $post = UtilService::getMore(
+            [
+                ['page', 1],
+                ['uid',0],  //员工uid
+                ['nickname',''], //名称
+                ['contract_id', ''], //签约id
+                ['time',[]],
+            ], $request
+        );
+        $where = [];
+        if(!empty($post['uid'])){
+            $where[]=["uid","=",$post['uid']];
+        }
+//        else
+//            if(!empty($post['mobile'])){
+//            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+//            if(!empty($m)) {
+//                $where[]=["o.uid","=",$m['uid']];
+//            }
+//        }
+        if(!empty($post['nickname'])){
+            $where[]=["nickname","like",$post['nickname']];
+        }
+        if(!empty($post['contract_id'])){
+            $where[]=["contract_id","=",$post['contract_id']];
+        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["create_time","between","{$startTime},{$endTime}"];
+        }
+
+        $order = new UserClockModel;
+        $data  = $order
+//            ->alias("o")
+//            ->field("*,u1.mobile,u1.nickname,a.title as show_template_title,a.imgs as show_template_imgs")
+//            ->leftJoin("user u1","u1.uid = uid")
+//            ->leftJoin("show_template a","a.id = show_template_id")
+            ->field('*')
+            ->where($where)
+            ->page((int)$post["page"], $pageSize)
+            ->order("id","desc")
+            ->select()
+            ->toArray();
+        $pageCount = $order->where($where)->count();
+
+        $result = UtilService::getParam([
+            "id",
+            "uid",
+            "nickname",
+            "contract_id",
+            "longitude",
+            "latitude",
+
+            ['create_time', 'create_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+
+        ], $data);
+
+
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 评论列表
+     * @param Request $request
+     */
+    public function contractCommentList(Request $request)
+    {
+        $pageSize = 50;
+        $post = UtilService::getMore(
+            [
+                ['page', 1],
+                ['uid',0],  //员工uid
+                ['to_uid',''], //名称
+                ['contract_no', ''], //签约id
+                ['time',[]],
+            ], $request
+        );
+        $where = [];
+        if(!empty($post['uid'])){
+            $where[]=["uid","=",$post['uid']];
+        }
+//        else
+//            if(!empty($post['mobile'])){
+//            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+//            if(!empty($m)) {
+//                $where[]=["o.uid","=",$m['uid']];
+//            }
+//        }
+        if(!empty($post['nickname'])){
+            $where[]=["nickname","like",$post['nickname']];
+        }
+        if(!empty($post['contract_id'])){
+            $where[]=["contract_id","=",$post['contract_id']];
+        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["create_time","between","{$startTime},{$endTime}"];
+        }
+        $order = new ContractCommentModel();
+        $data  = $order
+//            ->alias("o")
+//            ->field("*,u1.mobile,u1.nickname,a.title as show_template_title,a.imgs as show_template_imgs")
+//            ->leftJoin("user u1","u1.uid = uid")
+//            ->leftJoin("show_template a","a.id = show_template_id")
+            ->field('*')
+            ->where($where)
+            ->page((int)$post["page"], $pageSize)
+            ->order("id","desc")
+            ->select()
+            ->toArray();
+        $pageCount = $order->where($where)->count();
+
+        $result = UtilService::getParam([
+            "id",
+            "contract_no",
+            "uid",
+            "to_uid",
+            ['create_time', 'create_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    // 删除评论
+    public function deleteComment(\think\Request $request)
+    {
+        $id = $request->param('id');
+        $article = ContractCommentModel::where('id', $id)->find();
+        if (!$article) {
+            return app('json')->fail('评论不存在');
+        }
+        $article->delete();
+        return app('json')->success();
+    }
+
+
+
+
+
+    /**
+     * 合约列表
+     * @param \app\Request $request
+     * @return mixed
+     */
+    public function getContractList(\think\Request $request)
+    {
+//        $pageSize = 50;
+//        $post =  UtilService::getMore([
+//            ['page',1],
+//            ['pageSize',50],
+//            ['nickname',''],
+////            ['uid',''],
+//            ['parent_uid',''],
+//            ['mobile',''],
+//            ['status',''],
+//            ['time',[]],
+//        ],$request);
+////        $post['uid']=$request->user["uid"];
+//        $data = (new UserModel)->getDataList($post,"*",1);
+//        return app('json')->success([
+//            'list'      => $data["list"],
+//            'pageCount' => $data["totalCount"],
+//            'pageSize'  => $data["pageSize"],
+//            'page'      => $data["page"],
+//        ]);
+        $post = UtilService::getMore([
+            ['page', 1],
+            ['pageSize', 50],
+            ['status',-2] //1未签约 2已签约 3已解约
+        ], $request);
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0 ? 1 : (int)$post["page"];
+        $where=[];
+        $where[]=["uid","=",$request->user["uid"]];
+        $totalCount = (new UserContractRecordModel)->where($where)->count();
+        if ($post["status"]!=-2){
+            $where[]=['status','=',$post["status"]];
+        }
+        $data=null;
+        if($totalCount>0){
+            $data = (new UserContractRecordModel)
+//                ->field("")
+//                ->alias("ut")
+//                ->join("show_template t", "t.id = show_template_id","left")
+                ->where($where)
+                ->order("is_default", "desc")
+                ->order("id", "desc")
+                ->page($post["page"], $post["pageSize"])
+                ->select();
+            foreach($data as $k=>$v){
+                $data[$k]["is_use"]      = 1;//是否已经购买或者可以使用
+                switch ($data[$k]["status"]){
+                    case 0:
+                        $data[$k]["status_name"] = "未签约";
+                        break;
+                    case 1:
+                        $data[$k]["status_name"] = "已签约";
+                        break;
+                    case -1:
+                        $data[$k]["status_name"] = "已解约";
+                        break;
+                }
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
+    }
+
+    /**
+     * 甲方创建合约
+     */
+    public function form_save(Request $request){
+        $post = UtilService::getMore([
+            ['uid','0'],  //甲方uid
+            ['phone',''],  //甲方手机号
+            ['address',''], //甲方地址
+            ['card',''], //甲方身份证号
+            ['to_uid','0'], //员工uid
+            ['price',0],  //服务费
+            ['deposit',0], // 定金
+            ['balance',0], //余款
+            ['period',0], // 周期天数
+            ['start_time',''], // 开始时间
+            ['end_time',''], // 结束时间
+
+//            ['uid_img','']  //甲方签名图片路径
+//            ['to_phone',''].
+//            ['to_address',''],
+//            ['to_card',''],
+//            ['data',[]],
+//            ['year',''],
+//            ['month',''],
+//            ['day',''],
+
+        ],$request);
+        $id = (int)$post["id"];
+
+        $uid = (int)$post["uid"];
+        if(empty($uid)){
+            return app('json')->fail("参数错误");
+        }
+//        $year = $post['year'];
+//        $month = $post['month'];
+//        $day = $post['day'];
+//
+//// 检查年月日是否为空
+//        if (empty($year) || empty($month) || empty($day)) {
+//            return app('json')->fail("日期参数错误");
+//        }
+//
+//// 创建 DateTime 对象
+//        $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
+//
+//// 检查日期是否有效
+//        if (!$date || $date->format('Y-m-d') !== "$year-$month-$day") {
+//            return app('json')->fail("无效的日期");
+//        }
+//        unset($post['year']);
+//        unset($post['month']);
+//        unset($post['day']);
+//// 转换为时间戳
+//        $timestamp = $date->getTimestamp();
+//
+//        $post['create_time'] = $timestamp;
+        //用户信息
+//        if(!empty($post["uid_img"])){
+//            $post['status'] = 2;
+//        }else{
+        $post['status'] = 0;
+//        }
+        if (empty($id)){
+            $post['contract_no'] = makeOrderId($post['uid'],"CR");
+            $r = (new UserContractRecordModel)->save($post);
+        }else{
+            $r = (new UserContractRecordModel)->where("id",$id)->update($post);
+        }
+
+        return app('json')->success("数据保存成功");
+    }
+    /**
+     * 甲方签约合约
+     */
+    public function check(Request $request){
+        $post = UtilService::getMore([
+            ['id',0],  //合约id
+            ['uid_img',''],  //甲方签名图片路径
+            ['check_time','']//签约时间
+//            ['to_phone',''].
+//            ['to_address',''],
+//            ['to_card',''],
+//            ['data',[]],
+//            ['year',''],
+//            ['month',''],
+//            ['day',''],
+
+        ],$request);
+        $info = (new UserContractRecordModel)->where("id",$post["id"])->find();
+        if(empty($info)){
+            return app('json')->fail("合约不存在");
+        }
+
+        // 检查签约时间是否为空
+        if (empty($post['uid_img'])) {
+            return app('json')->fail("签字错误");
+        }
+// 检查签约时间是否为空
+        if (empty($post['check_time'])) {
+            return app('json')->fail("日期参数错误");
+        }
+
+//        $post['status'] = 1;
+        $post['from_check'] = 1;
+        if ($info['to_check']==1){
+            $post['status']==1;
+        }
+
+//        $post['contract_no'] = makeOrderId($post['uid'],"CR");
+        $r = (new UserContractRecordModel)->where("id",$post["id"])->update($post);
+        return app('json')->success("数据保存成功");
+    }
+//    乙方确认
+    public function to_check(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],  //
+            ['to_uid_img',''],  //乙方签名图片路径
+            ['to_phone',''], //乙方手机号
+            ['to_address',''], //乙方地址
+            ['to_card',''], //乙方身份证号
+            ['to_check_time','']//签约时间
+        ],$request);
+        $info = (new UserContractRecordModel)->where("id",$post["id"])->find();
+        if(empty($info)){
+            return app('json')->fail("合约不存在");
+        }
+        // 检查签约时间是否为空
+        if (empty($post['to_uid_img'])) {
+            return app('json')->fail("签字错误");
+        }
+// 检查签约时间是否为空
+        if (empty($post['to_check_time'])) {
+            return app('json')->fail("日期参数错误");
+        }
+        $post['to_check'] = 1;
+        if ($info['from_check']==1){
+            $post['status']==1;
+        }
+        $r = (new UserContractRecordModel)->where("id",$post["id"])->update($post);
+        return app('json')->success("数据保存成功");
+    }
+//    员工签到
+    public function clock_in(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],  //合约id
+            ['longitude',''],  //经度
+            ['latitude',''],  //纬度
+
+        ],$request);
+        $uid = (int)$post["uid"];
+        // 检查签约时间是否为空
+        if (empty($post['id'])) {
+            return app('json')->fail("签字错误");
+        }
+        $nickname=\app\model\api\User::where('uid',$uid)->value('nickname');
+        $r = (new UserContractRecordModel)->where("id",$post["id"])->save([
+            'uid'=>$uid,
+            'nickname' => $nickname,
+            'longitude'=>$post['longitude'],
+            'latitude'=>$post['latitude'],
+            'contract_id'=>$post['id'],
+            'create_time'=>time()
+        ]);
+        return app('json')->success("数据保存成功");
+    }
+//  添加客户评论
+    public function comment(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],  //合约id
+            ['content',''],  //评论内容
+        ],$request);
+        $uid = (int)$post["uid"];
+        $info = (new UserContractRecordModel)->where("id",$post["id"])->find();
+        if(empty($info)){
+            return app('json')->fail("合约不存在");
+        }
+        if ($info['status']!=1){
+            return app('json')->fail("只能在签约期间才能发表评论");
+        }
+        // 检查签约时间是否为空
+        if (empty($post['id'])) {
+            return app('json')->fail("签字错误");
+        }
+        $r = (new ContractCommentModel)->save([
+            'uid'=>$uid,
+            'contract_id'=>$post['id'],
+            'content'=>$post['content'],
+            'create_time'=>time()
+        ]);
+        return app('json')->success("数据保存成功");
+    }
+}

+ 25 - 0
app/system/route/contract.php

@@ -0,0 +1,25 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:52
+// +----------------------------------------------------------------------
+use think\facade\Route;
+
+//@广告栏目
+Route::group('contract', function () {
+    //员工签到列表
+    Route::post('UserClockList', 'contract/UserClockList');
+
+    
+
+
+})->middleware([
+    \app\system\middleware\AllowOriginMiddleware::class,
+    \app\system\middleware\AdminAuthTokenMiddleware::class,
+    \app\system\middleware\AdminCkeckRoleMiddleware::class
+]);