| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380 |
- <?php
- // +----------------------------------------------------------------------
- // | [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018-2020 rights reserved.
- // +----------------------------------------------------------------------
- // | Author: TABLE ME
- // +----------------------------------------------------------------------
- // | Date: 2020-08-25 17:23
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- 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;
- use app\model\api\InfoAudit;
- use app\model\api\TypeAudit;
- use app\model\api\UserAudit;
- use app\model\api\ServiceType;
- use app\model\api\ServiceLabel as ServiceLabelModel;
- use app\model\api\ServiceTimeType;
- use app\model\api\City as CityModel;
- use app\model\api\Sys as SysModel;
- use app\model\api\ShowTemplate;
- use app\model\api\ShowTemplateOrder;
- use app\model\api\UserShowTemplate;
- use app\model\api\UserWorkType;
- use app\model\api\PayTrade as PayTradeModel;
- use app\api\controller\pub;
- use app\Request;
- use library\services\UtilService;
- use library\utils\QRcodeComm;
- use library\utils\Qiniu;
- use library\utils\IdentityCard;
- use library\utils\WxpayV2 as wxpayApi;
- use think\db\exception\DbException;
- use library\lib\weixina;
- use think\facade\Db;
- use think\Image;
- use think\Route;
- use think\Collection;
- class User extends BaseController
- {
- /**
- * 获取用户详情
- * @param Request $request
- */
- public function userInfo(Request $request){
- //资料审核信息
- $infoAuditData = (new InfoAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
- $userAuditData = (new UserAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
- $typeAuditData = (new TypeAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
- $data = [];
- $data['uid'] = $request->user['uid'];
- $data['nickname'] = $request->user['nickname'];
- $data['mobile'] = $request->user['mobile'];
- $data['avatar'] = $request->user['avatar'];
- $data['name'] = $request->user['name'];
- $data['sex'] = $request->user['sex'];
- $data['type'] = $request->user['type'];//用户类型
- $data['type_name'] = "";//用户类型名称
- $data['work_type_id'] = $request->user['work_type_id'];//用户职称类型
- $data['work_type_title'] = $request->user['work_type_title'];//用户职称类型名称
- $data['card_look_count'] = $request->user['card_look_count'];//用户名片浏览次数
- $data['info_audit_status'] = empty($infoAuditData)?-2:$infoAuditData["status"];
- $data['user_audit_status'] = empty($userAuditData)?-2:$userAuditData["status"];
- $data['type_audit_status'] = empty($typeAuditData)?-2:$typeAuditData["status"];
- //资料通过需要重新提交认证
- if(!empty($infoAuditData) && !empty($typeAuditData)){
- if($infoAuditData["status"]==1 && $typeAuditData["status"]==1 && $infoAuditData["admin_time"]>$typeAuditData["admin_time"]){
- $data['type_audit_status'] = -3;
- }
- }
- $data['show_template_code'] = "";
- $data['show_template_id'] = "";
- $tmpData = (new UserShowTemplate)
- ->field("t.id,t.code,t.title,t.is_init,b.is_default")
- ->alias("b")
- ->join("show_template t","t.id = b.show_template_id","left")
- ->where("b.uid",$request->user['uid'])
- ->order("b.is_default","desc")
- ->order("b.id","desc")
- ->find();
- if(!empty($tmpData)){
- $data['show_template_code'] = $tmpData["code"];
- $data['show_template_id'] = $tmpData["id"];
- $data['show_template_init'] = $tmpData["is_init"];
- $data['show_template_default'] = $tmpData["is_default"];
- }
- return app('json')->success($data);
- }
- /**
- * 获取用户子级列表
- * @param Request $request
- */
- public function getChildList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $post["parent_uid"]= $request->user["uid"];
- $data = (new UserModel)->getDataList($post,"u.uid,u.mobile,u.nickname,u.avatar");
- $list = $data["list"];
- foreach ($list as &$item) {
- $userInfo = $this->getUserInfo($item["uid"]);
- $item["is_type_audit"] = $userInfo["is_type_audit"];
- $item["ancestral_place"] = $userInfo["ancestral_place"];
- $item["auth_info"] = $userInfo["auth_info"];
- $item["user_work_type_id"] = $userInfo["user_work_type_id"];
- }
- $data["list"] = $list;
- return app('json')->success($data);
- }
- /**
- * 获取用户总邀请人数排行榜
- * @param Request $request
- */
- public function getInviterRanking(Request $request)
- {
- $time = $request->param('time');
- $times = $request->param('times');
- $users = (new UserModel())
- ->where('parent_uid', '<>', 0)
- ->where('regtime', '>=', $time)
- ->where('regtime', '<=', $times)
- ->field('parent_uid as uid, count(*) as invite_count')
- ->group('parent_uid')
- ->order('invite_count', 'desc')
- ->select();
- $rankList = [];
- foreach ($users as $key => $value) {
- $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
- if (!$userInfo['nickname']) {
- continue;
- }
- $auth = (new InfoAudit)->where('uid', $value['uid'])->find();
- $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
- if ($auth) {
- $auth_info = $auth->toArray();
- } else {
- $auth_info = null;
- }
- $rankList[] = [
- 'rank' => $key + 1,
- 'uid' => $value['uid'],
- 'nickname' => $userInfo['nickname'],
- 'avatar' => $userInfo['avatar'],
- 'invite_count' => $value['invite_count'],
- 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
- 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
- 'auth_info' => $auth_info,
- 'user_work_type_id' => $user_work_type_title['title'],
- ];
- }
- $inviteCount = array_column($rankList, 'invite_count');
- $uid = array_column($rankList, 'uid');
- array_multisort($inviteCount, SORT_DESC, $uid, SORT_ASC, $rankList);
- $data['list'] = $rankList;
- return app('json')->success($data);
- }
- /**
- * 设置用户信息
- * @param Request $request
- */
- public function setUserInfo(Request $request){
- $post = UtilService::getMore([
- ['avatar',''],
- ['nickname',''],
- ['name',''],
- // ['mobile',''],
- ['sex', ''],
- ],$request);
- $save=[];
- if(!empty($post["avatar"])){
- $save["avatar"] = $post["avatar"];
- }
- if(!empty($post["nickname"])){
- $save["nickname"] = $post["nickname"];
- }
- if(!empty($post["name"])){
- $save["name"] = $post["name"];
- }
- // if(!empty($post["mobile"])){
- // if(is_mobile($post["mobile"])){
- // return app("json")->fail("请输入正确的手机号码");
- // }
- // $save["mobile"] = $post["mobile"];
- // }
- if(in_array((string)$post["sex"],["0","1","2"])){
- $save["sex"] = (int)$post["sex"];
- }
- if(empty($save)){
- return app("json")->fail("提交数据为空");
- }
- //是否需要审核
- $isInfoAudit = 0;
- if($isInfoAudit==0){
- $r = (new UserModel)->where("uid",$request->user["uid"])->update($save);
- if(!$r){
- return app("json")->fail("提交数据为空");
- }
- }else{
- $data = (new UserAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
- if(!empty($data) && $data["status"]==0){
- return app('json')->fail("资料审核中,请勿重复提交");
- }
- $save["uid"] = $request->user["uid"];
- $save["status"] = 0;
- $r = (new UserAudit)->insert($save);
- if(!$r){
- return app("json")->fail("提交数据为空");
- }
- }
- return app("json")->success("提交成功");
- }
- /**
- * 绑定手机号
- * @param Request $request
- */
- public function bindMobile(Request $request){
- [$code] = UtilService::getMore([
- ['code', '', 'empty', 'code参数错误'],
- ], $request, true);
- if(!empty($request->user['mobile'])){
- return app('json')->fail("当前账户已绑定过手机号码");
- }
- $weixinA = new weixina();
- $data=$weixinA->getPhoneNumber($code);//新版
- if(empty($data) || empty($data['purePhoneNumber'])) {
- return app('json')->fail("绑定失败,请重新绑定01".$weixinA->error);
- }
- $save=[
- // "countryCode"=>empty($data['countryCode'])?"":$data['countryCode'],
- "mobile"=>$data['purePhoneNumber'],
- ];
- // if($request->user["nickname"]=="微信用户"){
- // $save["nickname"] = $data['purePhoneNumber'];
- // }
- $r = (new UserModel)->where('uid', $request->user['uid'])->update($save);
- if(!$r){
- return app('json')->fail("绑定失败,请重新绑定02");
- }
- $result = [];
- $result['nickname'] = $request->user['nickname'];
- $result['avatar'] = $request->user['avatar'];
- return app('json')->success($result);
- }
- /**
- * 获取名片信息
- * @param Request $request
- */
- public function getUserCardInfo(Request $request){
- $data = (new InfoAudit)->getItem(["uid"=>$request->user["uid"],"status"=>1]);
- if(empty($data)){
- return app('json')->fail("您还没有通过名片信息审核");
- }
- $typeData = (new TypeAudit)->where("uid",$request->user["uid"])->order("id","desc")->find();
- $data["is_type_audit"] = (empty($typeData) || $typeData["status"]!=1)?0:1;
- return app('json')->success($data);
- }
- /**
- * 提交资料审核
- * @param Request $request
- */
- public function subInfoAudit(Request $request){
- $data = (new InfoAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
- if(!empty($data) && $data["status"]==0){
- return app('json')->fail("资料审核中,请勿重复提交");
- }
- $post = UtilService::getMore([
- ['avatar',''],
- ['name','','empty','请输入真实姓名'],
- ['mobile','','is_moblie','请输入正确的手机号码'],
- ['idcard','','empty','请输入正确的身份证号码'],
- ['birthday',''],
- ['service_type',''],
- ['service_price',''],
- ['service_min_price',''],
- ['service_max_price',''],
- ['service_area',[]],
- ['service_project',[]],
- ['service_intro_content',''],
- ['service_intro_imgs',[]],
- ['service_audit_imgs',[]],//此处为我的证书
- ['service_imgs',[]],//我的服务照片
- ['service_count',0],
- ['work_year',''],
- ['ancestral_place',''],
- ['education',''],
- ['minority',''],
- ['is_china',1],
- ['user_work_type_id','0'],//服务职称
- ['service_label',[]],//服务标签
- ],$request);
- if(!IdentityCard::isValid($post["idcard"])){
- return app('json')->fail("请输入正确的身份证号码");
- }
- $save=[];
- $save["avatar"] = empty($post["avatar"]) ? "" : $post["avatar"];
- $save["name"] = empty($post["name"]) ? "" : $post["name"];
- $save["mobile"] = empty($post["mobile"]) ? "" : $post["mobile"];
- $save["idcard"] = empty($post["idcard"]) ? "" : $post["idcard"];
- $save["service_count"] = $post['service_count'];
- // $save["birthday"] = empty($post["birthday"])? 0 : strtotime($post["birthday"]);
- $save["constellation"] = IdentityCard::get_starsign($post["idcard"]);//星座
- $save["twelve"] = IdentityCard::get_zodiac($post["idcard"]);//星座
- $save["birthday"] = strtotime(IdentityCard::get_birthday($post["idcard"]));
- //服务类型
- if(!empty($post["service_type"])){
- $timeTypeData = (new ServiceTimeType)->where("code",$post["service_type"])->where("status",1)->select();
- if(empty($timeTypeData)){
- return app('json')->fail("服务时长类型不存在");
- }
- $save["service_type"] = $post["service_type"];
- }
- //服务价格区间
- // $save["service_price"] = empty($post["service_price"]) ? "" : $post["service_price"];
- $save["service_min_price"] = empty($post["service_min_price"]) ? 0 : $post["service_min_price"];
- $save["service_max_price"] = empty($post["service_max_price"]) ? 0 : $post["service_max_price"];
- //服务区域
- $cityModel = new CityModel();
- if(!empty($post["service_area"]) && is_array($post["service_area"])){
- $saveAre=[];
- foreach($post["service_area"] as $v){
- $stc = str_replace(['省','市','区','县'],['','','',''],$v);
- $str = str_replace(['辖'],['市辖'],$stc);
- $arr = explode(",",$str);
- $city_id = $cityModel->where('merger_name','like',"%".$arr[1].",".$arr[2])->value('id');
- if(!$city_id) $city_id = $cityModel->where('merger_name','like',"%".$arr[0].",".$arr[1])->value('id');
- $saveAre[] = $city_id;
- }
- if(!empty($saveAre)){
- $save["service_area"] = implode(",", $saveAre);
- }
- }
- // //服务区域
- // $cityModel = new CityModel();
- // if(!empty($post["service_area"]) && is_array($post["service_area"])){
- // $saveAre=[];
- // foreach($post["service_area"] as $v){
- // @file_put_contents('dub.txt','1');
- // $arr = explode(",",$v);
- // $str1 = $arr[0].','.$arr[1];
- // @file_put_contents('dub.txt','2');
- // $stc = str_replace(['省','市','区','县'],['','','',''],$str1);
- // $str2 = $stc.",".$arr[2]!='市辖区'?str_replace(['省','市','区','县'],['','','',''],$arr[2]):'市辖区';
- // $arr3 = explode(",",$str2);
- // $city_id = $cityModel->where('merger_name','like',"%".$arr3[1].",".$arr3[2])->value('id');
- // @file_put_contents('dub.txt','3');
- // if(!$city_id)
- // {
- // $city_id = $cityModel->where('merger_name','like',"%".$arr3[0].",".$arr3[1])->value('id');
- // $city_id1 = $cityModel->where('merger_name','like',"%".$arr3[0].",".$arr3[1])->value('city_id');
- // $city_id2 = $cityModel->where('parent_id',$city_id1)->where('name','市辖区')->value('id');
- // if($city_id2>0) $city_id= $city_id2;
- // }
- // @file_put_contents('dub.txt','4');
- // $saveAre[] = $city_id;
- //
- // }
- // if(!empty($saveAre)){
- // $save["service_area"] = implode(",", $saveAre);
- // }
- // }
- //服务内容
- $serviceTypeModel = new ServiceTypeModel();
- if(!empty($post["service_project"]) && is_array($post["service_project"])){
- $saveCon=[];
- foreach($post["service_project"] as $k=>$v){
- if(empty(trim($v))){
- continue;
- }
- $itemData = $serviceTypeModel->where("id",(int)$v)->where("status",1)->find();
- if(!empty($itemData)){
- $saveCon[]=$itemData["id"];
- }
- }
- if(!empty($saveCon)){
- $save["service_project"] = implode(",", $saveCon);
- }
- }
- //服务标签
- $save["service_label"]="";
- $labelData = (new ServiceLabelModel)->getColumnList("id","id",$post["service_label"]);
- if(!empty($labelData)){
- $save["service_label"] = implode(",", $labelData);
- }
- $save["service_intro_content"] = empty($post["service_intro_content"])? "" : $post["service_intro_content"];
- $save["service_intro_imgs"] = empty($post["service_intro_imgs"]) ? "" : implode(",", $post["service_intro_imgs"]);
- $save["service_audit_imgs"] = empty($post["service_audit_imgs"]) ? "" : implode(",", $post["service_audit_imgs"]);
- $save["service_imgs"] = empty($post["service_imgs"]) ? "" : implode(",", $post["service_imgs"]);//我的服务展示
- $save['work_year'] = empty($post["work_year"]) ? "": $post["work_year"];
- $save['ancestral_place'] = empty($post["ancestral_place"])? "": $post["ancestral_place"];
- $save['education'] = empty($post["education"]) ? "": $post["education"];
- $save['minority'] = empty($post["minority"]) ? "": $post["minority"];
- $save["status"] = 1;
- $save["time"] = time();
- $save["uid"] = $request->user["uid"];
- $save['is_china'] = $post["is_china"];
- //服务职称
- $save["user_work_type_id"] = empty($post["user_work_type_id"]) ? 0: (int)$post["user_work_type_id"];
- if($save["user_work_type_id"]>0 && (new UserWorkType)->where("id",$post["user_work_type_id"])->where("status",1)->count()<=0){
- return app('json')->fail("当前类型不能选择");
- }
- //生成编码
- $r = (new InfoAudit)->insertGetId($save);
- if (!$r) {
- return app('json')->fail("系统错误");
- }
- $exist = (new InfoAudit)->where('uid', $save['uid'])->find();
- if ($exist && !empty($exist['no'])) {
- $no = $exist['no'];
- } else {
- $id = str_pad($r, 5, "0", STR_PAD_LEFT);
- $no = "MYJ" . date("ym") . $id;
- }
- (new InfoAudit)->where("id", $r)->update(["no" => $no]);
- (new InfoAudit)->where("id", $r)->update(["status" => 1]);
- return app('json')->success("提交成功,数据已通过审核");
- }
- /**
- * 平台认证
- * @param Request $request
- */
- public function subTypeAudit(Request $request){
- $data = (new TypeAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
- if(!empty($data) && $data["status"]==0){
- return app('json')->fail("平台审核中,请勿重复提交");
- }
- $post = UtilService::getMore([
- ['service_audit_imgs',[],"empty","请上传服务认证截图"],
- ['store_name','','',''],
- ],$request);
- $save=[];
- $save["service_audit_imgs"] = is_array($post["service_audit_imgs"]) ? implode(",", $post["service_audit_imgs"]) : "";
- $save["store_name"] = empty($post["store_name"]) ? "" : $post["store_name"];
- $save["status"] = 0;
- $save["time"] = time();
- $save["uid"] = $request->user["uid"];
- if(empty($save["service_audit_imgs"])){
- return app('json')->fail("请上传服务认证截图");
- }
- $r = (new TypeAudit)->insertGetId($save);
- if(!$r){
- return app('json')->fail("系统错误");
- }
- $no = "CERT-".date("YmdHis")."-".$r;
- (new TypeAudit)->where("id",$r)->update(["no"=>$no]);
- return app('json')->success("提交成功,请耐心等待审核");
- }
- /**
- * 模板订单提交[第一步]
- * @param Request $request
- */
- public function subShowTemplateOrder(Request $request){
- [$id,$pay_type] = UtilService::getMore([
- ['id','','empty','参数错误'],
- ['pay_type','','empty','请选择支付方式'],
- ],$request,true);
- if(!in_array($pay_type,["wxpay","balance"])){
- return app('json')->fail('不支持该支付方式!');
- }
- $weixinConfig = (new SysModel)->getWeixinConfig();
- // if(empty($weixinConfig)){
- // return app('json')->fail('支付配置为空!');
- // }
- //缓存
- $redis = \think\facade\Cache::store('redis');
- $key = 'show_template_order_sub_' . $request->user['uid'];
- $bool = $redis->handler()->exists($key);
- if ($bool) {
- return app('json')->fail('请务重复操作,请稍等在重试!');
- }
- $redis->set($key,1,5);//5秒缓存
- $proData = (new ShowTemplate)->where("id",$id)->where("status",1)->find();
- if(empty($proData)){
- return app('json')->fail("当前模板已下架");
- }
- $proData = $proData->toArray();
- $count = (new UserShowTemplate)->where("uid",$request->user['uid'])->where("show_template_id",$id)->count();
- if($count>0){
- return app('json')->fail("您已购买过当前模板");
- }
- //验证
- $orderCount = (new ShowTemplateOrder)->where("uid",$request->user['uid'])->where("show_template_id",$id)->where("status",1)->count();
- if($orderCount>0){
- return app('json')->fail("您已下单该模板,请勿重复下单");
- }
- $price = floatval($proData["price"]);
- // if($price<0.01){
- // return app('json')->fail("模板信息错误");
- // }
- $allMoney = $price;//订单商品费用
- $total_money = $allMoney;//订单总费用
- $payMoney = $total_money;//订单需支付费用
- $payMoney = $payMoney <= 0 ? 0 : $payMoney;
- $nowTime = time();
- //余额支付验证
- if($pay_type=="balance" && $payMoney > $request->user["money"]){
- return app('json')->fail("当前余额不足");
- }
- //主订单数据
- $save=[];
- $save['uid'] = $request->user['uid'];
- $save['order_id'] = makeOrderId($request->user['uid'],"ST");
- $save['pay_type'] = $pay_type;//
- $save['total_money'] = $total_money;//订单总金额
- $save['all_money'] = $allMoney;//商品中金额
- $save['pay_money'] = $payMoney;//实际支付金额
- $save['balance'] = 0;//余额支付了多少(目前不用)
- $save['status'] = $payMoney <= 0 ? 1 : 0;
- $save['pay_time'] = $payMoney <= 0 ? time() : 0;
- $save['time'] = $nowTime;
- $save['show_template_id'] = $proData["id"];
- $save['show_template_title'] = $proData["title"];;
- $save['show_template_price'] = $proData["price"];
- $save['show_template_img'] = empty($proData["imgs"]) ? "" : explode(",", $proData["imgs"])[0];
- $save['show_template_code'] = $proData["code"];
- //余额实时支付
- if($pay_type=="balance"){
- $save['status'] = 1;
- $save['pay_time'] = time();
- }
- try{
- Db::startTrans();
- $o_id = (new ShowTemplateOrder)->insertGetId($save);
- if(empty($o_id)){
- return app('json')->fail("订单提交失败");
- }
- //不需要支付
- if($payMoney<=0 && $save['status']==1){
- //验证并绑定当前模板
- (new UserShowTemplate)->userBindTemp($save["show_template_id"],$save['uid']);
- Db::commit();
- return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
- }
- //余额支付
- if($pay_type=="balance"){
- //验证并绑定当前模板
- (new UserShowTemplate)->userBindTemp($save["show_template_id"],$save['uid']);
- //修改用户余额
- $res = (new UserDetailModel)->balancePay($request->user["uid"],$payMoney,"show_temp_pay",["to_id"=>$o_id]);
- if(!$res){
- Db::rollback();
- return app('json')->fail("余额支付失败");
- }
- Db::commit();
- return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
- }
- //微信支付
- if(empty($request->user['openid'])){
- Db::rollback();
- return app('json')->fail('用户还未绑定微信!');
- }
- //清理之前支付凭证 || 防止重复购买
- $payTrade = (new PayTradeModel)
- ->where("uid",$request->user["uid"])
- ->where("o_id",$o_id)
- ->where("type","temp")
- ->where("status",0)
- ->where("time","<",time() - 7*24*60*60)
- ->select()
- ->toArray();
- $wxpay = new wxpayApi();
- // $wxpay = new wxpayApi($weixinConfig);
- foreach ($payTrade as $v) {
- // if($v['pay_type'] == 'wxpay') {
- // $result = $wxpay->closeOrder($v['pay_no']);
- // }
- (new PayTradeModel)->where("id",$v['id'])->where("status",0)->delete();
- }
- $mtime = microtime(true)*10000;
- $payOn = "T".date("Ymd").$mtime .rand(100,999) . $request->user['uid'];
- $out_trade_no="";
- $payType = $save["pay_type"];
- //添加交易记录
- $trade = [
- 'uid' => $request->user['uid'],
- 'o_id' => $o_id,
- 'order_id' =>$save["order_id"],
- 'pay_no' => $payOn,
- 'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
- 'pay_type' => $payType,
- 'money' => $payMoney,
- 'type' => 'temp',
- 'd_json' => serialize(['orderId'=>$save["order_id"],"give_score"=>0]),
- 'time' => time(),
- 'status' => 0,
- ];
- $r=(new PayTradeModel)->insert($trade);
- if(!$r){
- Db::rollback();
- return app('json')->fail('支付信息获取失败!');
- }
- $clictip = get_client_ip();
- if(empty($clictip)){
- $clictip = $request->ip();
- }
- $payData = $wxpay->wxmpPay([
- 'body' => "微信小程序购买模板",
- 'out_trade_no' => $payOn,
- 'total' => $payMoney,
- 'openid' => $request->user['openid'],
- 'payer_client_ip' => $clictip,
- ]);
- if(empty($payData)){
- Db::rollback();
- return app('json')->fail($wxpay->errorMsg);
- }
- Db::commit();
- $redis->delete($key);
- return app('json')->success([
- 'jsApiParameters'=> $payData,
- 'pay_no' => $payOn,
- 'order_id' => $save["order_id"],
- "status" => $save['status'],
- "money" => $payMoney,
- ]);
- } catch (DbException $db){
- Db::rollback();
- return app('json')->fail("订单生成失败");
- }
- }
- /**
- * 获取模板购买订单详情
- * @param Request $request
- */
- public function payShowTemplateOrderInfo(Request $request){
- [$order_id] = UtilService::getMore([
- ['order_id','','empty','参数错误'],
- ],$request,true);
- $data = (new ShowTemplateOrder)
- ->field("order_id,total_money,all_money,pay_money,status,time")
- ->where("order_id",$order_id)
- ->where("uid",$request->user["uid"])
- ->find();
- if(empty($data)){
- return app('json')->fail('信息不存在!');
- }
- $data=$data->toArray();
- if($data["status"]==0 && $data["time"]<time() - 30*60){
- (new ShowTemplateOrder)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
- $data["status"]==-1;
- }
- $data["time"] = date("Y-m-d H:i:s",$data["time"]);
- return app('json')->success($data);
- }
- /**
- * 用户模板列表
- * @param Request $request
- */
- public function userShowTemplateList(Request $request){
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $where=[];
- $where[]=["ut.uid","=",$request->user["uid"]];
- $totalCount = (new UserShowTemplate)->alias("ut")->where($where)->count();
- $data=null;
- if($totalCount>0){
- $data = (new UserShowTemplate)
- ->field("ut.id,t.id as show_template_id,t.title,t.price,t.old_price,t.status,t.imgs,t.is_hot,t.is_recommend,t.code,look_count,t.real_sales,t.unreal_sales,ut.is_default")
- ->alias("ut")
- ->join("show_template t", "t.id = ut.show_template_id","left")
- ->where($where)
- ->order("ut.is_default", "desc")
- ->order("ut.id", "desc")
- ->page($post["page"], $post["pageSize"])
- ->select();
- foreach($data as $k=>$v){
- $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
- $data[$k]["imgs"] = getImageAr($v["imgs"]);
- $data[$k]["img"] = empty($data[$k]["imgs"]) ? "" : $data[$k]["imgs"][0];
- $data[$k]["sales_count"] = $data[$k]["real_sales"] + $data[$k]["unreal_sales"];
- unset($data[$k]["real_sales"]);
- unset($data[$k]["unreal_sales"]);
- }
- }
- $data = empty($data)?[]:$data;
- return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
- }
- /**
- * 设置默认模板
- * @param Request $request
- */
- public function setShowTemplate(Request $request) {
- [$show_template_id] = UtilService::getMore([
- ['show_template_id', '', 'empty', '参数错误'],
- ], $request, true);
- (new UserShowTemplate)->where("uid", $request->user["uid"])->where("is_default", 1)->update(["is_default" => 0]);
- (new UserShowTemplate)->where("uid", $request->user["uid"])->where("show_template_id", $show_template_id)->update(["is_default" => 1]);
- return app('json')->success("设置成功");
- }
- /**
- * 获取邀请海报小程序码
- * @param Request $request
- */
- public function getWxmpInviteQrcode(Request $request){
- $inviteData = (new SysModel)->getDataInfo("invite");
- $bgimg = $inviteData["img"];
- if(!empty($request->user["invite_img"])){
- return app('json')->success(["qrcode"=>$request->user["invite_img"],"bgimg"=>$bgimg]);
- }
- $weixinA = new weixina();
- // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
- $data = $weixinA->getUnlimitedQRCode("pages/index/index",$request->user["uid"]);
- // var_dump($data);
- if(empty($data)){
- return app('json')->fail("小程序码获取失败".$weixinA->error);
- }
- $base64 = 'data:'.$data['contentType'].';base64,'.base64_encode($data['buffer']);
- $res = $this->uploadImageBase64("wximg",$base64,1);
- if($res["code"]!=1){
- return app('json')->fail($res["msg"]);
- }
- (new UserModel)->where("uid",$request->user["uid"])->update(["invite_img"=>$res["url"]]);
- return app('json')->success(["qrcode"=>$res["url"],"bgimg"=>$bgimg]);
- }
- // public function getWxmpInviteQrcode2(Request $request){
- //
- // //获取小程序码
- // $weixinA = new weixina();
- // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
- // if(empty($data)){
- // return app('json')->fail("小程序码获取失败".$weixinA->error);
- // }
- // $base64 = 'data:'.$data['contentType'].';base64,'.base64_encode($data['buffer']);
- // $code = "temp";
- // $sysData = (new SysModel())->where("id",1)->find();
- // $uploadConfig = config('filesystem');
- // //验证base64格式
- // preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
- // if(!$result){
- // return ["code"=>-1,"msg"=>"base64格式格式错误"];
- // }
- // //验证图片后缀
- // if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
- // return ["code"=>-1,"msg"=>"不支持的图片格式"];
- // }
- // $rootPath = config('filesystem.disks.resource.root');
- // $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
- // $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
- // $path = dirname($filePath);
- // // 检测目录
- // if (!is_dir($path)) {
- // if (!mkdir($path, 0777, true)) {
- // return ["code"=>-1,"msg"=>"生成目录失败"];
- // }
- // return ["code"=>-1,"msg"=>"上传目录不存在"];
- // }
- // //重名文件验证
- // if (is_file($filePath)) {
- // return ["code"=>-1,"msg"=>"文件已存在"];
- // }
- // if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
- // return ["code"=>-1,"msg"=>"文件报错失败"];
- // }
- //
- // //获取海报背景
- // $inviteData = (new SysModel)->getDataInfo("invite");
- // if(empty($inviteData["img"])){
- // return ["code"=>-1,"msg"=>"海报背景不存在"];
- // }
- // $bgimg =explode("resource", $inviteData["img"])[1];
- // if(empty($bgimg)){
- // return ["code"=>-1,"msg"=>"海报背景不存在"];
- // }
- //
- // $savePath = $rootPath. DIRECTORY_SEPARATOR .$code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true))."b".".jpg";
- //
- //
- //
- //
- // $bg = $rootPath.$bgimg;
- // $bgSize = getimagesize($bg);
- // $qrcodeSize = getimagesize($filePath);
- // $handle = Image::open($bg);
- // $handle->water($filePath,[($bgSize[0]-$qrcodeSize[0])/2,($bgSize[1]-$qrcodeSize[1])/2]);
- // $handle->save($savePath,"jpg",80);
- // $qiniu = new Qiniu;
- // $img_url = $qiniu->updateFile('img', $savePath, $savePath);
- // if (empty($img_url['url'])) {
- // return ["code"=>-1,"msg"=>"文件报错失败:".$qiniu->getError()];
- // }
- // @unlink($filePath);
- // @unlink($savePath);
- // return ["code"=>1,"url"=>str_replace("\\", "/", $img_url['url'])];
- // }
- //
- // public function checkImgPath(){
- //
- // }
- /**
- * 图片合成
- * @param type $bg
- * @param type $qrcode
- * @param type $savePath
- */
- public function createPosterImg($bg,$qrcode,$savePath){
- }
- /**
- * 获取小程序码
- * @param Request $request
- */
- public function getWxmpQrcode(Request $request){
- $weixinA = new weixina();
- $data = $weixinA->getUnlimitedQRCode("pages/index/index","a=1");
- if(empty($data)){
- return app('json')->fail("小程序码获取失败".$weixinA->error);
- }
- $base64 = 'data:'.$data['contentType'].';base64,'.base64_encode($data['buffer']);
- $res = $this->uploadImageBase64("wximg",$base64);
- if($res["code"]!=1){
- return app('json')->fail($res["msg"]);
- }
- return app('json')->success(["img"=>$res["data"]]);
- }
- /**
- *
- * @param Request $request
- */
- public function uploadBase64(Request $request){
- [$img,$code] = UtilService::getMore([
- ['img', '','empty',"请上传图片"],
- ['code', 'image'],
- ], $request,true);
- // $imgAr = explode("base64,",$img);
- // if(empty($imgAr)){
- // return app("json")->fail("请上传base64图片");
- // }
- // $imgBase64 = count($imgAr)==1?$imgAr[0]:$imgAr[1];
- // //判断字符串是否经过编码方法
- // if($imgBase64!=base64_encode(base64_decode($imgBase64))){
- // return app("json")->fail("请上传base64图片");
- // }
- // $base64 = "data:application/octet-stream;base64,".$imgBase64;//七牛
- $res = $this->uploadImageBase64($code,$img);
- if($res["code"]!=1){
- return app('json')->fail($res["msg"]);
- }
- return app('json')->success(["img"=>$res["data"]]);
- }
- /**
- * 图片上传
- * @param Request $request
- * @return type
- */
- public function upload(Request $request){
- $uploadConfig = config('filesystem');
- $sysData = (new SysModel())->where("id",1)->find();
- $file = $request->file('file');
- $code = $request->post("code","image");
- if(empty($file)) {
- return app('json')->fail("未上传文件");
- }
- $size = $file->getSize();
- if(!empty($size) && $size>$uploadConfig["image"]["size"]*1024*1024){
- return app('json')->fail("图片不能超过{$uploadConfig["image"]["size"]}M");
- }
- if(!in_array($code, $uploadConfig['image']['path'])){
- return app('json')->fail("上传路径错误");
- }
- $ext = $file->extension();
- if(!in_array($ext, $uploadConfig['image']['ext'])){
- return app('json')->fail("图片类型错误");
- }
- $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
- if(!$upPath){
- return app('json')->fail("上传失败01");
- }
- $savePath = $sysData['system_url'].'/resource/' . $upPath;
- $imgUrl = str_replace("\\", "/", $savePath);
- return app('json')->success(['img'=>$imgUrl,'size'=>$size]);
- }
- /**
- * 视频上传
- * @param Request $request
- * @return type
- */
- public function uploadVideo(Request $request){
- $uploadConfig = config('filesystem');
- $sysData = (new SysModel())->where("id",1)->find();
- $file = $request->file('file');
- $code = $request->post("code","video");
- if(empty($file)) {
- return app('json')->fail("未上传文件");
- }
- if(!in_array($code, $uploadConfig['video']['path'])){
- return app('json')->fail("上传路径错误");
- }
- $ext = $file->extension();
- if(!in_array($ext, $uploadConfig['video']['ext'])){
- return app('json')->fail("视频类型错误");
- }
- $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
- if(!$upPath){
- return app('json')->fail("上传失败01");
- }
- $savePath = $sysData['system_url'].'/resource/' . $upPath;
- $imgUrl = str_replace("\\", "/", $savePath);
- return app('json')->success(['video'=>$imgUrl]);
- }
- /**
- * base64文件上传
- * @param type $code
- * @param type $base64
- */
- public function uploadImageBase64($code,$base64,$isQiniu=0){
- $sysData = (new SysModel())->where("id",1)->find();
- $uploadConfig = config('filesystem');
- //验证base64格式
- preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
- if(!$result){
- return ["code"=>-1,"msg"=>"base64格式格式错误"];
- }
- //验证图片后缀
- if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
- return ["code"=>-1,"msg"=>"不支持的图片格式"];
- }
- $rootPath = config('filesystem.disks.resource.root');
- $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
- $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
- $path = dirname($filePath);
- // 检测目录
- if (!is_dir($path)) {
- if (!mkdir($path, 0777, true)) {
- return ["code"=>-1,"msg"=>"生成目录失败"];
- }
- return ["code"=>-1,"msg"=>"上传目录不存在"];
- }
- //重名文件验证
- if (is_file($filePath)) {
- return ["code"=>-1,"msg"=>"文件已存在"];
- }
- if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
- return ["code"=>-1,"msg"=>"文件报错失败"];
- }
- //七牛上传
- if($isQiniu==1){
- $qiniu = new Qiniu;
- $img_url = $qiniu->updateFile('img', $filePath, $filePath);
- if (empty($img_url['url'])) {
- return ["code"=>-1,"msg"=>"文件报错失败:".$qiniu->getError()];
- }
- @unlink($filePath);
- return ["code"=>1,"url"=>str_replace("\\", "/", $img_url['url'])];
- }
- $savePath = $sysData['system_url'].config('filesystem.disks.resource.url').DIRECTORY_SEPARATOR.$hashName;
- return ["code"=>1,"url"=>str_replace("\\", "/", $savePath)];
- }
- /**
- * 七牛上传图片
- * @param Request $request
- */
- public function qiniuUpload(Request $request)
- {
- $file = $request->file('file');
- if (empty($file)) {
- return app('json')->fail("未上传文件");
- }
- $rootTmp = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
- $image_size = @getimagesize($rootTmp);
- if ($image_size[0] > 1000) {
- $imgS = Image::open($rootTmp);
- $imgS->thumb(1000, $image_size[1]);
- $imgS->save($rootTmp);
- } else {
- if ($image_size[1] > 1000) {
- $imgS = Image::open($rootTmp);
- $imgS->thumb($image_size[0], 1000);
- $imgS->save($rootTmp);
- }
- }
- $qiniu = new Qiniu;
- $img_url = $qiniu->updateFile('img', $rootTmp, $rootTmp);
- if (empty($img_url['url'])) {
- return app('json')->fail($qiniu->getError());
- }
- @unlink($rootTmp);
- return app('json')->success(['img' => $img_url['url']]);
- }
- /**
- * 七牛上传token
- * @param Request $request
- */
- public function qiniuUploadToken(Request $request){
- [$bucket] = UtilService::getMore([
- ['bucket', ''],
- ], $request,true);
- $qiniu = new Qiniu;
- $token = $qiniu->createUploadToken($bucket);
- return app('json')->success(['token' => $token]);
- }
- /**
- * 获取用户模板信息
- * @param int $uid 用户ID
- * @return array
- */
- private function getUserInfo($uid)
- {
- $userInfo = (new UserModel)->where('uid', $uid)->find();
- $auth = (new InfoAudit)->where('uid', $uid)->find();
- $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
- if ($auth) {
- $auth_info = $auth->toArray();
- } else {
- $auth_info = null;
- }
- return [
- 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
- 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
- 'auth_info' => $auth_info,
- 'user_work_type_id' => $user_work_type_title['title'],
- ];
- }
- /**
- * 合约列表
- * @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=[];
- $totalCount = (new UserContractRecordModel)->where($where)->count();
- $uid= $request->user["uid"];
- if ($uid>0){
- $where[]=["uid","=",$uid];
- }
- 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();
- // var_dump((new UserContractRecordModel)->getLastSql());die();
- 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("数据保存成功");
- }
- }
|