|
|
@@ -0,0 +1,864 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Api;
|
|
|
+
|
|
|
+use App\Modes\AccountLog;
|
|
|
+use App\Modes\AdverActivity;
|
|
|
+use App\Modes\AdverActivityLog;
|
|
|
+use App\Modes\Advertising;
|
|
|
+use App\Modes\Area;
|
|
|
+use App\Modes\Config;
|
|
|
+use App\Modes\ErrorLog;
|
|
|
+use App\Modes\Industry;
|
|
|
+use App\Modes\MsgTemplate;
|
|
|
+use App\Modes\Order;
|
|
|
+use App\Modes\Upgrade;
|
|
|
+use App\Modes\User;
|
|
|
+use App\Modes\UserMsg;
|
|
|
+use App\Service\PayDispatchService;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use \App\Modes\Proxy;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
+use Mockery\Exception;
|
|
|
+use Yansongda\Pay\Gateways\Alipay;
|
|
|
+use Yansongda\Pay\Pay;
|
|
|
+
|
|
|
+class AdverController extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 检查发布广告参数
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/3/22
|
|
|
+ * @param $param
|
|
|
+ * @param Proxy $proxyConfig
|
|
|
+ * @return bool|string
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ private static function checkParam($param, $proxyConfig)
|
|
|
+ {
|
|
|
+ // 检查发布地区关系
|
|
|
+ if ($isRelation = Area::isRealation($param['province'], $param['city'], $param['district']) == false) {
|
|
|
+ return '地区从属关系不符';
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($param['start_time'] > $param['end_time']) {
|
|
|
+ return '有效开始时间不能大于结束时间';
|
|
|
+ }
|
|
|
+
|
|
|
+// if ($param['guarantee'] == 1 && ($param['bet_start_time'] > $param['bet_end_time'])) {
|
|
|
+// return '担保开始时间不能大于结束时间';
|
|
|
+// }
|
|
|
+
|
|
|
+ if ($proxyConfig['money'] != $param['price']) {
|
|
|
+ return '抱歉,单价数据不一致,请重新提交';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (($proxyConfig['money'] * $param['total_num']) != ($param['price'] * $param['total_num'])) {
|
|
|
+ return '抱歉,总价不一致,请重新提交';
|
|
|
+ }
|
|
|
+
|
|
|
+ /*if ($proxyConfig['min_money'] > ($param['price'] * $param['total_num'])) {
|
|
|
+ return '抱歉,未达到广告发布最低额度';
|
|
|
+ }*/
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 对赌广告上传协议数据
|
|
|
+ *wsl 20190730
|
|
|
+ * */
|
|
|
+ public function userGuarantee(Request $request){
|
|
|
+ $params=$request->all();
|
|
|
+ if(empty($params['id']))return showJsonErr('广告id不能为空');
|
|
|
+ if(empty($params['user_guarantee_url']))return showJsonErr('担保协议必传');
|
|
|
+
|
|
|
+ $info=Advertising::whereId($params['id'])->first();
|
|
|
+ if(empty($info)){
|
|
|
+ return showJsonErr('广告不存在');
|
|
|
+ }
|
|
|
+ $bet=\DB::table('advertising_bet')->where('advertising_id','=',$params['id'])->first();
|
|
|
+ if(empty($bet)) return showJsonErr('对赌广告数据错误');
|
|
|
+ if($info->status!=2){
|
|
|
+ return showJsonErr('当前广告状态不允许修改协议内容');
|
|
|
+ }
|
|
|
+ $data=['user_guarantee_url'=>$params['user_guarantee_url']];
|
|
|
+ $res=\DB::table('advertising_bet')->where('id','=',$bet->id)->update($data);
|
|
|
+ Advertising::whereId($params['id'])->update(['guarantee_url'=>$params['user_guarantee_url']]);
|
|
|
+ if($res>=0){
|
|
|
+ return showJsonSucc('上传成功,请等待上级确认');
|
|
|
+ }else return showJsonErr('上传失败');
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * 对赌广告上传业绩数据
|
|
|
+ *wsl 20190730
|
|
|
+ * */
|
|
|
+ public function userAchievement(Request $request){
|
|
|
+ $params=$request->all();
|
|
|
+ if(empty($params['id']))return showJsonErr('广告id不能为空');
|
|
|
+ if(empty($params['user_achievement_url']))return showJsonErr('业绩数据必传');
|
|
|
+
|
|
|
+ $info=Advertising::whereId($params['id'])->first();
|
|
|
+ if(empty($info)){
|
|
|
+ return showJsonErr('广告不存在');
|
|
|
+ }
|
|
|
+ $bet=\DB::table('advertising_bet')->where('advertising_id','=',$params['id'])->first();
|
|
|
+ if(empty($bet)) return showJsonErr('对赌广告数据错误');
|
|
|
+ /*if($bet->bet_end_time>date('Y-m-d H:i:s')){
|
|
|
+ return showJsonErr('对赌结束时间为'.$bet->bet_end_time.',请在该时间之后上传业务数据');
|
|
|
+ }*/
|
|
|
+ if($info->status !=3){
|
|
|
+ return showJsonErr('抱歉,当前广告状态不允许修改内容');
|
|
|
+ }
|
|
|
+ $data=['user_achievement_url'=>$params['user_achievement_url']];
|
|
|
+ $res=\DB::table('advertising_bet')->where('id','=',$bet->id)->update($data);
|
|
|
+ if($res>=0){
|
|
|
+ return showJsonSucc('上传成功,请耐心等待平台审核完成');
|
|
|
+ }else return showJsonErr('上传失败');
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 代理广告
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/3/21
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ public function index(Request $request)
|
|
|
+ {
|
|
|
+ $type = $request->input('type',0);
|
|
|
+ if (!in_array($type, [0,1,2])) {
|
|
|
+ return showJsonErr('type错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($type == 1) {//间1
|
|
|
+ $uids = User::getInviteeOne(\Auth::id());
|
|
|
+ } elseif ($type == 2) {//间2
|
|
|
+ $uids = User::getInviteeTwo(\Auth::id());
|
|
|
+ } else {//直推
|
|
|
+ $uids = User::whereInvitor(\Auth::id())->pluck('id');
|
|
|
+ }
|
|
|
+ if ($uids->isEmpty()) {
|
|
|
+ return showJsonErr('数据为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并查询字段
|
|
|
+ $select = ['id', 'uid', 'title', 'image', 'content', 'bet_status', 'guarantee', 'status', 'created_at','end_time'];
|
|
|
+ // 合并查询字段
|
|
|
+ $userSelect = ['id', 'nick_name'];
|
|
|
+
|
|
|
+ $res = Advertising::whereIn('uid',$uids)
|
|
|
+ ->with(['User' => function ($query) use ($userSelect) {
|
|
|
+ $query->select($userSelect);
|
|
|
+ }])
|
|
|
+ ->orderByDesc('id')
|
|
|
+ ->select($select);
|
|
|
+ $res->whereIn('status',[2,3,4,5,6,9]);
|
|
|
+
|
|
|
+
|
|
|
+ $r=$res->paginate(perPage());
|
|
|
+
|
|
|
+ if($r->isNotEmpty()){
|
|
|
+ collect($r->items())->each(function ($item, $key) {
|
|
|
+ if($item->end_time<date('Y-m-d H:i:S')){
|
|
|
+ $item->status=9;
|
|
|
+ }
|
|
|
+ if($item->guarantee==1){
|
|
|
+ $item->bet=\DB::table('advertising_bet')->where('advertising_id','=',$item->id)->first();
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return showJsonSucc(1001, $r);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页-代理明细
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/3/21
|
|
|
+ * @param Request $request
|
|
|
+ * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ public function adver(Request $request)
|
|
|
+ {
|
|
|
+ $validator = \Validator::make($param = $request->post(), [
|
|
|
+ 'type' => 'required|between:0,2',
|
|
|
+ 'page' => 'required|numeric'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return showJson(102, $validator->errors()->first());
|
|
|
+ }
|
|
|
+ $userinfo=User::whereId(\Auth::id())->first()->toArray();
|
|
|
+ if ($param['type'] == 1) {
|
|
|
+ $ids = User::getInviteeOne(\Auth::id());
|
|
|
+ //获取当前间1配置的百分比
|
|
|
+ $pct=Proxy::getJianPct($userinfo,1,2,$ids);
|
|
|
+
|
|
|
+ } elseif ($param['type'] == 2) {
|
|
|
+ $ids = User::getInviteeTwo(\Auth::id());
|
|
|
+ //获取当前间2配置的百分比
|
|
|
+ $pct=Proxy::getJianPct($userinfo,2,2,$ids);
|
|
|
+ } else {
|
|
|
+ $ids = User::getInvitee(\Auth::id());
|
|
|
+ $pctarr = Proxy::getSettingByAreaAndLevel($userinfo['level'],$userinfo['province'],$userinfo['city'],$userinfo['district']);
|
|
|
+ $pct=$pctarr['adver_invite'];
|
|
|
+ }
|
|
|
+ $user = User::getList($ids, ['nick_name', 'id', 'mobile']);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ($user->isNotEmpty()) {
|
|
|
+ collect($user->items())->each(function ($item, $key) {
|
|
|
+ $item['adverNum'] = Advertising::whereUid($item['id'])->whereIn('status', [3, 4, 9])->count('id'); // 广告笔数
|
|
|
+ $item['performance'] = Advertising::whereUid($item['id'])->whereIn('status', [3, 4, 9])->sum('total_price'); // 广告业绩总额
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return showJsonSucc('获取数据成功', [
|
|
|
+ 'user' => $user,
|
|
|
+ 'pct' => $pct,
|
|
|
+ 'totalPerformance' => Advertising::whereIn('uid', $ids)->whereStatus(3)->sum('total_price'), // 代理费总额
|
|
|
+ 'count' => count($ids),//总人数
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 新发布广告流程
|
|
|
+ * wsl
|
|
|
+ * 20190729
|
|
|
+ * */
|
|
|
+ public function add(Request $request){
|
|
|
+
|
|
|
+ $validator = \Validator::make($param = $request->post(), [
|
|
|
+ 'title' => 'required|string',
|
|
|
+ 'image' => 'string',
|
|
|
+ 'scene' => 'integer|between:1,3',
|
|
|
+ 'image_group' => 'string',
|
|
|
+ 'industry' => 'required',
|
|
|
+ 'content' => 'string',
|
|
|
+ 'redirect' => 'url',
|
|
|
+ 'province' => 'required|numeric',
|
|
|
+ 'city' => 'required|numeric',
|
|
|
+ 'district' => 'required|numeric',
|
|
|
+ 'start_time' => 'required|date',
|
|
|
+ 'end_time' => 'required|date',
|
|
|
+ 'total_num' => 'required|numeric',
|
|
|
+ 'price' => 'required|numeric',
|
|
|
+ 'total_price' => 'required|numeric',
|
|
|
+ 'pay_type' => 'required|integer',
|
|
|
+ 'guarantee_content' => 'string',
|
|
|
+ 'is_company' => 'required|between:1,2',
|
|
|
+ 'license' => 'required_if:is_company,2',
|
|
|
+ 'license_number' => 'required_if:is_company,2',
|
|
|
+ 'idcard_number'=>'required_if:is_company,1',
|
|
|
+ 'idcard_front'=>'required_if:is_company,1',
|
|
|
+ 'idcard_reverse'=>'required_if:is_company,1',
|
|
|
+ 'bet_start_time'=>'required_if:guarantee,1',
|
|
|
+ 'bet_end_time'=>'required_if:guarantee,1',
|
|
|
+ 'bet_address'=>'required_if:guarantee,1',
|
|
|
+ 'bet_province'=>'required_if:guarantee,1',
|
|
|
+ 'bet_city'=>'required_if:guarantee,1',
|
|
|
+ 'bet_district'=>'required_if:guarantee,1',
|
|
|
+ 'real_name'=>'required|string',//投放人姓名
|
|
|
+ 'address'=>'required|string',//联系地址
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return showJson(102, $validator->errors()->first());
|
|
|
+ }
|
|
|
+ if (\Auth::user()->level == 0 || empty(\Auth::user()->province)|| empty(\Auth::user()->city) || empty(\Auth::user()->district)) {
|
|
|
+ return showJsonErr('请完善用户信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ $proxyConfig = Proxy::getConfig(\Auth::id(), $param['province'], $param['city'], $param['district']);
|
|
|
+
|
|
|
+ $proxyc = Proxy::whereUserLevel(\Auth::user()->level)->whereStatus(1)->whereUid(\Auth::id())->whereAreaType(4)->first();
|
|
|
+ if(empty($proxyc->id) || !empty($param['guarantee'])){
|
|
|
+ $proxyc=Proxy::getSettingByAreaAndLevel(\Auth::user()->level,\Auth::user()->province,\Auth::user()->city,\Auth::user()->district);
|
|
|
+
|
|
|
+ }else $proxyc->toArray();
|
|
|
+
|
|
|
+ if (($checkParam = self::checkParam($param, $proxyc)) !== true) {
|
|
|
+ return showJsonErr($checkParam);
|
|
|
+ }
|
|
|
+ //已发布的广告条数
|
|
|
+ $free_yfb=Advertising::whereUid(\Auth::id())->whereIn('status',[2,3,4])->sum('total_num');
|
|
|
+ // 判断支付价格
|
|
|
+ $free_num = Proxy::getActivityFreeNum(\Auth::id(),\Auth::user()->province,\Auth::user()->city,\Auth::user()->district,\Auth::user()->level);; // 获取剩余发布广告免费次数
|
|
|
+ //剩余可使用的免费次数
|
|
|
+ $free_num=$free_num-$free_yfb<=0?0:$free_num-$free_yfb;
|
|
|
+
|
|
|
+ if ($free_num >= $param['total_num']) {
|
|
|
+ $totalPrice = 0;
|
|
|
+ } elseif(!empty($free_num)&&$free_num<$param['total_num']) {
|
|
|
+ $totalPrice = ($param['total_num'] - $free_num) * $proxyc['money'];
|
|
|
+ }else{
|
|
|
+ $totalPrice=$param['total_num']*$proxyc['money'];
|
|
|
+ }
|
|
|
+ if (bccomp($totalPrice,$param['total_price'],2)!=0) {
|
|
|
+ return showJsonErr('广告价格不正确', [
|
|
|
+ 'total_price' => $totalPrice,
|
|
|
+ 'free_num' => $free_num
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($free_num) && $totalPrice==0 ){
|
|
|
+ return showJsonErr('抱歉,您的免费次数已用完');
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否是担保广告
|
|
|
+ if(!empty($param['guarantee'])){
|
|
|
+ $proxyc['min_money']=$proxyc['guarantee_min_money'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最低额度限制
|
|
|
+ /*if ($free_num-$param['total_num']< 0 && ($proxyc['min_money'] > $param['total_price'])) {
|
|
|
+ return showJsonErr('抱歉,广告价格未达到最低额度要求');
|
|
|
+ }*/
|
|
|
+ if (($free_num == 0 ||$free_num<$param['total_num']) && $proxyc['min_money'] > $param['total_price']) {
|
|
|
+ return showJsonErr('抱歉,广告价格未达到最低额度要求');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $param['residue_num'] = $param['total_num'];
|
|
|
+
|
|
|
+ \DB::beginTransaction();
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 如果是担保广告,则需要上级用户审核
|
|
|
+ if (!empty($param['guarantee']) && $param['guarantee'] == 1) {
|
|
|
+ $param['bet_status'] = 0;
|
|
|
+ } else {
|
|
|
+ $param['bet_status'] = 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ $param['order_no'] = $orderNo = Order::makeOrderNo();
|
|
|
+ $param['uid'] = \Auth::id();
|
|
|
+ if (!empty($param['image_group'])) {
|
|
|
+ $param['image'] = explode(',', $param['image_group'])[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ $payData = [];
|
|
|
+ //$param['total_price']=0.01;
|
|
|
+ $adverActivityLogStatus = 2;
|
|
|
+ $adverStatus = 1; //待支付
|
|
|
+ // 如果是免费发布广告则不需要支付,生成订单信息
|
|
|
+ if ($param['total_price'] > 0) {
|
|
|
+ $pay = PayDispatchService::dispatch($param['pay_type']);
|
|
|
+ // $payData = $pay->getPayInfo($orderNo, $param['total_price'], \Auth::user()->mobile . '购买广告位'); // 获取支付信息
|
|
|
+ //判断支付方式生成支付代码
|
|
|
+ if($param['pay_type']==2){//支付宝
|
|
|
+ $payData = $pay->getAppPayInfo($orderNo,$param['total_price'] , \Auth::user()->mobile . '购买广告位'); // 测试,金额一致为0.01
|
|
|
+ }elseif($param['pay_type']==3){//微信
|
|
|
+ $payData = $pay->getPayInfo($orderNo, $param['total_price'], \Auth::user()->mobile . '购买广告位'); // 测试,金额一致为0.01
|
|
|
+ }elseif($param['pay_type']==21){
|
|
|
+ $pay = PayDispatchService::dispatch(2);
|
|
|
+ $payData = $pay->getPayInfo($orderNo,$param['total_price'] , \Auth::user()->mobile . '购买广告位'); // 测试,金额一致为0.01
|
|
|
+ }elseif($param['pay_type']==31){
|
|
|
+ $pay = PayDispatchService::dispatch(3);
|
|
|
+ $getPayInfoh5Data = $pay->getPayInfoh5($orderNo, $param['total_price'], \Auth::user()->mobile . '购买广告位'); // 测试,金额一致为0.01
|
|
|
+ $payData['url'] = 'http://itaoniu.wohuicn.com/re.php?re='.urlencode($getPayInfoh5Data->getTargetUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成订单
|
|
|
+ $orderId = Order::insertData([
|
|
|
+ 'uid' => \Auth::id(),
|
|
|
+ 'type' => 2,
|
|
|
+ 'order_no' => $orderNo,
|
|
|
+ 'pay_no' => $pay_no = $orderNo,
|
|
|
+ 'price' => $param['total_price'],
|
|
|
+ 'is_pay' => 0,
|
|
|
+ 'pay_type' => $param['pay_type'],
|
|
|
+ 'status' => 2,
|
|
|
+ ]);
|
|
|
+ if (empty($orderId)) {
|
|
|
+ \DB::rollBack();
|
|
|
+ return showJsonErr('生成订单失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $adverActivityLogStatus = 1;
|
|
|
+ $adverStatus = 1; //待支付
|
|
|
+ } else {
|
|
|
+ $param['pay_type'] = 0;//如果金额为0,
|
|
|
+ $adverStatus = 2; //如果金额为0,,已支付待审核
|
|
|
+ }
|
|
|
+ if ($proxyConfig->uid = \Auth::id() && $proxyConfig->free_num > 0) {
|
|
|
+ $activity_id = 0;//单独设置的即使有活动也没用
|
|
|
+ } else {
|
|
|
+ $activity_id = AdverActivity::getCurrentActivityId();
|
|
|
+ }
|
|
|
+ // 营销活动-如果使用了免费次数则生成记录
|
|
|
+ $aalId = AdverActivityLog::insertGetId([
|
|
|
+ 'uid' => \Auth::id(),
|
|
|
+ 'activity_id' => $activity_id,
|
|
|
+ 'total_price' => $param['total_price'],
|
|
|
+ 'price' => $param['price'],
|
|
|
+ 'free_num' => $free_num,
|
|
|
+ 'mininum_money' => $proxyc['min_money'],
|
|
|
+ 'status' => $adverActivityLogStatus,
|
|
|
+ ]);
|
|
|
+ $param['activity_id'] = $aalId;
|
|
|
+ $param['status'] = $adverStatus;
|
|
|
+ // 添加广告发布记录
|
|
|
+ $sparam=$param;
|
|
|
+ if(isset($param['bet_end_time']))unset($param['bet_end_time']);
|
|
|
+ if(isset($param['bet_start_time']))unset($param['bet_start_time']);
|
|
|
+ if(isset($param['bet_address']))unset($param['bet_address']);
|
|
|
+ if(isset($param['bet_province']))unset($param['bet_province']);
|
|
|
+ if(isset($param['bet_city']))unset($param['bet_city']);
|
|
|
+ if(isset($param['bet_district']))unset($param['bet_district']);
|
|
|
+
|
|
|
+ $advertID = Advertising::insertGetId($param);
|
|
|
+ //如果是对赌广告
|
|
|
+ if($param['guarantee']==1){
|
|
|
+ $betdata=[
|
|
|
+ 'advertising_id'=>$advertID,
|
|
|
+ 'bet_start_time'=>$sparam['bet_start_time'],
|
|
|
+ 'bet_end_time'=>$sparam['bet_end_time'],
|
|
|
+ 'bet_address'=>$sparam['bet_address'],
|
|
|
+ 'bet_province'=>$sparam['bet_province'],
|
|
|
+ 'bet_city'=>$sparam['bet_city'],
|
|
|
+ 'bet_district'=>$sparam['bet_district'],
|
|
|
+ 'bet_money'=>$proxyc['guarantee_min_money'],
|
|
|
+ 'bet_state'=>0,//等待上级确认
|
|
|
+ ];
|
|
|
+ \DB::table('advertising_bet')->insert($betdata);
|
|
|
+ }
|
|
|
+ if (!$advertID) {
|
|
|
+ \DB::rollBack();
|
|
|
+ ErrorLog::saveMsg('发布广告失败', $sparam);
|
|
|
+ return showJsonErr('发布广告失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ \DB::commit();
|
|
|
+
|
|
|
+ return showJsonSucc('提交发布广告成功', [
|
|
|
+ 'payData' => $payData
|
|
|
+ ]);
|
|
|
+
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ \DB::rollBack();
|
|
|
+ ErrorLog::saveMsg('发布广告失败,出现异常问题', ['msg' => $exception->getMessage(),
|
|
|
+ 'line' => $exception->getLine(),
|
|
|
+ 'file' => $exception->getFile(),]);
|
|
|
+ return showJsonErr('发布广告失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布广告pc
|
|
|
+ * @author wsl
|
|
|
+ * @date 2019/7/1
|
|
|
+ * @param Request $request
|
|
|
+ * @descriptiona
|
|
|
+ */
|
|
|
+ public function pcadd(Request $request){
|
|
|
+
|
|
|
+ $validator = \Validator::make($param = $request->post(), [
|
|
|
+ 'title' => 'required|string',
|
|
|
+ 'image' => 'string',
|
|
|
+ 'scene' => 'integer|between:1,3',
|
|
|
+ 'image_group' => 'string',
|
|
|
+ 'industry' => 'required',
|
|
|
+ 'content' => 'string',
|
|
|
+ 'redirect' => 'url',
|
|
|
+ 'province' => 'required|numeric',
|
|
|
+ 'city' => 'required|numeric',
|
|
|
+ 'district' => 'required|numeric',
|
|
|
+ 'start_time' => 'required|date',
|
|
|
+ 'end_time' => 'required|date',
|
|
|
+ 'total_num' => 'required|numeric',
|
|
|
+ 'price' => 'required|numeric',
|
|
|
+ 'total_price' => 'required|numeric',
|
|
|
+ 'pay_type' => 'required|integer|between:1,3',
|
|
|
+ 'guarantee_content' => 'string',
|
|
|
+ 'is_company' => 'required|between:1,2',
|
|
|
+ 'license' => 'required_if:is_company,2',
|
|
|
+ 'license_number' => 'required_if:is_company,2',
|
|
|
+ 'idcard_number'=>'required_if:is_company,1',
|
|
|
+ 'idcard_front'=>'required_if:is_company,1',
|
|
|
+ 'idcard_reverse'=>'required_if:is_company,1',
|
|
|
+ 'bet_start_time'=>'required_if:guarantee,1',
|
|
|
+ 'bet_end_time'=>'required_if:guarantee,1',
|
|
|
+ 'bet_address'=>'required_if:guarantee,1',
|
|
|
+ 'bet_province'=>'required_if:guarantee,1',
|
|
|
+ 'bet_city'=>'required_if:guarantee,1',
|
|
|
+ 'bet_district'=>'required_if:guarantee,1',
|
|
|
+ 'pay_type' => 'required|between:1,5', // 0-未支付 1-现金 2-支付宝 3-微信 4-银行转账 5-桃牛支付
|
|
|
+ 'real_name'=>'required|string',//投放人姓名
|
|
|
+ 'address'=>'required|string',//联系地址
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return showJson(102, $validator->errors()->first());
|
|
|
+ }
|
|
|
+ if (\Auth::user()->level == 0 || empty(\Auth::user()->province)|| empty(\Auth::user()->city) || empty(\Auth::user()->district)) {
|
|
|
+ return showJsonErr('请完善用户信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ $proxyConfig = Proxy::getConfig(\Auth::id(), $param['province'], $param['city'], $param['district']);
|
|
|
+
|
|
|
+ $proxyc = Proxy::whereUserLevel(\Auth::user()->level)->whereStatus(1)->whereUid(\Auth::id())->whereAreaType(4)->first();
|
|
|
+ if(empty($proxyc->id) || !empty($param['guarantee'])){
|
|
|
+ $proxyc=Proxy::getSettingByAreaAndLevel(\Auth::user()->level,\Auth::user()->province,\Auth::user()->city,\Auth::user()->district);
|
|
|
+
|
|
|
+ }else $proxyc->toArray();
|
|
|
+
|
|
|
+ if (($checkParam = self::checkParam($param, $proxyc)) !== true) {
|
|
|
+ return showJsonErr($checkParam);
|
|
|
+ }
|
|
|
+ //已发布的广告条数
|
|
|
+ $free_yfb=Advertising::whereUid(\Auth::id())->whereIn('status',[2,3,4])->sum('total_num');
|
|
|
+ // 判断支付价格
|
|
|
+ $free_num = Proxy::getActivityFreeNum(\Auth::id(),\Auth::user()->province,\Auth::user()->city,\Auth::user()->district,\Auth::user()->level);; // 获取剩余发布广告免费次数
|
|
|
+ //剩余可使用的免费次数
|
|
|
+ $free_num=$free_num-$free_yfb<=0?0:$free_num-$free_yfb;
|
|
|
+
|
|
|
+ if ($free_num >= $param['total_num']) {
|
|
|
+ $totalPrice = 0;
|
|
|
+ } elseif(!empty($free_num)&&$free_num<$param['total_num']) {
|
|
|
+ $totalPrice = ($param['total_num'] - $free_num) * $proxyc['money'];
|
|
|
+ }else{
|
|
|
+ $totalPrice=$param['total_num']*$proxyc['money'];
|
|
|
+ }
|
|
|
+ if (bccomp($totalPrice,$param['total_price'],2)!=0) {
|
|
|
+ return showJsonErr('广告价格不正确', [
|
|
|
+ 'total_price' => $totalPrice,
|
|
|
+ 'free_num' => $free_num
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($free_num) && $totalPrice==0 ){
|
|
|
+ return showJsonErr('抱歉,您的免费次数已用完');
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否是担保广告
|
|
|
+ if(!empty($param['guarantee'])){
|
|
|
+ $proxyc['min_money']=$proxyc['guarantee_min_money'];
|
|
|
+ }
|
|
|
+ // 最低额度限制
|
|
|
+ if (($free_num == 0 ||$free_num<$param['total_num']) && $proxyc['min_money'] > $param['total_price']) {
|
|
|
+ return showJsonErr('抱歉,广告价格未达到最低额度要求');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $param['residue_num'] = $param['total_num'];
|
|
|
+
|
|
|
+ \DB::beginTransaction();
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 如果是担保广告,则需要上级用户审核
|
|
|
+ if (!empty($param['guarantee']) && $param['guarantee'] == 1) {
|
|
|
+ $param['bet_status'] = 0;
|
|
|
+ } else {
|
|
|
+ $param['bet_status'] = 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ $param['order_no'] = $orderNo = Order::makeOrderNo();
|
|
|
+ $param['uid'] = \Auth::id();
|
|
|
+ if (!empty($param['image_group'])) {
|
|
|
+ $param['image'] = explode(',', $param['image_group'])[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ $payData = [];
|
|
|
+ //$param['total_price']=0.01;
|
|
|
+ $adverActivityLogStatus = 2;
|
|
|
+ $adverStatus = 1; //待支付
|
|
|
+ // 如果是免费发布广告则不需要支付,生成订单信息
|
|
|
+ if ($param['total_price'] > 0) {
|
|
|
+ $pay = PayDispatchService::dispatch($param['pay_type']);
|
|
|
+ // $payData = $pay->getPayInfo($orderNo, $param['total_price'], \Auth::user()->mobile . '购买广告位'); // 获取支付信息
|
|
|
+ //判断支付方式生成支付代码
|
|
|
+ if($param['pay_type']==2){//支付宝
|
|
|
+ $payData = $pay->getPcPayInfo($orderNo,$param['total_price'] , \Auth::user()->mobile . '购买广告位'); // 测试,金额一致为0.01
|
|
|
+ }
|
|
|
+ if($param['pay_type']==3){//微信
|
|
|
+ $payData = $pay->getPcPayInfo($orderNo, $param['total_price'], \Auth::user()->mobile . '购买广告位'); // 测试,金额一致为0.01
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成订单
|
|
|
+ $orderId = Order::insertData([
|
|
|
+ 'uid' => \Auth::id(),
|
|
|
+ 'type' => 2,
|
|
|
+ 'order_no' => $orderNo,
|
|
|
+ 'pay_no' => $pay_no = $orderNo,
|
|
|
+ 'price' => $param['total_price'],
|
|
|
+ 'is_pay' => 0,
|
|
|
+ 'pay_type' => $param['pay_type'],
|
|
|
+ 'status' => 2,
|
|
|
+ ]);
|
|
|
+ if (empty($orderId)) {
|
|
|
+ \DB::rollBack();
|
|
|
+ return showJsonErr('生成订单失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $adverActivityLogStatus = 1;
|
|
|
+ $adverStatus = 1; //待支付
|
|
|
+ } else {
|
|
|
+ $param['pay_type'] = 0;//如果金额为0,
|
|
|
+ $adverStatus = 2; //如果金额为0,,已支付待审核
|
|
|
+ }
|
|
|
+ if ($proxyConfig->uid = \Auth::id() && $proxyConfig->free_num > 0) {
|
|
|
+ $activity_id = 0;//单独设置的即使有活动也没用
|
|
|
+ } else {
|
|
|
+ $activity_id = AdverActivity::getCurrentActivityId();
|
|
|
+ }
|
|
|
+ // 营销活动-如果使用了免费次数则生成记录
|
|
|
+ $aalId = AdverActivityLog::insertGetId([
|
|
|
+ 'uid' => \Auth::id(),
|
|
|
+ 'activity_id' => $activity_id,
|
|
|
+ 'total_price' => $param['total_price'],
|
|
|
+ 'price' => $param['price'],
|
|
|
+ 'free_num' => $free_num,
|
|
|
+ 'mininum_money' => $proxyc['min_money'],
|
|
|
+ 'status' => $adverActivityLogStatus,
|
|
|
+ ]);
|
|
|
+ $param['activity_id'] = $aalId;
|
|
|
+ $param['status'] = $adverStatus;
|
|
|
+ // 添加广告发布记录
|
|
|
+ $sparam=$param;
|
|
|
+ if(isset($param['bet_end_time']))unset($param['bet_end_time']);
|
|
|
+ if(isset($param['bet_start_time']))unset($param['bet_start_time']);
|
|
|
+ if(isset($param['bet_address']))unset($param['bet_address']);
|
|
|
+ if(isset($param['bet_province']))unset($param['bet_province']);
|
|
|
+ if(isset($param['bet_city']))unset($param['bet_city']);
|
|
|
+ if(isset($param['bet_district']))unset($param['bet_district']);
|
|
|
+
|
|
|
+ $advertID = Advertising::insertGetId($param);
|
|
|
+ //如果是对赌广告
|
|
|
+ if($param['guarantee']==1){
|
|
|
+ $betdata=[
|
|
|
+ 'advertising_id'=>$advertID,
|
|
|
+ 'bet_start_time'=>$sparam['bet_start_time'],
|
|
|
+ 'bet_end_time'=>$sparam['bet_end_time'],
|
|
|
+ 'bet_address'=>$sparam['bet_address'],
|
|
|
+ 'bet_province'=>$sparam['bet_province'],
|
|
|
+ 'bet_city'=>$sparam['bet_city'],
|
|
|
+ 'bet_district'=>$sparam['bet_district'],
|
|
|
+ 'bet_money'=>$proxyc['guarantee_min_money'],
|
|
|
+ ];
|
|
|
+ \DB::table('advertising_bet')->insert($betdata);
|
|
|
+ }
|
|
|
+ if (!$advertID) {
|
|
|
+ \DB::rollBack();
|
|
|
+ ErrorLog::saveMsg('发布广告失败', $sparam);
|
|
|
+ return showJsonErr('发布广告失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ \DB::commit();
|
|
|
+
|
|
|
+ return showJsonSucc('提交发布广告成功', [
|
|
|
+ 'payData' => $payData
|
|
|
+ ]);
|
|
|
+
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ \DB::rollBack();
|
|
|
+ ErrorLog::saveMsg('发布广告失败,出现异常问题', ['msg' => $exception->getMessage(),
|
|
|
+ 'line' => $exception->getLine(),
|
|
|
+ 'file' => $exception->getFile(),]);
|
|
|
+ return showJsonErr('发布广告失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布记录
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/3/26
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ public function publish(Request $request)
|
|
|
+ {
|
|
|
+ $validator = \Validator::make($param = $request->all(), [
|
|
|
+ 'type' => 'required|in:0,2,3,4,5,9' //广告状态 1-待支付 2-待审核 3-发布中 4-屏蔽 5-拒绝 9-过期
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return showJsonErr($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ //$where = ['uid' => \Auth::id(),['in' => ['status' => [2,3,4,5,6,9]]]];
|
|
|
+ $where = ['uid' => \Auth::id()];
|
|
|
+ if(@$param['ad_type']==1){
|
|
|
+ //已有广告
|
|
|
+ $where[]=['redirect','!=',''];
|
|
|
+ }
|
|
|
+ if(@$param['ad_type']==2){
|
|
|
+ //新广告
|
|
|
+ $where[]=['redirect','=',''];
|
|
|
+ }
|
|
|
+ $field = ['redirect', 'image_group', 'is_update'];
|
|
|
+
|
|
|
+
|
|
|
+ $res = Advertising::getList($where, $field, [], $param);
|
|
|
+ return showJsonSucc(1001, $res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 邀请人审核担保
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/3/26
|
|
|
+ * @param Request $request
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ public function auditBet(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($param = $request->all(), [
|
|
|
+ 'id' => 'required|exists:advertising,id',
|
|
|
+ 'bet_status' => 'required|integer|between:1,3',
|
|
|
+ 'bet_rejuse_remark' => 'string'
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return showJsonErr($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ $adver = Advertising::whereId($param['id'])->first();
|
|
|
+ $bet=\DB::table('advertising_bet')->where('advertising_id',$adver->id)->first();
|
|
|
+ if(empty($bet)){
|
|
|
+ return showJsonErr('对赌广告数据错误');
|
|
|
+ }
|
|
|
+ if ($adver->status != 2) {
|
|
|
+ return showJsonErr('抱歉,当前广告状态不允许操作');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($bet->bet_state != 0) {
|
|
|
+ return showJsonErr('您不能操作当前广告状态');
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果拒绝的话
|
|
|
+ if($param['bet_status']==2){
|
|
|
+ //退款操作wsl 20190628
|
|
|
+ if($adver->total_price!='0.000'&&$adver->total_price>0){
|
|
|
+ $order=Order::where('order_no','=',$adver->order_no)
|
|
|
+ ->select('order_no','pay_no','price','pay_type','is_pay')
|
|
|
+ ->first();
|
|
|
+ if(empty($order))return showJsonErr('当前订单数据不完整无法原路退款!');
|
|
|
+ $remark='原路退款异常';
|
|
|
+ //如果订单为未付款就不走退款操作了
|
|
|
+ try{
|
|
|
+ if($order->is_pay==1){
|
|
|
+ if(in_array($order->pay_type,[2,21]) && $adver->status!=5){
|
|
|
+ $pay = \App::make('aliPay');
|
|
|
+ $r=$pay->getReturnInfo($order->order_no, $order->pay_no,$order->price);
|
|
|
+ if($r->code==10000){
|
|
|
+ $remark='您发布的广告-'.$adver->title.'-审核不通过,资金原路退回支付宝';
|
|
|
+ }
|
|
|
+ }elseif(in_array($order->pay_type,[3,31]) && $adver->status!=5){
|
|
|
+ //微信退款
|
|
|
+ $pay = \App::make('wechat');
|
|
|
+ $r=$pay->getReturnInfo($order->order_no, $order->pay_no,$order->price,$order->price);
|
|
|
+ if($r->return_code=='SUCCESS'){
|
|
|
+ $remark='您发布的广告-'.$adver->title.'-审核不通过,资金原路退回微信账户';
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ AccountLog::saveDataByPost($adver->uid,44,$order->price,User::whereId($adver->uid)->value('balance'),2,1,$remark);
|
|
|
+
|
|
|
+ }
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return showJsonErr($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $msg_content=MsgTemplate::getTemplateContent(3,['date' => $adver->created_at, 'adverid' => $adver->id, 'title' => $adver->title, 'totalprice' => $adver->total_price]);
|
|
|
+ $msgarr=['title'=>'广告审核通知','uid'=>$adver->uid,'type'=>12,'content'=>$msg_content];
|
|
|
+ UserMsg::SendGetui($msgarr);
|
|
|
+
|
|
|
+ $param['status']=5;
|
|
|
+ $betdata=[
|
|
|
+ 'refuse_desc'=>$param['bet_rejuse_remark']
|
|
|
+ ];
|
|
|
+ \DB::table('advertising_bet')->where('id','=',$bet->id)->update($betdata);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($param['bet_rejuse_remark']))unset($param['bet_rejuse_remark']);
|
|
|
+ unset($param['s']);
|
|
|
+ if (!Advertising::whereId($param['id'])->update($param)) {
|
|
|
+
|
|
|
+ return showJsonErr('审核失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ return showJsonSucc('审核成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 广告详情
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/4/23
|
|
|
+ * @param Request $request
|
|
|
+ * @description
|
|
|
+ * edit by wsl 20190730
|
|
|
+ */
|
|
|
+ public function show(Request $request)
|
|
|
+ {
|
|
|
+ if(empty($request->post('id'))){
|
|
|
+ return showJsonErr('id不能为空');
|
|
|
+ }
|
|
|
+ $adver = Advertising::whereId($request->post('id'))->select()->first();
|
|
|
+ if ($adver) {
|
|
|
+ if($adver->industry!='all'){
|
|
|
+ $arr=explode(',',$adver->industry);
|
|
|
+ $adver->industry = Industry::whereIn('id',$arr)->select(['id','content'])->get();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($adver->guarantee==1){
|
|
|
+ $adver->bet=\DB::table('advertising_bet')->where('advertising_id','=',$adver->id)->first();
|
|
|
+ }
|
|
|
+ $adver->provincestr=Area::whereId($adver->province)->value('name');
|
|
|
+ $adver->citystr=Area::whereId($adver->city)->value('name');
|
|
|
+ $adver->districtstr=Area::whereId($adver->district)->value('name');
|
|
|
+ }
|
|
|
+ return showJsonSucc(1001, $adver);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新广告
|
|
|
+ * @author lyh
|
|
|
+ * @date 2019/4/23
|
|
|
+ * @param Request $request
|
|
|
+ * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ public function modify(Request $request)
|
|
|
+ {
|
|
|
+
|
|
|
+ $validator = Validator::make($param = $request->all(), [
|
|
|
+ 'id' => 'required|exists:advertising,id',
|
|
|
+ 'title' => 'required|string',
|
|
|
+ 'scene' => 'between:1,3',
|
|
|
+ 'image' => 'string',
|
|
|
+// 'content' => '',
|
|
|
+ 'industry' => 'required|exists:industry,id',
|
|
|
+ 'province' => 'required|exists:area,id',
|
|
|
+ 'city' => 'required|exists:area,id',
|
|
|
+ 'district' => 'required|exists:area,id'
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return showJsonErr($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $adver = Advertising::find($param['id']);
|
|
|
+
|
|
|
+ if ($adver->status == 3 && $adver->is_update == 1) {
|
|
|
+ return showJsonErr('抱歉,广告不能编辑');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($adver->guarantee == 1) {
|
|
|
+ $param['bet_status'] = 3;
|
|
|
+ }
|
|
|
+ if (!empty($param['image'])) {
|
|
|
+ $param['image_group']=$param['image'];
|
|
|
+ $param['image'] = explode(',', $param['image_group'])[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ $param['status'] = 2;
|
|
|
+ $param['is_update'] = 1;
|
|
|
+ $result = Advertising::whereId($param['id'])->update($param);
|
|
|
+ if (!$result) {
|
|
|
+ return showJsonErr('编辑广告失败');
|
|
|
+ }
|
|
|
+ return showJsonSucc('编辑广告成功,已重新提交审核');
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|