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 = []; $uid = UtilService::getMore([ ['uid', 0], ], $request); $uid = $uid['uid']; // if ($uid>0){ // $where[]=["uid","=",$uid]; // } $totalCount = (new UserContractRecordModel)->where($where) ->when($uid > 0, function ($query) use ($uid) { $query->where(function ($query) use ($uid) { $query->where('uid', $uid) ->whereOr('to_uid', $uid); }); })->count(); if ($post["status"] != -2) { $where[] = ['status', '=', $post["status"]]; } $data = null; if ($totalCount > 0) { $data = (new UserContractRecordModel) ->where($where) ->when($uid > 0, function ($query) use ($uid) { $query->where(function ($query) use ($uid) { $query->where('uid', $uid) ->whereOr('to_uid', $uid); }); }) ->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[$k]["comment"] = (new ContractCommentModel())->where('contract_id',$v["id"])->select(); $data[$k]["comment"] = (new ContractCommentModel())->where('contract_id', $v["id"])->find(); if (!empty($data[$k]["comment"])) { $data[$k]["comment"] = $data[$k]["comment"]->toArray(); } } } $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([ ['id', 0], ['uid', '0'], //甲方uid ['name', ''], //甲方姓名 ['phone', ''], //甲方手机号 ['address', ''], //甲方地址 ['card', ''], //甲方身份证号 ['to_uid', 0], //员工uid ['to_name', ''], //乙方姓名 ['price', 0], //服务费 ['deposit', 0], // 定金 ['balance', 0], //余款 ['period', 0], // 周期天数 ['start_time', ''], // 开始时间 ['end_time', ''], // 结束时间 ['mark', ''], //备注 ['longitude', ''], //经度 ['latitude', ''] //纬度 // ['uid_img',''] //甲方签名图片路径 // ['to_phone','']. // ['to_address',''], // ['to_card',''], // ['data',[]], // ['year',''], // ['month',''], // ['day',''], ], $request); $id = (int)$post["id"]; unset($post["id"]); $uid = (int)$post["uid"]; if (empty($uid)) { return app('json')->fail("参数错误"); } $post['start_time'] = strtotime($post['start_time']); $post['end_time'] = strtotime($post['end_time']); $start = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('start_time', [$post['start_time'], $post['end_time']])->find(); $end = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('end_time', [$post['start_time'], $post['end_time']])->find(); // $start2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('start_time',[$post['start_time'],$post['end_time']])->find(); // $end2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('end_time',[$post['start_time'],$post['end_time']])->find(); // if (!empty($start)||!empty($end)||!empty($start2)||!empty($end2)){ if (!empty($start) || !empty($end)) { 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 ($id > 0) { $r = (new UserContractRecordModel)->where("id", $id)->update($post); } else { $post['contract_no'] = makeOrderId($post['uid'], "CR"); $r = (new UserContractRecordModel)->save($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['check_time'] = strtotime($post['check_time']); // $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_time'] = strtotime($post['to_check_time']); $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([ ['contract_id', '0'], //合约id ['longitude', ''], //经度 ['latitude', ''], //纬度 // ['uid',0] ], $request); $uid = UtilService::getMore([ ['uid', 0], ], $request); $uid = $uid['uid']; // $uid = (int)$post["uid"]; // 检查签约时间是否为空 if (empty($post['contract_id'])) { return app('json')->fail("签字错误"); } $time = time(); $info = (new UserContractRecordModel)->where('status',1)->where("id", $post["contract_id"])->where('start_time', '<', $time)->where('end_time', '>', $time)->find(); if (!empty($info)) { $info = $info->toArray(); } else { return app('json')->fail("合约未签约或已解约"); } // $nickname=\app\model\api\User::where('uid',$uid)->value('nickname'); $r = (new UserClockModel)->save([ 'uid' => $uid, 'nickname' => $info['to_name'], 'longitude' => $post['longitude'], 'latitude' => $post['latitude'], 'contract_id' => $post['contract_id'], 'create_time' => time() ]); return app('json')->success("数据保存成功"); } // 添加客户评论 public function comment(Request $request) { $post = UtilService::getMore([ ['contract_id', '0'], //合约id ['content', ''], //评论内容 // ['uid',0] ], $request); $uid = UtilService::getMore([ ['uid', 0], ], $request); $uid = $uid['uid']; // $uid = $post['uid']; $time = time(); $info = (new UserContractRecordModel)->where("id", $post["contract_id"])->find(); if (!empty($info)) { $info = $info->toArray(); } else { return app('json')->fail("没有签约中的合约"); } if ($info['status'] != 1) { return app('json')->fail("只有签约状态才能发表评论"); } // var_dump($time); // var_dump($info);die(); if ($info['start_time'] > $time || $info['end_time'] < $time) { return app('json')->fail("只能在签约期间才能发表评论"); } // ->where('start_time','>',$time)->where('end_time','<',$time) // 检查签约时间是否为空 // if (empty($post['id'])) { // return app('json')->fail("签字错误"); // } $r = (new ContractCommentModel)->save([ 'uid' => $uid, 'name' => $info['name'], 'contract_id' => $post['contract_id'], 'contract_no' => $info['contract_no'], 'to_uid' => $info['to_uid'], 'to_name' => $info['to_name'], 'content' => $post['content'], 'create_time' => time() ]); return app('json')->success("数据保存成功"); } // 甲方主动解约 public function lift_contract(Request $request) { $post = UtilService::getMore([ ['contract_id', '0'], //合约id // ['uid',0] ], $request); // 检查签约时间是否为空 if (empty($post['contract_id'])) { return app('json')->fail("没有该合约"); } $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([ 'status' => -1, 'delete_time' => time() ]); return app('json')->success("解约成功"); } // 乙方主动解约 public function right_contract(Request $request) { $post = UtilService::getMore([ ['contract_id', '0'], //合约id // ['uid',0] ], $request); // 检查签约时间是否为空 if (empty($post['contract_id'])) { return app('json')->fail("没有该合约"); } $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([ 'status' => -1, 'delete_time' => time() ]); return app('json')->success("解约成功"); } // 打卡列表 /** * 打卡列表 * @param \app\Request $request * @return mixed */ public function getClockList(\think\Request $request) { $post = UtilService::getMore([ ['page', 1], ['pageSize', 50], ['time', ''], ['contract_id',0] ], $request); $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"]; $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"]; $where = []; $uid = UtilService::getMore([ ['uid', 0], ], $request); $uid = $uid['uid']; if ($uid > 0) { $where[] = ["uid", "=", $uid]; } if (!empty($post['time'])) { $start_time = strtotime($post['time']); $end_time = $start_time + 86400; // 将时间范围添加到查询条件中 $where[] = ["create_time", ">=", $start_time]; $where[] = ["create_time", "<", $end_time]; // $where[] = ["create_time",'=',strtotime($post['time'])]; } if ($post['contract_id']>0){ $where[] = ["contract_id",'=',$post['contract_id']]; } $totalCount = (new UserClockModel())->where($where)->count(); $data = null; if ($totalCount > 0) { $data = (new UserClockModel) ->where($where) ->order("id", "desc") ->page($post["page"], $post["pageSize"]) ->select(); } $data = empty($data) ? [] : $data; return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]); } }