companyTplRepository = $companyTplRepository; $this->companyRepository = $companyRepository; $this->memberPointService = $memberPointService; $this->tplRepository = $tplRepository; $this->memberHandselRepository = $memberHandselRepository; $this->paymentService = $paymentService; $this->payService = $payService; $this->memberSetmealRepository = $memberSetmealRepository; $this->memberLogRepository=$memberLogRepository; } public function templateList($user) { $tplFalse = collect([]); $tplTrue = $this->companyTplRepository->getTplByUid(['uid'=>$user->id]); if($tplTrue->isEmpty()){ $tplFalse = $GLOBALS['template']; }else{ foreach ($tplTrue as $key1=>$val1) { $tplTrue[$key1]->default_tpl = false; if($user->tpl == $val1->tpls->blade_name){ $tplTrue[$key1]->default_tpl = true; } } $tplid = array_unique(array_column($tplTrue->toArray(),'tplid')); if(!$GLOBALS['template']->isEmpty()){ foreach ($GLOBALS['template'] as $key=>$val){ if(in_array($val->id,$tplid)){ unset($GLOBALS['template'][$key]); } } $tplFalse = $GLOBALS['template']; } } return ['tplTrue'=>$tplTrue,'tplFalse'=>$tplFalse]; } public function companyUpdate($user, $tpl) { if (empty($tpl)) { throw new ResponseException('模板文件丢失!'); } $this->memberLogRepository->createLog($user,1031,request('name')); return $this->companyRepository->companySave(['tpl'=>$tpl], $user->id); } public function incrementTpl($user, $input, $route) { $project_id = intval($input['project_id']); if (empty($project_id)) { throw new ResponseException('模板文件丢失!'); } $tpl = $this->tplRepository->find($project_id); if (!$tpl) { throw new ResponseException('模板文件丢失!'); } $companyTpl = $this->companyTplRepository->getTpl(['uid'=>$user->id,'tplid'=>$project_id]); if ($companyTpl) { throw new ResponseException('该模板已购买过!'); } if ($input['pay_type']=='points') { $memberPoint = $this->memberPointService->getPoints($user->id, 1); if (!$memberPoint) { throw new ResponseException('积分不足,请使用其他方式支付!'); } $mysetmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype); if($mysetmeal){ if($mysetmeal->discount_tpl){ $tpl->price = intval(round($tpl->price*$mysetmeal->discount_tpl/10)); } } if ($memberPoint->points < $tpl->price) { throw new ResponseException('积分不足,请使用其他方式支付!'); } //操作事务开始 DB::beginTransaction(); try { $this->companyTplRepository->createTpl(['uid'=>$user->id,'tplid'=>$project_id]); $order = new Order(); $order->uid = $user->id; $order->utype = $user->utype; $order->order_type = 10; $order->pay_type = 1; $order->is_pay = 2; $order->amount = $tpl->price/config('aix.companyset.points.points_set.payment_rate'); $order->pay_points = $tpl->price; $order->payment = 'points'; $order->payment_cn = '积分'; $order->payment_time = time(); $order->service_name = '企业模板'; $order->discount = '企业模板'; $order->description = '购买服务:企业模板('.$tpl->name.')'; $order->setmeal = $project_id; //购买模板的套餐ID 就显示模板ID $order->charge = json_encode($input); $order->save(); $PayService = new PayService(); $order->oid = $PayService->getTradeNo($order->id); $order->save(); $this->memberHandselRepository->addNew( ['uid'=>$user->id, 'utype'=>$user->utype, 'htype'=>'increment_tpl', 'htype_cn'=>'购买企业模板:'.$tpl->name, 'operate'=>2, 'points'=>$tpl->price ] ); MembersPoint::where( ['uid'=>$user->id,'utype'=>$user->utype] )->decrement('points', $tpl->price); DB::commit(); return ['code'=>'points','status'=>1,'info'=>$order->oid]; } catch (\Exception $e) { DB::rollback(); return ['code'=>'points','status'=>0,'info'=>$e->getMessage()]; } } else { $paymenttpye = $this->paymentService->returnPayment($input['payment_name']); if (!$paymenttpye) { throw new ResponseException('支付方式错误!'); } if (is_weixin()) { if ($input['payment_name'] == 'offline') { $type='pay'; } else { $type = 'wap'; } } else { if (strpos($route->uri, 'mobile')!== false) { if ($input['payment_name'] == 'offline') { $type='pay'; } else { $type = 'wap'; } } else { if ($input['payment_name']=='wechat') { $type = 'scan'; } elseif ($input['payment_name'] == 'offline') { $type='pay'; } else { $type = 'web'; } } } $order = new Order(); if ($input['is_deductible']) { $order->pay_type = 3; $order->amount = $input['amount'] + ($input['deductible']/config('aix.companyset.points.points_set.payment_rate')); $order->pay_points = $input['deductible']; $is_deductible = '使用积分抵现(抵扣积分:)'.$input['deductible'].'积分!支付金额:'.$input['amount'].'元'; $order->description = '购买服务:企业模板('.$tpl->name.')'.$is_deductible; } else { $order->pay_type = 2; $order->amount = $input['amount']; $order->pay_points = 0; $is_deductible = '未使用积分抵现!支付金额:'.$input['amount'].'元'; $order->description = '购买服务:企业模板('.$tpl->name.')'.$is_deductible; } $order->discount = '企业模板'; $order->service_name = '企业模板'; $order->order_type = 10; $order->pay_amount = $input['amount']; $order->payment = $input['payment_name']; if ($input['payment_name']=='alipay') { $order->payment_cn = '支付宝'; } elseif ($input['payment_name']=='wechat') { $order->payment_cn = '微信'; } else { $order->payment_cn = '线下转账'; } $input['uid'] = $user->id; $input['utype'] = $user->utype; $order->charge = json_encode($input); $order->uid = $user->id; $order->utype = $user->utype; $order->save(); $tradeNo = $this->payService->getTradeNo($order->id); $payOrder = new PayOrder(); $payOrder->trade_no = $tradeNo; $payOrder->subject = '企业模板'; $payOrder->detail = $order->description; $payOrder->price = $input['amount']; $payOrder->callback = "App\Services\Common\OrderService.incrementTplUpdate"; if ($type == 'web') { $payOrder->return_url=route('service.template.index'); } if ($type=='wap') { if ($input['payment_name']=='wechat') { $payOrder->return_url=route('mobile.common.orderWechat', ['oid'=>$payOrder->trade_no]); } else { $payOrder->return_url=route('mobile.firm.service.order.index'); } } $result = $this->payService->pay($input['payment_name'], $type, $payOrder); $order->oid = $payOrder->trade_no; $order->save(); if ($input['payment_name']=='wechat') { if ($type=='wap') { return [ 'code'=>'wechat', 'tradeCode'=>$result, 'type'=>$type ]; } else { return [ 'code'=>'wechat', 'tradeCode'=>get_qrcode_html($result->code_url), 'tradeNo'=>[ 'number'=>$payOrder->trade_no, ], 'type'=>$type ]; } } elseif ($input['payment_name']=='alipay') { return [ 'code'=>'alipay', 'tradeCode'=>$result, ]; } else { return [ 'code'=>'offline', 'tradeNo'=>$tradeNo ]; } } } }