| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529 | <?php/** * Created by PhpStorm. * User: wuzhenke * Date: 2018/11/16 * Time: 11:17 */namespace App\Http\Controllers\Jkq\Company;use Aix\Pay\Data\PayOrder;use App\Exceptions\ResponseException;use App\Http\Controllers\Jkq\JkqBaseController;use App\Models\Jobs;use App\Models\Promotion;use App\Repositories\JobsRepository;use App\Repositories\MemberHandselRepository;use App\Repositories\MemberLogRepository;use App\Repositories\MembersChargeLogRepository;use App\Repositories\PromotionRepository;use App\Repositories\QueueAutoRefreshRepository;use App\Services\Common\MembersSetmealService;use App\Services\Common\OrderService;use App\Services\Common\PaymentService;use App\Services\Common\PayService;use App\Services\Common\SetmealIncrementsService;use App\Services\Common\SetmealService;use App\Services\Company\CompanyService;use App\Services\Company\CompanyTplService;use App\Services\Company\ComplaintConsultantService;use App\Services\Company\ServiceService;use App\Services\Person\MemberPointService;use Illuminate\Http\Request;use Illuminate\Support\Facades\DB;class ServiceController extends JkqBaseController{    protected $serviceService;    protected $membersSetmealService;    protected $payService;    protected $setmealService;    protected $memberPointService;    protected $orderService;    protected $memberLogRepository;    protected $memberHandselRepository;    protected $membersChargeLogRepository;    protected $paymentService;    protected $setmealIncrementsService;    protected $companyService;    protected $queueAutoRefreshRepository;    protected $jobsRepository;    protected $promotionRepository;    protected $companyTplService;    protected $complaintConsultantService;    /**     * ServiceController constructor.     * @param $serviceService     * @param $membersSetmealService     * @param $payService     * @param $setmealService     * @param $memberPointService     * @param $orderService     * @param $memberLogRepository     * @param $memberHandselRepository     * @param $membersChargeLogRepository     * @param $paymentService     * @param $setmealIncrementsService     * @param $companyService     * @param $queueAutoRefreshRepository     * @param $jobsRepository     * @param $promotionRepository     */    public function __construct(ServiceService $serviceService, PromotionRepository $promotionRepository, JobsRepository $jobsRepository, QueueAutoRefreshRepository $queueAutoRefreshRepository, CompanyService $companyService, SetmealIncrementsService $setmealIncrementsService, PaymentService $paymentService, MembersChargeLogRepository $membersChargeLogRepository, MemberHandselRepository $memberHandselRepository, MemberLogRepository $memberLogRepository, OrderService $orderService, MemberPointService $memberPointService, MembersSetmealService $membersSetmealService, PayService $payService, SetmealService $setmealService, CompanyTplService $companyTplService, ComplaintConsultantService $complaintConsultantService)    {        $this->serviceService = $serviceService;        $this->membersSetmealService = $membersSetmealService;        $this->payService = $payService;        $this->setmealService = $setmealService;        $this->memberPointService = $memberPointService;        $this->orderService = $orderService;        $this->memberLogRepository = $memberLogRepository;        $this->memberHandselRepository = $memberHandselRepository;        $this->membersChargeLogRepository = $membersChargeLogRepository;        $this->paymentService = $paymentService;        $this->setmealIncrementsService = $setmealIncrementsService;        $this->companyService = $companyService;        $this->queueAutoRefreshRepository = $queueAutoRefreshRepository;        $this->jobsRepository = $jobsRepository;        $this->promotionRepository = $promotionRepository;        $this->companyTplService = $companyTplService;        $this->complaintConsultantService = $complaintConsultantService;    }    /**我的套餐     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     */    public function index()    {        $user = auth('web-company')->user();//企业信息        $res = $this->serviceService->index($user);        return view('jkq.company.service.index', $res);    }    public function setmealDetail(Request $request)    {        $user = auth('web-company')->user();//企业信息        $res = $this->serviceService->setmealDetail($request->all(), $user);        return view('jkq.company.service.setmeal_detail', $res);    }    /**积分任务     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     */    public function points()    {        $user = auth('web-company')->user();        $res = $this->serviceService->points($user);        return view('jkq.company.service.points', $res);    }    /**积分明细     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     */    public function pointsDetail(Request $request)    {        $user = auth('web-company')->user();        $type = $request->type?$request->type:1;        $res = $this->serviceService->pointsDetail(3, $user);        return view('jkq.company.service.points_detail', $res);    }    /**套餐升级     * @param $id     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     * @throws \App\Exceptions\ResponseException     */    public function setmealAdd($id)    {        $user = auth('web-company')->user();        if (!$id) {            throw new ResponseException('请选择正确的套餐!', '', 404);        }        $setmeal = $this->serviceService->setmealAdd($id, $user);        return view('jkq.company.service.setmeal_add', $setmeal);    }    /**套餐弹窗     * @return \Illuminate\Http\JsonResponse     * @throws \Throwable     */    public function paySetmeal()    {        $user = auth('web-company')->user();        $mysetmeal = $this->membersSetmealService->getSetmealByUid($user->id, $user->utype);        if (config('aix.companyset.setmeal_com.setmeal_com_set.is_superposition') == 0 && config('aix.companyset.setmeal_com.setmeal_com_set.is_superposition_time') == 0) {   //项目和时间都不叠加            $tip = '您当前是【' . $mysetmeal->setmeal_name . '】重新开通套餐<br /><span class="font_yellow">1. 原有套餐资源以新开套餐资源为准;</span><br /><span class="font_yellow">2. 原有会员服务时长以新开套餐时长为准;</span><br />确定要重新开通套餐吗?';        } elseif (config('aix.companyset.setmeal_com.setmeal_com_set.is_superposition') == 0 && config('aix.companyset.setmeal_com.setmeal_com_set.is_superposition_time') == 1) { //项目不叠加时间叠加            $tip = '您当前是【' . $mysetmeal->setmeal_name . '】重新开通套餐<br /><span class="font_yellow">您的原套餐资源会被新开通的套餐资源覆盖</span><br />确定要重新开通套餐吗?';        } elseif (config('aix.companyset.setmeal_com.setmeal_com_set.is_superposition') == 1 && config('aix.companyset.setmeal_com.setmeal_com_set.is_superposition_time') == 0) { //项目叠加时间不叠加            $tip = '您当前是【' . $mysetmeal->setmeal_name . '】重新开通套餐<br /><span class="font_yellow">您的会员服务时长将以新开套餐服务时长为准</span><br />确定要重新开通套餐吗?';        } else {            $tip = '您当前是【' . $mysetmeal->setmeal_name . '】重新开通套餐<br /><span class="font_yellow">您的套餐资源和会员时长将叠加</span><br />确定要重新开通套餐吗?';        }        return response()->json(['status' => 1, 'data' => ['html' => view('jkq.company.ajax.ajax_warning', ['tip' => $tip])->render()]]);    }    /**会员套餐     * @param Request $request     * @return \Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    public function setmealAddSave(Request $request)    {        $user = auth('web-company')->user();        //检查未处理订单数        $order_pay_type = 1;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('points', '');        $setmeal_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        if ($payment_name == 'wechat') {            $type = 'scan';        } elseif ($payment_name == 'alipay') {            $type = 'web';        } elseif ($payment_name == 'offline') {            $is_deductible=0;            $type = 'pay';        }        if ($is_deductible == 0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = $request->input('amount', '');//应当付款价格        if ($amount == 0) {            $pay_type = 'points';        }        if ($deductible>0) {            $m_amount = floatval($deductible/config('aix.companyset.points.points_set.payment_rate')); //积分充值比例        } else {            $m_amount =0;//应该减去的钱        }        if ($setmeal_id == 0 || $setmeal_id==1) {            throw new ResponseException(AjaxError("请选择套餐",0));        }        $setmealInfo = $this->setmealService->getSetmealOne($setmeal_id);//套餐详情        if ($setmealInfo->apply==0){            throw new ResponseException(AjaxError("改套餐不可购买",0));        }        $mypoints = $this->memberPointService->getPoints($user->id, $user->utype);        $amount = $setmealInfo->expense;//套餐的价格        $price=$amount-$m_amount; //套餐-积分兑换的钱        $price=round($price, 2); //去小数点        $service_need_points = round($amount * config('aix.companyset.points.points_set.payment_rate'));        if (!config('aix.companyset.setmeal_com.setmeal_com_set.setmeal_by_points')) {            $is_deductible = 0;            $deductible = 0;            $pay_type = 'cash';        }        if ($pay_type == 'points') {            DB::beginTransaction();            try {                if ($mypoints->points < $service_need_points) {                    throw new \Exception('积分不足,请使用其他方式支付!');                }                $set_setmeal = $this->serviceService->setMembersSetmeal($user, $setmeal_id);                if (!$set_setmeal['status']) {                    throw new \Exception($set_setmeal['msg']);                }                $description = '购买服务:' . $setmealInfo->setmeal_name . ';积分支付:' . $service_need_points . "积分";                $order = $this->orderService->addOrder($user, 1, $setmealInfo->expense, 0, $service_need_points, $setmealInfo->setmeal_name, 'points', '积分支付', $description, 2, 0, $setmeal_id, time(), '');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //生成会员日志                $this->memberLogRepository->createLog($user, 9001, [$oid, '积分支付','']);                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'points_buy_setmeal';                    $handsel['htype_cn'] = '购买增值包:' . $setmealInfo->setmeal_name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                    $notes = date('Y-m-d H:i:s', time()) . "通过积分兑换成功开通{ $setmealInfo->setmeal_name}";                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return response()->json(['status' => 0, 'msg' => $e->getMessage()]);            }            return response()->json(['status' => 1, 'data' => $oid]);        } else {            if ($is_deductible == 1 && $mypoints->points < $deductible) {                throw new ResponseException('积分不足,请使用其他方式支付!');            }            if ($is_deductible == 1 && $deductible > 0) {                $description = $setmealInfo->setmeal_name . ';积分抵扣:' . $deductible . '积分';            }            if ($deductible > 0 && $is_deductible) {                $amount = $amount - floatval($deductible / config('aix.companyset.points.points_set.payment_rate'));            }            $paysetarr['ordtotal_fee'] = $price;            $payment = $this->paymentService->returnPayment($payment_name);            $description = '购买服务:' . $setmealInfo->setmeal_name . ';' . $payment->name . $paysetarr['ordtotal_fee'];            if ($deductible > 0 && $is_deductible == 1) {                $description .= ';积分支付:' . $deductible . '积分';            }            $params = [                'setmeal_id'=>$setmealInfo->id,                'setmeal_name'=>$setmealInfo->setmeal_name,                'company_id'=>$user->id,                'utype'=>$user->utype,                'companyname'=>$user->companyname,                'amount'=>$paysetarr['ordtotal_fee'],                'points'=>$deductible,                'payment'=>$payment_name,                'username'=>$user->username,                'subsite_id'=>$user->subsite_id,            ];            $insert_id = $this->orderService->addOrder($user, 1, $price, $paysetarr['ordtotal_fee'], $deductible, $setmealInfo->setmeal_name, $payment_name, $payment->name, $description, 1, $deductible, $setmeal_id, 0, serialize($params));            $tradeNo = $this->payService->getTradeNo($insert_id->id);            if (!$this->serviceService->updateOid($insert_id->id, $tradeNo)) {                throw new ResponseException('生成订单号失败');            }            $payOrder = new PayOrder();            $payOrder->trade_no = $tradeNo;            $payOrder->subject = '购买' . $setmealInfo->setmeal_name;            $payOrder->detail = $description;            $payOrder->price = $price;            $payOrder->callback = "App\Services\Common\OrderService.updateCompany";            $payOrder->return_url = route('jkq.service.order.index');            $result = $this->payService->pay($payment_name, $type, $payOrder);            if ($payment_name == 'wechat') {                return response()->json([                    'status' => 1,                    'tradeCode' => get_qrcode_html($result->code_url),                    'tradeNo' => $tradeNo,                ]);            } elseif ($payment_name =='alipay') {                return $result;            } else {                return response()->json([                    'status'=>1,                    'tradeNo'=>$tradeNo,                    'url'=>route("jkq.service.order.detail",['id'=>$insert_id->id]),                ]);            }        }    }    /**订单状态     * @param Request $request     * @return \Illuminate\Http\JsonResponse     */    public function checkOrderStatus(Request $request)    {        $tradeNo = $request->tradeNo;        if (!$tradeNo) {            return response()->json(['status' => 0, 'msg' => "订单号错误!"]);        }        return $this->orderService->getOrderbyTradeNo($tradeNo);    }    /**     * @return \Illuminate\Http\JsonResponse     * @throws \Throwable     */    public function paySetmealStatus()    {        $tip = '请在新打开的支付页面完成付款';        $description = '付款完成前请不要关闭此窗口,付款后请根据您的情况点击下面的按钮,如果在支付中遇到问题请到<a target="_blank" href="">帮助中心</a>。';        return response()->json(['status' => 1, 'html' => view('jkq.company.ajax.ajax_warning', ['tip' => $tip, 'description' => $description])->render()]);    }    /**增值服务     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     */    public function increment()    {        $res = $this->serviceService->increment(auth('web-company')->user());        return view('jkq.company.increment.index', $res);    }    /**各增值包     * @param Request $request     * @param $cat     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     * @throws ResponseException     */    public function incrementAdd(Request $request, $cat)    {        switch ($cat) {            case 'download_resume':            case 'sms':            case 'jobs':            case 'jobfair_num':                $display_tpl = "resume_sms";                break;            case 'stick':            case 'emergency':                $display_tpl = 'stick_emergency';                break;            case 'tpl':                $display_tpl = 'tpl';                break;            case 'auto_refresh_jobs':                $display_tpl = 'auto_refresh_jobs';                break;            default:                throw new ResponseException('参数错误');                break;        }        $res = $this->serviceService->incrementAdd($cat, $request->all());        return view("jkq.company.increment.increment_add_{$display_tpl}", $res);    }    /**增值服务 === 提示框内容     * @return \Illuminate\Http\JsonResponse     * @throws \Throwable     */    public function confirmPayIncrement()    {        $user = auth('web-company')->user();        $res = $this->serviceService->confirmPayIncrement($user);        return response()->json(['status'=>1, 'msg'=>'success','data'=>['html'=>view('jkq.company.ajax.ajax_warning', $res)->render()]]);    }    /**增值服务保存     * @param Request $request     * @return \Illuminate\Http\JsonResponse     */    public function incrementPaySave(Request $request)    {        $service_type = $request->input('service_type', '');        if (!$service_type) {            return response()->json(['status'=>0,'msg'=>"参数错误"]);        }        switch ($service_type) {            case 'download_resume':                $fun = 'DownloadResume';                break;            case 'sms':                $fun = 'Sms';                break;            case 'jobs':                $fun = 'Jobs';                break;            case 'jobfair_num':                $fun = 'JobfairNum';                break;            case 'stick':                $fun = 'Stick';                break;            case 'emergency':                $fun = 'Emergency';                break;            case 'tpl':                $fun = 'Tpl';                break;            case 'auto_refresh_jobs':                $fun = 'AutoRefreshJobs';                break;        }        $func_name = "increment".$fun;        $incrment_arr = ['download_resume','jobs','jobfair_num','sms','stick','emergency','tpl','auto_refresh_jobs'];        if (!in_array($service_type, $incrment_arr)) {            return response()->json(['status'=>0,'msg'=>"参数错误"]);        } else {            return $this->$func_name($request);        }    }    /**简历包     * @param $request     * @return array|\Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function incrementDownloadResume($request)    {        $cat = $request->input('service_type', 'download_resume');        $order_pay_type = 6;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', 0);        }        $amount = floatval($request->input('amount', 0));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        $user = auth('web-company')->user();        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //增值包套餐金额        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //增值包套餐所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' =>'积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                //会员套餐添加增值包数量                $setmeal_rst = $this->membersSetmealService->actionUserSetmeal(array('uid'=>$user->id, 'utype'=>1), $cat, 1, $increment_info->value);                if (!$setmeal_rst) {                    throw new \Exception('修改会员套餐失败!');                }                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, '', '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_download_resume';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                    $notes = date('Y-m-d H:i:s', time()) . "通过积分兑换成功开通{ $increment_info->name}";                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return response()->json(['status'=>0, 'msg' => $e->getMessage()]);            }            return response()->json(['status'=>1, 'msg' => '积分兑换成功!','data'=>$oid]);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return response()->json(['status'=>1, 'msg' => '积分不足,请使用其他方式支付!']);            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', '', 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    /**短信包     * @param $request     * @return array|\Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function incrementSms($request)    {        $cat = $request->input('service_type', 'sms');        $order_pay_type = 7;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);//        dd($request);        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = floatval($request->input('amount', ''));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        $user = auth('web-company')->user();        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //增值包套餐金额        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //增值包套餐所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                $companySms = $this->companyService->incSms($user->id, 1, $increment_info->value);                if (!$companySms) {                    throw new \Exception('会员短信数量增加失败!');                }                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, '', '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_download_resume';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return array( 'status'=>0, 'msg' => $e->getMessage());            }            return array( 'status'=>1, 'msg' => '积分兑换成功!','data'=>$oid);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return array( 'status'=>0, 'msg' => '积分不足,请使用其他方式支付!');            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', '', 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    protected function incrementJobfairNum($request)    {        $cat = $request->input('service_type', 'jobfair_num');        $order_pay_type = 15;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = floatval($request->input('amount', ''));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        $user = auth('web-company')->user();        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //增值包套餐金额        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //增值包套餐所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                $companySms = $this->membersSetmealService->actionUserSetmeal($user->id, 'jobfair_num', 1, $increment_info->value);                if (!$companySms) {                    throw new \Exception('会员招聘会场次数量增加失败!');                }                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, '', '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_jobfair_num';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return array( 'status'=>0, 'msg' => $e->getMessage());            }            return array( 'status'=>1, 'msg' => '积分兑换成功!','data'=>$oid);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return array( 'status'=>0, 'msg' => '积分不足,请使用其他方式支付!');            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', '', 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    /**购买职位增值包     * @param $request     * @return array|\Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function incrementJobs($request)    {        $cat = $request->input('service_type', 'jobs');        $order_pay_type = 15;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = floatval($request->input('amount', ''));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        $user = auth('web-company')->user();        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //增值包套餐金额        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //增值包套餐所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                $companySms = $this->membersSetmealService->actionUserSetmeal($user->id, 'jobs_meanwhile', 1, $increment_info->value);                if (!$companySms) {                    throw new \Exception('会员可发布职位数量增加失败!');                }                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, '', '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_jobs';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return array( 'status'=>0, 'msg' => $e->getMessage());            }            return array( 'status'=>1, 'msg' => '积分兑换成功!','data'=>$oid);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return array( 'status'=>0, 'msg' => '积分不足,请使用其他方式支付!');            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', '', 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    /**职位置顶     * @param $request     * @return \Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function incrementStick($request)    {        $user = auth('web-company')->user();        $cat = $request->input('service_type', 'stick');        $order_pay_type = 8;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        $jobs_id = $request->input('jobs_id', 0);        $form_validate = $request->input('form_validate', false); //支付宝支付是Form 表单提交的,错误信息返回json,不是form的就不进行callback        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = floatval($request->input('amount', ''));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        if (!$jobs_id) {            return response()->json(['status'=>0, 'msg'=>"请选择职位!"]);        }        if (!$jobsRes = $this->jobsRepository->findWhere(['id'=>$jobs_id,'company_id'=>$user->id])->first()) {            return response()->json(['status'=>0,'msg'=>'该职位不存在!']);        }        if ($this->jobsRepository->getInfo(['stick'=>1,'id'=>$jobs_id,])) {            return response()->json(['status'=>0,'msg'=>'该职位已置顶!']);        }        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //智能刷新所需积分        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //智能刷新所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                $promotionsqlarr['companyid']=$user->id;                $promotionsqlarr['jobid']=$jobs_id;                $promotionsqlarr['ptype'] = 1;                $promotionsqlarr['days']=$increment_info->value;                $promotionsqlarr['starttime']=time();                $promotionsqlarr['endtime']=strtotime("{$increment_info->value} day");                $promotion_insert_id = Promotion::create($promotionsqlarr);                if (!$promotion_insert_id) {                    throw new \Exception('职位置顶添加失败!');                }//                $refresh_time = $this->jobsRepository->getFires($jobs_id);                $stick_time = time();                $this->jobsRepository->update(['stime'=>$stick_time, 'stick'=>1], $jobs_id);                $params_array = array('days'=>$increment_info['value']);                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                $params_array['jobs_id'] = $jobs_id;                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, serialize($params_array), '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_download_resume';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return response()->json(['status'=>0, 'msg' => $e->getMessage()]);            }            event_search_update(Jobs::class, (string)$jobs_id, 'update');            return response()->json(['status'=>1, 'msg' => '积分兑换成功!','data'=>$oid]);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!!']);            }            if ($form_validate){//是否是表单验证的                //返回之后支付宝再用form 表单再请求一遍                return response()->json(['status'=>1, 'msg' => '验证成功!']);            }            $params['jobs_id'] = $jobs_id;            $params['days'] = $increment_info['value'];            $nowtime = time();            $params['starttime'] = $nowtime;            for ($i=0; $i < $params['days']*4; $i++) {                $timespace = 3600*6*$i;                if ($i+1==$params['days']*4) {                    $params['endtime'] = $nowtime+$timespace;                }            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', $params, 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    /**职位紧急     * @param $request     * @return \Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function incrementEmergency($request)    {        $user = auth('web-company')->user();        $cat = $request->input('service_type', 'emergency');        $order_pay_type = 9;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        $jobs_id = $request->input('jobs_id', 0);        $form_validate = $request->input('form_validate', false); //支付宝支付是Form 表单提交的,错误信息返回json,不是form的就不进行callback        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = floatval($request->input('amount', ''));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        if (!$jobs_id) {            return response()->json(['status'=>0, 'msg'=>"请选择职位!"]);        }        if (!$jobsRes = $this->jobsRepository->findWhere(['id'=>$jobs_id,'company_id'=>$user->id])->first()) {            return response()->json(['status'=>0,'msg'=>'该职位不存在!']);        }        if ($this->jobsRepository->getInfo(['emergency'=>1,'id'=>$jobs_id,])) {            return response()->json(['status'=>0,'msg'=>'该职位已紧急!']);        }        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //智能刷新所需积分        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //智能刷新所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                $promotionsqlarr['companyid']=$user->id;                $promotionsqlarr['jobid']=$jobs_id;                $promotionsqlarr['ptype'] = 2;                $promotionsqlarr['days']=$increment_info->value;                $promotionsqlarr['starttime']=time();                $promotionsqlarr['endtime']=strtotime("{$increment_info->value} day");                $promotion_insert_id = $this->promotionRepository->create($promotionsqlarr);                if (!$promotion_insert_id) {                    throw new \Exception('职位紧急添加失败!');                }                $this->jobsRepository->update(['emergency'=>1], $jobs_id);                $params_array = array('days'=>$increment_info['value']);                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                $params_array['jobs_id'] = $jobs_id;                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, serialize($params_array), '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_download_resume';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return response()->json(['status'=>0, 'msg' => $e->getMessage()]);            }            event_search_update(Jobs::class, (string)$jobs_id, 'update');            return response()->json(['status'=>1, 'msg' => '积分兑换成功!','data'=>$oid]);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!!']);            }            if ($form_validate){//是否是表单验证的                //返回之后支付宝再用form 表单再请求一遍                return response()->json(['status'=>1, 'msg' => '验证成功!']);            }            $params['jobs_id'] = $jobs_id;            $params['days'] = $increment_info['value'];            $nowtime = time();            $params['starttime'] = $nowtime;            for ($i=0; $i < $params['days']*4; $i++) {                $timespace = 3600*6*$i;                if ($i+1==$params['days']*4) {                    $params['endtime'] = $nowtime+$timespace;                }            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', $params, 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    /**企业模版     * @param $request     * @return ServiceController     */    protected function incrementTpl(Request $request)    {        $result = $this->companyTplService->incrementTpl(auth('web-company')->user(), $request->all(), $request->route());        if ($result['code']=='wechat') {            if ($result['type']=='wap') {                return $result['tradeCode'];            } else {                return json_encode(['tradeCode'=>$result['tradeCode'],'tradeNo'=>$result['tradeNo']]);            }        } elseif ($result['code']=='alipay') {            return $result['tradeCode'];        } elseif ($result['code']=='offline') {            return json_encode(['tradeNo'=>$result['tradeNo']]);        } else {            if ($result['status']==1) {                return $this->sendSuccessResponse($result['info']);            } else {                return $this->sendErrorResponse($result['info'], '', 400);            }        }    }    /**智能刷新     * @param $request     * @return \Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function incrementAutoRefreshJobs($request)    {        $cat = $request->input('service_type', 'auto_refresh_jobs');        $order_pay_type = 12;        $payment_name = $request->input('payment_name', '');        $pay_type = $request->input('pay_type', 'points');        $project_id = $request->input('project_id', 0);        $is_deductible = $request->input('is_deductible', 0);        $jobs_id = $request->input('id', 0);        $form_validate = $request->input('form_validate', false); //支付宝支付是Form 表单提交的,错误信息返回json,不是form的就不进行callback        if ($is_deductible==0) {            $deductible = 0;        } else {            $deductible = $request->input('deductible', '');        }        $amount = floatval($request->input('amount', ''));        if ($amount==0) {            $pay_type = 'points';        }        if ($project_id==0) {            return response()->json(['status'=>0, 'msg' => '请选择增值包套餐!']);        }        if (!$jobs_id) {            return response()->json(['status'=>0, 'msg'=>"请选择职位!"]);        }        if ($this->queueAutoRefreshRepository->findData(['type'=>1, 'pid'=>$jobs_id])) {            return response()->json(['status'=>0,'msg'=>'该职位已预约刷新!']);        }        $user = auth('web-company')->user();        $my_setmeal =  $this->membersSetmealService->getUserSetmeal($user, '1');    //会员套餐信息        if (isExpire($my_setmeal)){            return response()->json( ['status' => 0, 'msg' => "提醒:您的套餐已到期,请及时到我的套餐处升级套餐!"]);        }        $my_point = $this->memberPointService->getPoints($user->id, 1);  //获取会员积分信息        $increment_info = $this->setmealIncrementsService->getIncrement($project_id);       //获取所选简历增值包信息        $my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal);     //套餐折扣        $service_need_cash = $my_discount > 0 ?round($increment_info->price*$my_discount/10, 2):$increment_info->price; //智能刷新所需积分        if ($pay_type=='points') {      //积分支付            $service_need_points = round($service_need_cash*config('aix.companyset.points.points_set.payment_rate'));   //智能刷新所需积分            if ($my_point->points < $service_need_points) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!']);            }            //操作事务开始            DB::beginTransaction();            try {                //添加自动刷新记录                $days = $increment_info->value;                $params_array['days'] = $days;                $nowtime = time();                $params_array['days'] = $nowtime;                $params_array['starttime'] = $nowtime;                for ($i=0; $i < $days*4; $i++) {                    $timespace = 3600*6*$i;                    $this->queueAutoRefreshRepository->create(['uid'=>$user->id,'pid'=>$jobs_id,'type'=>1,'refreshtime'=>$nowtime+$timespace]);                    if ($i+1==$days*4) {                        $params_array['endtime'] = $nowtime+$timespace;                    }                }                $params_array['jobs_id'] = $jobs_id;                $description1 = '购买服务:'.$increment_info->name.';积分支付:'.$service_need_points.'积分';                $stime = time();                //添加订单信息                $order = $this->orderService->addOrder($user, $order_pay_type, $service_need_cash, 0, $service_need_points, $increment_info->name, $payment_name, '积分支付', $description1, 2, 0, $project_id, $stime, serialize($params_array), '专享'.$my_discount.'折优惠');                if (!$order) {                    throw new \Exception('生成订单失败!');                }                $oid = $this->payService->getTradeNo($order->id);//订单号                if (!$this->serviceService->updateOid($order->id, $oid)) {                    throw new \Exception('生成订单号失败!');                }                //会员日志:添加创建增值服务订单日志                $log_rst1 = $this->serviceService->writeMembersLog($user, '9001', [$oid,'积分兑换','']);                //修改会员积分                if (false === $p_rst = $this->memberPointService->reportDeal($user->id, $user->utype, 2, $service_need_points)) {                    throw new \Exception('修改会员积分失败!');                } else {                    $handsel['uid'] = $user->id;                    $handsel['utype'] = $user->utype;                    $handsel['htype'] = 'increment_download_resume';                    $handsel['htype_cn'] = '购买增值包:' . $increment_info->name;                    $handsel['operate'] = 2;                    $handsel['points'] = $service_need_points;                    if (!$this->memberHandselRepository->addNew($handsel)) { //添加积分操作记录                        throw new \Exception('添加积分操作记录失败!');                    }                }                DB::commit();            } catch (\Exception $e) {                DB::rollback();                return response()->json(['status'=>0, 'msg' => $e->getMessage()]);            }            return response()->json(['status'=>1, 'msg' => '积分兑换成功!','data'=>$oid]);        } else {            if ($is_deductible==1 && $my_point->points<$deductible) {                return response()->json(['status'=>0, 'msg' => '积分不足,请使用其他方式支付!!']);            }            if ($form_validate){//是否是表单验证的                //返回之后支付宝再用form 表单再请求一遍                return response()->json(['status'=>1, 'msg' => '验证成功!']);            }            $params['jobs_id'] = $jobs_id;            $params['days'] = $increment_info['value'];            $nowtime = time();            $params['starttime'] = $nowtime;            for ($i=0; $i < $params['days']*4; $i++) {                $timespace = 3600*6*$i;                if ($i+1==$params['days']*4) {                    $params['endtime'] = $nowtime+$timespace;                }            }            return $this->callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name, $service_need_cash, $is_deductible, $deductible, '', $params, 0, $project_id, '专享'.$my_discount.'折优惠');        }    }    /**购买积分     * @return ServiceController|\Illuminate\Contracts\View\Factory|\Illuminate\View\View     */    public function pointsAdd()    {        if (!config('aix.companyset.points.points_set.enable_com_buy_points')) {            return $this->sendErrorResponse('参数错误!', 404);        }        $res = $this->serviceService->pointsAdd();        return view('jkq.company.increment.points_add', $res);    }    public function pointsSave(Request $request)    {        if (!config('aix.companyset.points.points_set.enable_com_buy_points')) {            return $this->sendErrorResponse('企业充值未开启,请联系网站管理员!', 404);        }        $payment_name = $request->input('payment_name', '');        $points = $request->input('points', 0);        if (!$points) {            return response()->json(['status'=>0, 'msg'=>"请输入要购买的积分数量!"]);        } elseif ($points < config('aix.companyset.points.points_set.com_buy_points_min')) {            $points = config('aix.companyset.points.points_set.com_buy_points_min');        }        $service_need_cash = round($points/config('aix.companyset.points.points_set.payment_rate'), 2);        $paymenttpye = $this->paymentService->returnPayment($payment_name);        if (!$paymenttpye) {            return array( 'status'=>0, 'msg' => '支付方式错误!');        }        $user = auth('web-company')->user();        $description = '购买积分';        $params['points'] = $points;        $params['cash'] = $service_need_cash;        $params['rate'] = config('aix.companyset.points.points_set.payment_rate');        $order = $this->orderService->addOrder($user, 2, $service_need_cash, $service_need_cash, 0, '购买积分', $payment_name, $paymenttpye->name, $description, 1, 0, 0, 0, serialize($params));        $tradeNo = $this->payService->getTradeNo($order->id);        if (!$this->serviceService->updateOid($order->id, $tradeNo)) {            throw new ResponseException('生成订单号失败!');        }        if ($payment_name == 'wechat') {            $type = 'scan';        } elseif ($payment_name == 'offline') {            $type = 'pay';        } else {            $type = 'web';        }        $payOrder = new PayOrder();        $payOrder->trade_no = $tradeNo;        $payOrder->subject = '购买积分';        $payOrder->detail = $description;        $payOrder->price = $service_need_cash;        $payOrder->callback = "App\Services\Common\OrderService.pointsSave";        $result = $this->payService->pay($payment_name, $type, $payOrder);        if ($payment_name == 'wechat') {            return response()->json([                'status' => 1,                'tradeCode' => get_qrcode_html($result->code_url),                'tradeNo' => $tradeNo,            ]);        } elseif ($payment_name == 'offline') {            return response()->json([                'status'=>1,                'tradeNo'=>$tradeNo,                'url'=>route("service.order.detail",['id'=>$order->id]),            ]);        } else {            return $result;        }    }    /**现金支付     * @param $resume_id     * @param $my_setmeal     * @param $my_point     * @param $increment_info     * @param $order_pay_type     * @param string $payment_name     * @param string $amount     * @param $is_deductible     * @param int $deductible     * @param string $description     * @param string $params     * @param int $points     * @param int $stemeal     * @param string $discount     * @return \Illuminate\Http\JsonResponse     * @throws ResponseException     * @throws \Prettus\Validator\Exceptions\ValidatorException     */    protected function callCashPay($my_setmeal, $my_point, $increment_info, $order_pay_type, $payment_name = '', $amount = '0.0', $is_deductible, $deductible = 0, $description = '', $params = '', $points = 0, $stemeal = 0, $discount = '')    {        //获取支付方式        $paymenttpye = $this->paymentService->returnPayment($payment_name);        if (!$paymenttpye) {            return array( 'status'=>0, 'msg' => '支付方式错误!');        }        if (!config("aix.system.pay.{$payment_name}.is_on")) {            if ($payment_name == 'alipay') {                return "支付方式未开启!请联系客服电话:【".config('aix.system.pay.offline.service_tel')."】";            } else {                return array( 'status'=>0, 'msg' => "支付方式未开启!请联系客服电话:【".config('aix.system.pay.offline.service_tel')."】");            }        }        if ($payment_name == 'wechat') {            $type = 'scan';        } elseif ($payment_name == 'alipay') {            $type = 'web';        } elseif ($payment_name == 'offline') { //如果是线下转账            /**             * 把积分设为0,产生原因:线下线上用的同一个请求参数,             * 切换时候没有擦除,会带上积分             * bug-#1255             */            $is_deductible=0;            $type='pay';        }        if ($my_point->points < $deductible) {            return array( 'status'=>0, 'msg' => '积分不足,请使用其他方式支付!');        }        if ($is_deductible==0) {            $deductible = 0;        }        if ($deductible>0) {            $m_amount = round($amount- floatval($deductible/config('aix.companyset.points.points_set.payment_rate')),2);        } else {            $m_amount = $amount;        }        $paysetarr['ordtotal_fee']=$m_amount;        if ($description=='') {            $description = '购买服务:'.$increment_info->name;        }        $description .= ';'.$paymenttpye->name.$paysetarr['ordtotal_fee'].'元';        if ($deductible>0) {            $description .= ';积分支付:'.$deductible.'积分';        }        $stime = time();        $user = auth('web-company')->user();        //生成订单        $order = $this->orderService->addOrder($user, $order_pay_type, $amount, $paysetarr['ordtotal_fee'], $deductible, $increment_info->name, $payment_name, $paymenttpye->name, $description, 1, $deductible, $stemeal, 0, serialize($params), $discount);        $tradeNo = $this->payService->getTradeNo($order->id);        if (!$this->serviceService->updateOid($order->id, $tradeNo)) {            throw new ResponseException('生成订单号失败!');        }        $payOrder = new PayOrder();        $payOrder->trade_no = $tradeNo;        $payOrder->subject = '购买' . $increment_info->name;        $payOrder->detail = $description;        $payOrder->price = round($m_amount, 2);        $payOrder->callback = "App\Services\Common\OrderService.incrementSave";        $payOrder->return_url = route('jkq.service.order.index');        $result = $this->payService->pay($payment_name, $type, $payOrder);        if ($payment_name == 'wechat') {            return response()->json([                'status' => 1,                'tradeCode' => get_qrcode_html($result->code_url),                'tradeNo' => $tradeNo,            ]);        } elseif ($payment_name =='alipay') {            return $result;        } else {            return response()->json([                'status'=>1,                'tradeNo'=>$tradeNo,                'url'=>route("jkq.service.order.detail",['id'=>$order->id]),            ]);        }    }    /**订单列表     * @param Request $request     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     */    public function orderList(Request $request)    {        $user = auth('web-company')->user();        $res = $this->orderService->orderList($request->all(), $user);        return view('jkq.company.order.index', $res);    }    public function templateList()    {        $res = $this->companyTplService->templateList(auth('web-company')->user());        return view('jkq.company.increment.template', $res);    }    public function companyUpdate(Request $request)    {        $result = $this->companyTplService->companyUpdate(auth('web-company')->user(), $request->tpl);        if ($result) {            return $this->sendSuccessResponse('更新成功!');        } else {            return $this->sendErrorResponse('更新失败!');        }    }    public function complaintConsultant(Request $request)    {        if($request->method()=='POST'){            $result = $this->complaintConsultantService->getCompanyConsultant(auth('web-company')->user(), $request->all());            if ($result) {                return $this->sendSuccessResponse('投诉成功!');            } else {                return $this->sendErrorResponse('投诉失败!');            }        }else{            $arr['name'] = $request->name;            $arr['id'] = $request->id;            $html = view('jkq.company.ajax.complaint_consultant', $arr)->render();            return response()->json(['html'=>$html]);        }    }    /**删除订单     * @param Request $request     * @return \Illuminate\Http\JsonResponse     * @throws \Throwable     */    public function orderDel(Request $request)    {        $id = $request->id?$request->id:0;        if (!$id) {            return response()->json(['status'=>0,'msg'=>'参数错误']);        }        if ($request->method()=='POST') {            $user = auth('web-company')->user();            return $this->orderService->orderDel($id,$user);        }        $tip='订单被删除后无法恢复,您确定要删除该订单吗?';        return response()->json(['status'=>1, 'msg'=>'', 'data'=>['html'=>view('jkq.company.ajax.ajax_warning', ['tip'=>$tip])->render()]]);    }    /**订单取消     * @param Request $request     * @return \Illuminate\Http\JsonResponse     * @throws \Throwable     */    public function orderCancel(Request $request)    {        $user = auth('web-company')->user();        $id = $request->id?$request->id:0;        if (!$id) {            return response()->json(['status'=>0,'msg'=>'参数错误']);        }        if ($request->method() == 'POST') {            return $this->orderService->orderCancel($id, $user);        }        $tip='您确定要取消该订单吗?';        $description='如果您在支付过程中遇到问题,可以联系网站客服,联系电话:'.config('aix.system.site.site.bootom_tel').'。';        return response()->json(['status'=>1, 'msg'=>'', 'data'=>['html'=>view('jkq.company.ajax.ajax_warning', ['tip'=>$tip, 'description'=>$description])->render()]]);    }    /**订单详情     * @param $id     * @return ServiceController|\Illuminate\Contracts\View\Factory|\Illuminate\View\View     * @throws ResponseException     */    public function orderDetail($id)    {        if (!$id) {            return $this->sendErrorResponse('参数错误!', 404);        }        $user = auth('web-company')->user();        $res = $this->orderService->orderDetail($id, $user);        if ($res['order']->is_pay==2 || $res['order']->is_pay==3) {            $tpl = 'order_detail';        } else {            $tpl = 'order_detail_nopay';        }        return view("jkq.company.order.{$tpl}", $res);    }    /**索要发票     * @param Request $request     * @return array|\Illuminate\Http\JsonResponse     */    public function invoiceSave(Request $request)    {        $data = $request->except('_token');        $user = auth('web-company')->user();        return $this->orderService->invoiceSave($data, $user);    }    /**重新支付     * @param int $id     * @return ServiceController|\Illuminate\Http\JsonResponse     * @throws ResponseException     */    public function orderPayRepeat($id = 0)    {        if (!$id) {            return $this->sendErrorResponse('参数错误!', 404);        }        return $this->orderService->orderPayRepeat($id);    }    /**     * 电子票据     *///    public function enote($id = 0)//    {//        if (!$id) {//            return response()->json(['status'=>0, 'msg'=>"参数错误!"]);//        }//        $res = $this->orderService->enote($id);//        return response()->json(['status'=>1,'msg'=>'获取数据成功!','data'=>['html'=>view('app.company.ajax.ajax_enote', $res)->render()]]);//    }    /**订单支付成功     * @param $oid     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View     * @throws ResponseException     */    public function setmealFinish($oid)    {        $res = $this->serviceService->setmealFinish($oid);        return view('jkq.company.service.order_finish', $res);    }}
 |