| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- <?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 ContractRecordList(Request $request)
- {
- $pageSize = 50;
- $post = UtilService::getMore(
- [
- ['page', 1],
- ['phone',''], //甲方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",
- "end_time",
- "create_time",
- "delete_time",
- "check_time",
- // ['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','']
- ],$request,true);
- $adminInfo = UserContractRecordModel::where("id",$id)->find()->toArray();
- 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' =>$adminInfo['start_time'],
- 'end_time' =>$adminInfo['end_time'],
- 'create_time' =>$adminInfo['create_time'],
- 'delete_time' =>$adminInfo['delete_time'],
- 'check_time' =>$adminInfo['check_time'],
- // '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 UserClockList(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', '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], //甲方
- ['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', '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("数据保存成功");
- }
- }
|