MemberPointService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <?php
  2. namespace App\Services\Person;
  3. use Aix\Pay\Data\PayOrder;
  4. use App\Exceptions\ResponseException;
  5. use App\Models\Category;
  6. use App\Models\MemberInfo;
  7. use App\Models\MembersHandsel;
  8. use App\Models\MembersPoint;
  9. use App\Models\Order;
  10. use App\Models\Payment;
  11. use App\Models\PersonalServiceStick;
  12. use App\Models\PersonalServiceStickLog;
  13. use App\Models\PersonalServiceTag;
  14. use App\Models\PersonalServiceTagLog;
  15. use App\Models\PersonServiceTagCategory;
  16. use App\Models\Resume;
  17. use App\Models\Tpl;
  18. use App\Repositories\MemberPointRepository;
  19. use App\Repositories\ResumeRepository;
  20. use App\Repositories\TaskLogRepository;
  21. use App\Repositories\TaskRepository;
  22. use App\Services\Common\PayService;
  23. use SimpleSoftwareIO\QrCode\Facades\QrCode;
  24. class MemberPointService
  25. {
  26. /**
  27. * @var MemberPointRepository
  28. */
  29. protected $MemberPointRepository;
  30. protected $TaskLogRepository;
  31. protected $TaskRepository;
  32. protected $PayService;
  33. protected $resumeRepository;
  34. /**
  35. * MemberPointService constructor.
  36. * @param MemberPointRepository $MemberPointRepository
  37. * @param TaskLogRepository $TaskLogRepository
  38. * @param TaskRepository $TaskRepository
  39. * @param PayService $PayService
  40. * @param ResumeRepository $resumeRepository
  41. */
  42. public function __construct(MemberPointRepository $MemberPointRepository, TaskLogRepository $TaskLogRepository, TaskRepository $TaskRepository, PayService $PayService, ResumeRepository $resumeRepository)
  43. {
  44. $this->MemberPointRepository = $MemberPointRepository;
  45. $this->TaskLogRepository = $TaskLogRepository;
  46. $this->TaskRepository = $TaskRepository;
  47. $this->PayService = $PayService;
  48. $this->resumeRepository = $resumeRepository;
  49. }
  50. public function getPointsById($user)
  51. {
  52. $content = $this->MemberPointRepository->getPointsById($user->id, $user->utype);
  53. $points = $this->TaskLogRepository->getTodayPoints($user->id, $user->utype);
  54. $todayPoints = $points ? $points : 0;
  55. $onPoints = $this->TaskLogRepository->getSinglePoints($user->id, $user->utype);
  56. $dayPoints = $this->TaskLogRepository->getDayPoints($user->id, $user->utype);
  57. $arrAll = $this->TaskRepository->getAllPoints($user->utype);
  58. $allPoints = 0;
  59. foreach ($arrAll as $key => $val) {
  60. if ($val->once==1) {
  61. $allPoints+=$val->points;
  62. } else {
  63. $allPoints+=(abs($val->times))*($val->points);
  64. }
  65. }
  66. $lastPoints = (int)$allPoints-$onPoints-$dayPoints > 0 ? (int)$allPoints-$onPoints-$dayPoints : 0;
  67. $member = MemberInfo::where(['uid'=>$user->id])->first();
  68. $memhanselGet = MembersHandsel::where([
  69. 'uid'=>$user->id,
  70. 'utype'=>$user->utype,
  71. 'operate'=>1,
  72. ])->orderBy('id', 'desc')->paginate(10);
  73. $memhanselPo = MembersHandsel::where([
  74. 'uid'=>$user->id,
  75. 'utype'=>$user->utype,
  76. 'operate'=>2,
  77. ])->orderBy('id', 'desc')->paginate(10);
  78. $pointGet = MembersHandsel::where([
  79. 'uid'=>$user->id,
  80. 'utype'=>$user->utype,
  81. 'operate'=>1,
  82. ])->sum('points');
  83. $pointPo = MembersHandsel::where([
  84. 'uid'=>$user->id,
  85. 'utype'=>$user->utype,
  86. 'operate'=>2,
  87. ])->sum('points');
  88. return [
  89. 'content' =>$content,
  90. 'points'=>$todayPoints,
  91. 'lastPoints'=>$lastPoints,
  92. 'member'=>$member,
  93. 'memhanselGet'=>$memhanselGet,
  94. 'memhanselPo'=>$memhanselPo,
  95. 'pointGet'=>$pointGet,
  96. 'pointPo'=>$pointPo
  97. ];
  98. }
  99. /**根据uid 和utype获取points
  100. * @param $uid
  101. * @param $utype
  102. * @return mixed
  103. */
  104. public function getPoints($uid, $utype)
  105. {
  106. return $this->MemberPointRepository->getPointsById($uid, $utype);
  107. }
  108. /**积分操作
  109. * @param $uid
  110. * @param $utype
  111. * @param $i_type
  112. * @param $points
  113. * @return mixed
  114. */
  115. public function reportDeal($uid, $utype, $i_type, $points)
  116. {
  117. return $this->MemberPointRepository->reportDeal($uid, $utype, $i_type, $points);
  118. }
  119. /**
  120. * 获取任务状态。
  121. */
  122. public function getTask($user, $type=0)
  123. {
  124. $task = $this->MemberPointRepository->getTaskById($user->id, $user->utype);
  125. foreach ($task as $key => $val) {
  126. if ($key=='task_logs') {
  127. $task_id = [];
  128. $task_id_w = [];
  129. foreach ($val as $k => $v) {
  130. if ($v['once']!=1) {
  131. $task_id[] = $v['task_id'];
  132. } else {
  133. $task_id_w[] = $v['task_id'];
  134. }
  135. }
  136. }
  137. }
  138. $count = [];
  139. $task_id = array_unique($task_id);
  140. foreach ($task_id as $k => $v) {
  141. $count[$v] = $this->TaskLogRepository->getTaskLogCount($user->id, $v, $user->utype);
  142. }
  143. $task_info = $this->TaskRepository->getTaskById(array_keys($count));
  144. $finshTask = []; //已完成任务。
  145. foreach ($count as $k1 => $v1) {
  146. foreach ($task_info as $key1 => $val1) {
  147. if ($k1==$val1->id) {
  148. if ($val1->times!=-1) {
  149. if ($v1==$val1->times) {
  150. $finshTask[$k1]['id']=$val1->id;
  151. $finshTask[$k1]['title']=$val1->title;
  152. $finshTask[$k1]['points']=$val1->points;
  153. $finshTask[$k1]['type']='日常任务';
  154. $finshTask[$k1]['status']='已完成';
  155. $finshTask[$k1]['t_alias']=$val1->t_alias;
  156. $finshTask[$k1]['count']='(*'.$v1.')';
  157. }
  158. }
  159. }
  160. }
  161. }
  162. $task_info_w = $this->TaskRepository->getTaskById(($task_id_w));
  163. foreach ($task_info_w as $ke => $va) {
  164. $finshTask[$va->id]['id'] = $va->id;
  165. $finshTask[$va->id]['title'] = $va->title;
  166. $finshTask[$va->id]['points'] = $va->points;
  167. $finshTask[$va->id]['type'] = '一次性任务';
  168. $finshTask[$va->id]['status'] = '已完成';
  169. $finshTask[$va->id]['t_alias'] = $va->t_alias;
  170. $finshTask[$va->id]['count']='';
  171. }
  172. $task_ZZ=$this->TaskRepository->getTaskByUtype($user->utype);
  173. $task_info_z = [];
  174. foreach ($task_ZZ as $key => $val) {
  175. if (!in_array($val->id, array_keys($finshTask))) {
  176. $task_info_z[$val->id]['id'] = $val->id;
  177. $task_info_z[$val->id]['title'] = $val->title;
  178. $task_info_z[$val->id]['points'] = $val->points;
  179. if ($val->once==1) {
  180. $task_info_z[$val->id]['count'] = '';
  181. $task_info_z[$val->id]['type'] = '一次性任务';
  182. } else {
  183. $task_info_z[$val->id]['type'] = '日常任务';
  184. $hjk = $this->TaskLogRepository->getTaskLogCount($user->id, $val->id, $user->utype);
  185. $times =$val->times;
  186. if (!$hjk) {
  187. if ($times==-1) {
  188. $task_info_z[$val->id]['count'] = '';
  189. } else {
  190. $task_info_z[$val->id]['count'] = '(*'.$val->times.')';
  191. }
  192. } else {
  193. if ($times==-1) {
  194. $task_info_z[$val->id]['count'] = '';
  195. } else {
  196. $lasT = $times-$hjk;
  197. $task_info_z[$val->id]['count'] = '(*'.$lasT.')';
  198. }
  199. }
  200. }
  201. $defultType = '';
  202. if ($type == 1) {
  203. if (get_subsite_id() > 0) {
  204. $defultType = '/jkq/mobile';
  205. } else {
  206. $defultType = '/mobile';
  207. }
  208. } elseif ($type == 2) {
  209. $defultType = '/jkq';
  210. }
  211. if ($val->id==1) {
  212. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/auth/register" STYLE="text-decoration: none;">去完成</a>';
  213. } elseif ($val->id==2) {
  214. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/memberInfo" STYLE="text-decoration: none;">去完成</a>';
  215. } elseif ($val->id==3) {
  216. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/index" STYLE="text-decoration: none;">去完成</a>';
  217. } elseif ($val->id==4) {
  218. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/content/jobs" STYLE="text-decoration: none;">去完成</a>';
  219. } elseif ($val->id==5) {
  220. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/memberInfo/head" STYLE="text-decoration: none;">去完成</a>';
  221. } elseif ($val->id==6) {
  222. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/resume" STYLE="text-decoration: none;">去完成</a>';
  223. } elseif ($val->id==7) {
  224. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/memberInfo/memberSafe" STYLE="text-decoration: none;">去完成</a>';
  225. } elseif ($val->id==9) {
  226. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/memberInfo/memberSafe" STYLE="text-decoration: none;">去完成</a>';
  227. } elseif ($val->id==11) {
  228. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/resume" STYLE="text-decoration: none;">去完成</a>';
  229. } elseif ($val->id==12) {
  230. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/resume" STYLE="text-decoration: none;">去完成</a>';
  231. } elseif ($val->id==13) {
  232. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/content/jobs" STYLE="text-decoration: none;">去完成</a>';
  233. } elseif ($val->id==14) {
  234. $task_info_z[$val->id]['status'] = '<a href="###" class="invitation_reg" STYLE="text-decoration: none;">去完成</a>';
  235. } elseif ($val->id==15) {
  236. $task_info_z[$val->id]['status'] = '<a href="'.$defultType.'/person/memberInfo/memberSafe" STYLE="text-decoration: none;">去完成</a>';
  237. } else {
  238. $task_info_z[$val->id]['status'] = '<a href="" STYLE="text-decoration: none;">去完成</a>';
  239. }
  240. $task_info_z[$val->id]['t_alias'] = $val->t_alias;
  241. }
  242. }
  243. $todayPoints = 0;
  244. $rs=$this->TaskLogRepository->getTodayPoints($user->id, $user->utype);
  245. if ($rs) {
  246. $todayPoints = $rs;
  247. }
  248. $onPoints = $this->TaskLogRepository->getSinglePoints($user->id, $user->utype);
  249. $dayPoints = $this->TaskLogRepository->getDayPoints($user->id, $user->utype);
  250. $arrAll = $this->TaskRepository->getAllPoints($user->utype);
  251. $allPoints = 0;
  252. foreach ($arrAll as $key => $val) {
  253. if ($val->once==1) {
  254. $allPoints+=$val->points;
  255. } else {
  256. $allPoints+=(abs($val->times))*($val->points);
  257. }
  258. }
  259. $lastPoints = (int)$allPoints-$onPoints-$dayPoints > 0 ? (int)$allPoints-$onPoints-$dayPoints : 0;
  260. $member = MemberInfo::where(['uid'=>$user->id])->first();
  261. return[
  262. 'w_finsh'=>$task_info_z,
  263. 'finsh'=>$finshTask,
  264. 'content'=>$task,
  265. 'todayPoints'=>$todayPoints,
  266. 'lastPoints'=>$lastPoints,
  267. 'member'=>$member,
  268. 'wap_title'=>'我的任务'
  269. ];
  270. }
  271. public function increment_add($type, $user)
  272. {
  273. $resume = $this->resumeRepository->getSuccessResume($user->id, getResumeStatus());
  274. $points = MembersPoint::where(['uid'=>$user->id,'utype'=>$user->utype])->first();
  275. $payment = Payment::select(['id','name','alias'])->get();
  276. foreach ($payment as $key => $val) {
  277. if (!config("aix.system.pay.{$val->alias}.is_on")) {
  278. unset($payment[$key]);
  279. }
  280. }
  281. switch ($type) {
  282. case 'stick':
  283. $info = PersonalServiceStick::select(['id','days','points'])->orderBy('list_order', 'desc')->get();
  284. $tpl_name = 'increment_add_stick';
  285. $wap_title = '简历置顶';
  286. break;
  287. case 'tag':
  288. $tagCategory = Category::where(['alias'=>'AIX_personaltag'])->get();
  289. $tag = PersonalServiceTag::select(['id', 'days', 'points'])->orderBy('list_order', 'desc')->get();
  290. foreach ($resume as $key => $val) {
  291. $PersonalServiceTagLog = PersonalServiceTagLog::where(['resume_id'=>$val->id,'resume_uid'=>$user->id])->first();
  292. if ($PersonalServiceTagLog) {
  293. if ($PersonalServiceTagLog->endtime-time()>0) {
  294. $resume[$key]['tagLog'] = true;
  295. } else {
  296. $resume[$key]['tagLog'] = false;
  297. }
  298. } else {
  299. $resume[$key]['tagLog'] = false;
  300. }
  301. }
  302. $info = ['tagCategory'=>$tagCategory,'tag'=>$tag];
  303. $tpl_name = 'increment_add_tag';
  304. $wap_title = '醒目标签';
  305. break;
  306. default:
  307. //如果没有可以预览的简历信息,则获取默认简历
  308. if ($resume->isEmpty()) {
  309. $def_resume = $this->resumeRepository->getPersonInfo($user->id);
  310. if ($def_resume->toArray()) {
  311. $resume[0] = $def_resume;
  312. } else {
  313. $resume = [];
  314. }
  315. }
  316. $tpl_name = 'increment_add_tpl';
  317. $info = Tpl::where(['tpl_type'=>2,'display'=>1])->get();
  318. $wap_title = '简历模板';
  319. break;
  320. }
  321. return ['tpl'=>$tpl_name,'resume'=>$resume,'info'=>$info,'points'=>$points,'payment'=>$payment,
  322. 'wap_title'=>$wap_title];
  323. }
  324. public function pay($input, $user)
  325. {
  326. $order = new Order();
  327. if ($input['payment_name']=='wechat') {
  328. $order->payment_cn = '微信扫码';
  329. } else {
  330. $order->payment_cn = '支付宝';
  331. }
  332. if ($input['is_deductible']) {
  333. $order->pay_type = 3;
  334. $order->amount = $input['amountNum'];
  335. $order->pay_amount = $input['amount'];
  336. $order->pay_points = $input['deductible'];
  337. $order->payment = $input['payment_name'];
  338. $is_deductible = '使用积分抵现(抵扣积分:)'.$input['deductible'].'积分!支付金额:'.$input['amount'].'元';
  339. if ($input['type']=='tag') {
  340. $categorys = Category::where('id', $input['tagid'])->first();
  341. $order->discount = isset($categorys->demand) ? $categorys->demand : '-';
  342. $order->description = "简历标签(简历ID:".$input['resume_id']."),天数:".$input['days']."天,需要积分:".$input['points'].'积分,'.$is_deductible;
  343. $order->service_name = '简历标签';
  344. $order->order_type = 4;
  345. } else {
  346. $order->description = "简历置顶(简历ID:".$input['resume_id']."),天数:".$input['days']."天,需要积分:".$input['points'].'积分,'.$is_deductible;
  347. $order->service_name = '简历置顶';
  348. $order->order_type = 3;
  349. $order->discount = '置顶'.$input['days'].'天';
  350. }
  351. } else {
  352. $order->pay_type = 2;
  353. $order->amount = $input['amountNum'];
  354. $order->pay_amount = $input['amount'];
  355. $order->pay_points = 0;
  356. $order->payment = $input['payment_name'];
  357. $is_deductible = '未使用积分抵现!支付金额:'.$input['amount'].'元';
  358. if ($input['type']=='tag') {
  359. $categorys = Category::where('id', $input['tagid'])->first();
  360. $order->discount = isset($categorys->demand) ? $categorys->demand : '-';
  361. $order->description = "简历标签(简历ID:".$input['resume_id']."),天数:".$input['days']."天,需要积分:".$input['points'].'积分,'.$is_deductible;
  362. $order->service_name = '简历标签';
  363. $order->order_type = 4;
  364. } else {
  365. $order->description = "简历置顶(简历ID:".$input['resume_id']."),天数:".$input['days']."天,需要积分:".$input['points'].'积分,'.$is_deductible;
  366. $order->service_name = '简历置顶';
  367. $order->order_type = 3;
  368. $order->discount = '置顶'.$input['days'].'天';
  369. }
  370. }
  371. $order->charge = json_encode($input);
  372. $order->uid = $user->id;
  373. $order->utype = $user->utype;
  374. $order->save();
  375. return ['order'=>$order,'input'=>$input];
  376. }
  377. public function updateOrder($tradeNo, $input, $order, $route)
  378. {
  379. if (is_weixin()) {
  380. $type = 'official';
  381. } else {
  382. if (strpos($route->uri,'mobile')!== false) {
  383. $type = 'wap';
  384. } else {
  385. if ($input['payment_name']=='wechat') {
  386. $type = 'scan';
  387. } else {
  388. $type = 'web';
  389. }
  390. }
  391. }
  392. /* $type = 'official'; //------------自定义默认值。*/
  393. $payorder=new PayOrder();
  394. $payorder->trade_no=$tradeNo;
  395. if ($input['type']=='tag') {
  396. $payorder->subject="简历标签";
  397. } else {
  398. $payorder->subject="简历置顶";
  399. }
  400. if ($input['is_deductible']) {
  401. $is_deductible = '使用积分抵现(抵扣积分:)'.$input['deductible'].'积分!支付金额:'.$input['amount'].'元';
  402. } else {
  403. $is_deductible = '未使用积分抵现!支付金额:'.$input['amount'].'元';
  404. }
  405. if ($input['type']=='tag') {
  406. $payorder->detail="简历标签(简历ID:".$input['resume_id']."),天数:".$input['days']."天,需要积分:".$input['points'].'积分,'.$is_deductible;
  407. } else {
  408. $payorder->detail="简历置顶(简历ID:".$input['resume_id']."),天数:".$input['days']."天,需要积分:".$input['points'].'积分,'.$is_deductible;
  409. }
  410. $payorder->price=$input['amount'];
  411. $payorder->callback='App\Services\Common\OrderService.updateOrder';
  412. if ($type == 'web') {
  413. $payorder->return_url=route('person.order_list');
  414. }
  415. if ($type=='wap') {
  416. if ($input['payment_name']=='wechat') {
  417. $payorder->return_url=route('mobile.common.orderWechat',['oid'=>$payorder->trade_no]);
  418. } else {
  419. $payorder->return_url=route('mobile.person.order_list');
  420. }
  421. }
  422. if ($type=='official') {
  423. $payorder->openid = $this->PayService->getPayOpenid();
  424. /* $payorder->openid = 'o6poWw3LbYDgCGXCeM-qf-DYV1mo';*/
  425. }
  426. $result=$this->PayService->pay($input['payment_name'], $type, $payorder);
  427. $order->oid = $payorder->trade_no;
  428. $order->save();
  429. if ($input['payment_name']=='wechat') {
  430. if ($type=='wap') {
  431. return [
  432. 'code'=>'wechat',
  433. 'tradeCode'=>$result,
  434. 'type'=>$type
  435. ];
  436. }elseif ($type=='official') {
  437. return [
  438. 'code'=>'wechat',
  439. 'tradeCode'=>$result,
  440. 'type'=>$type
  441. ];
  442. } else {
  443. return [
  444. 'code'=>'wechat',
  445. 'tradeCode'=>get_qrcode_html($result->code_url),
  446. 'tradeNo'=>[
  447. 'number'=>$payorder->trade_no,
  448. ],
  449. 'type'=>$type
  450. ];
  451. }
  452. } else {
  453. return [
  454. 'code'=>'alipay',
  455. 'tradeCode'=>$result,
  456. ];
  457. }
  458. }
  459. public function payStatus($tradeNo)
  460. {
  461. if (!$tradeNo) {
  462. return false;
  463. }
  464. $order = Order::where('oid', $tradeNo)->first();
  465. if ($order->is_pay==2) {
  466. return true;
  467. } else {
  468. return false;
  469. }
  470. }
  471. public function order_list($user, $all)
  472. {
  473. $param_array = array('status','settr');
  474. $params= array();
  475. if ($all) {
  476. foreach ($all as $k => $v) {
  477. if (in_array($k, $param_array)) {
  478. $params[$k] = $v;
  479. }
  480. }
  481. }
  482. $data[] = ['uid','=',$user->id];
  483. $data[] = ['utype','=',$user->utype];
  484. if (request()->status) {
  485. $data[] = ['is_pay','=',request()->status];
  486. }
  487. if (request()->settr) {
  488. $data[] = ['order_type','=',request()->settr];
  489. }
  490. return['order'=>Order::where($data)->orderBy('id', 'desc')->paginate(10),'params'=>$params];
  491. }
  492. public function order_detail($oid,$user)
  493. {
  494. $res = Order::where(['uid'=>$user->id,'utype'=>$user->utype])->get()->toArray();
  495. $array_id = array_column($res,'oid');
  496. if(!in_array($oid,$array_id)){
  497. throw new ResponseException('订单不存在!');
  498. }
  499. $order = Order::where(['oid'=>$oid])->first();
  500. $charge = json_decode($order->charge);
  501. $order->charge_cn = '';
  502. if ($charge) {
  503. $order->charge_cn = isset(Resume::find($charge->resume_id)->title) ?
  504. Resume::find($charge->resume_id)->title : '';
  505. $order->service_time = '';
  506. if ($order->order_type==3) {
  507. if (isset(PersonalServiceStickLog::where(['resume_id'=>$charge->resume_id])->first()->endtime)) {
  508. $endtime = PersonalServiceStickLog::where(['resume_id'=>$charge->resume_id])->first()->endtime;
  509. if ($order->is_pay==2) {
  510. $order->service_time = $endtime;
  511. }
  512. }
  513. }
  514. if ($order->order_type==4) {
  515. if (isset(PersonalServiceTagLog::where(['resume_id'=>$charge->resume_id])->first()->endtime)) {
  516. $endtime = PersonalServiceTagLog::where(['resume_id'=>$charge->resume_id])->first()->endtime;
  517. if ($order->is_pay==2) {
  518. $order->service_time = $endtime;
  519. }
  520. }
  521. }
  522. }
  523. return $order;
  524. }
  525. public function order_cancel($id,$user)
  526. {
  527. if (!$id) {
  528. throw new ResponseException('订单不存在!');
  529. }
  530. $res = Order::where(['uid'=>$user->id,'utype'=>$user->utype])->get()->toArray();
  531. $array_id = array_column($res,'id');
  532. if(!in_array($id,$array_id)){
  533. throw new ResponseException('订单不存在!');
  534. }
  535. return Order::where(['id'=>$id])->update(['is_pay'=>3]);
  536. }
  537. public function order_delete($id,$user)
  538. {
  539. if (!$id) {
  540. throw new ResponseException('订单不存在!');
  541. }
  542. $res = Order::where(['uid'=>$user->id,'utype'=>$user->utype])->get()->toArray();
  543. $array_id = array_column($res,'id');
  544. if(!in_array($id,$array_id)){
  545. throw new ResponseException('订单不存在!');
  546. }
  547. return Order::where(['id'=>$id])->delete();
  548. }
  549. public function payAgain($id, $route)
  550. {
  551. if (!$id) {
  552. throw new ResponseException('订单不存在!');
  553. }
  554. $order = Order::where(['id'=>$id])->first();
  555. if ($order) {
  556. if (is_weixin()) {
  557. $type = 'wap';
  558. } else {
  559. if (strpos($route->uri,'mobile')!== false) {
  560. $type = 'wap';
  561. } else {
  562. if ($order->payment=='wechat') {
  563. $type = 'scan';
  564. } else {
  565. $type = 'web';
  566. }
  567. }
  568. }
  569. $payorder = PayOrder::where(['trade_no'=>$order->oid])->first();
  570. if ($type == 'web') {
  571. $payorder->return_url=route('person.order_list');
  572. }
  573. if ($type=='wap') {
  574. $payorder->return_url=route('mobile.person.order_list');
  575. }
  576. $result=$this->PayService->pay($order->payment, $type, $payorder);
  577. if ($order->payment=='wechat') {
  578. if ($type=='wap') {
  579. return [
  580. 'code'=>'wechat',
  581. 'tradeCode'=>$result,
  582. 'type'=>$type
  583. ];
  584. } else {
  585. return [
  586. 'code'=>'wechat',
  587. 'tradeCode'=>get_qrcode_html($result->code_url),
  588. 'tradeNo'=>[
  589. 'number'=>$payorder->trade_no,
  590. ],
  591. 'type'=>$type
  592. ];
  593. }
  594. } else {
  595. return [
  596. 'code'=>'alipay',
  597. 'tradeCode'=>$result,
  598. ];
  599. }
  600. } else {
  601. throw new ResponseException('订单不存在,数据异常!');
  602. }
  603. }
  604. }