OrderService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Ad;
  4. use App\Model\AdPlace;
  5. use App\Model\Order;
  6. use App\Model\OrderAd;
  7. use App\Model\Website;
  8. use App\Tools\Result;
  9. use Carbon\Carbon;
  10. use Hyperf\DbConnection\Db;
  11. use Hyperf\RpcServer\Annotation\RpcService;
  12. #[RpcService(name: "OrderService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  13. class OrderService implements OrderServiceInterface
  14. {
  15. /**
  16.  * 查询没有广告的广告位
  17.  * @param
  18.  * @return void
  19. */
  20. public function getAD(array $data): array
  21. {
  22. $where = [
  23. 'ad_place.width' => $data['width'],
  24. 'ad_place.height' => $data['height'],
  25. ];
  26. $start = Carbon::parse($data['starttime']);
  27. $end = Carbon::parse($data['endtime']);
  28. $status = [
  29. 0 => '1',
  30. 1 => '4',
  31. 2 => '6',
  32. ];
  33. $ads = Ad::where('fromtime', '<=', $start)->where('totime', '>=', $end)->select('pid')->get()->all();
  34. $orderads = OrderAd::where('fromtime', '<=', $start)->where('totime', '>=', $end)->whereIn('status', $status)->select('pid')->get()->all();
  35. $pids = array_merge($ads, $orderads);
  36. $ad_pids = array_unique($pids);
  37. // $ad_pid = [1,2,3];
  38. if (!empty($ad_pids)) {
  39. $pid = [];
  40. foreach ($ad_pids as $val) {
  41. array_push($pid, $val['pid']);
  42. }
  43. $placeids = AdPlace::whereNotIn('id', $pid)->where($where)->select('id')->get()->all();
  44. // 符合用户条件的空广告位
  45. $place_id = [];
  46. foreach ($placeids as $val) {
  47. array_push($place_id, $val['id']);
  48. }
  49. $rep = AdPlace::whereIn('ad_place.id', $place_id)
  50. ->leftJoin('website', 'ad_place.website_id', 'website.id')
  51. ->select('ad_place.*', 'website.website_name', 'website.id')
  52. ->selectSub('website.id', 'webid')
  53. ->selectSub('ad_place.id', 'pid')
  54. ->orderBy("website.id", "asc")
  55. ->limit($data['pageSize'])
  56. ->offset(($data['page'] - 1) * $data['pageSize'])
  57. ->get();
  58. } else {
  59. $rep = AdPlace::where($where)
  60. ->leftJoin('website', 'ad_place.website_id', 'website.id')
  61. ->select('ad_place.*', 'website.website_name', 'website.id')
  62. ->selectSub('website.id', 'webid')
  63. ->selectSub('ad_place.id', 'pid')
  64. ->orderBy("website.id", "asc")
  65. ->limit($data['pageSize'])
  66. ->offset(($data['page'] - 1) * $data['pageSize'])
  67. ->get();
  68. }
  69. $startTime = strtotime($data['starttime']);
  70. $endTime = strtotime($data['endtime']);
  71. $time = ($endTime - $startTime) / (24 * 60 * 60);
  72. $roundedValue = round($time, 2);
  73. $days = number_format($roundedValue, 2, '.', '');
  74. $count = count($rep);
  75. $data = [
  76. 'rows' => $rep->toArray(),
  77. 'count' => $count,
  78. 'days' => $days,
  79. ];
  80. if (empty($rep)) {
  81. return Result::error("暂时没有符合您条件的广告位");
  82. }
  83. return Result::success($data);
  84. }
  85. /**
  86. * 添加订单
  87. * @param
  88. * @return void
  89. */
  90. public function addOrder(array $data): array
  91. {
  92. $ads = Ad::whereIn($data['id'])
  93. ->leftJoin('ad_place', 'ad.pid', 'ad_place.id')
  94. ->leftJoin("article_data", "article.id", "article_data.article_id")
  95. ->select("ad_place.*", "ad.*")
  96. ->orderBy("ad.id", "desc")
  97. ->limit($data['pageSize'])
  98. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  99. $count = Ad::whereIn($data['id'])->count();
  100. $data = [
  101. 'rows' => $ads->toArray(),
  102. 'count' => $count,
  103. ];
  104. if (empty($rep)) {
  105. return Result::error("没有信息数据");
  106. }
  107. return Result::success($data);
  108. }
  109. /**
  110. * 获取订单列表
  111. * @param
  112. * @return void
  113. */
  114. public function getOrderListAdmin(array $data): array
  115. {
  116. // 获取分页参数,默认每页 10 条记录
  117. $page = isset($data['page']) ? (int) $data['page'] : 1;
  118. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  119. // 构建查询条件
  120. $where = [
  121. 'order.status' => $data['status'], // 明确指定 order 表的 status 列
  122. ];
  123. // 添加订单号查询条件
  124. if (!empty($data['order_num'])) {
  125. $where['order.order_num'] = $data['order_num']; // 明确指定 order 表的 order_num 列
  126. }
  127. // 处理时间范围查询
  128. $start = $data['sttime'];
  129. $end = $data['edtime'];
  130. // 查询数据并分页
  131. $query = Order::where($where)
  132. ->when(!empty($start) && !empty($end), function ($q) use ($start, $end) {
  133. $q->whereBetween('order.fromtime', [$start, $end]); // 明确指定 order 表的 fromtime 列
  134. })
  135. ->when(!empty($start), function ($q) use ($start) {
  136. $q->where('order.fromtime', '>=', $start); // 明确指定 order 表的 fromtime 列
  137. })
  138. ->when(!empty($end), function ($q) use ($end) {
  139. $q->where('order.totime', '<=', $end); // 明确指定 order 表的 totime 列
  140. })
  141. ->leftJoin('user as admin_user', 'order.admin_user_id', '=', 'admin_user.id')
  142. ->leftJoin('user as user', 'order.user_id', '=', 'user.id')
  143. ->select(
  144. 'order.*',
  145. 'admin_user.user_name as admin_user_name',
  146. 'user.user_name as user_name'
  147. )
  148. ->orderBy('order.id');
  149. // 执行分页查询
  150. $result = $query->paginate($perPage, ['*'], 'page', $page);
  151. // 返回分页结果
  152. return Result::success([
  153. 'count' => $result->total(),
  154. 'current_page' => $result->currentPage(),
  155. 'last_page' => $result->lastPage(),
  156. 'pagesize' => $result->perPage(),
  157. 'rows' => $result->items(),
  158. ]);
  159. }
  160. /**
  161. * 获取订单详情
  162. * @param
  163. * @return void
  164. */
  165. public function getOrderDetailAdmin(array $data): array
  166. {
  167. $order = Order::where('order.id', $data['id'])
  168. ->leftJoin('user as admin_user', 'order.admin_user_id', '=', 'admin_user.id')
  169. ->leftJoin('user as user', 'order.user_id', '=', 'user.id')
  170. ->select(
  171. 'order.*',
  172. 'admin_user.user_name as admin_user_name',
  173. 'user.user_name as user_name'
  174. )->first();
  175. if (empty($order)) {
  176. return Result::error("没有信息数据");
  177. }
  178. $pid = $order['id'];
  179. $ad = OrderAd::where('order_id', $pid)->get();
  180. $order['ad'] = $ad;
  181. return Result::success($order);
  182. }
  183. /**
  184. * 修改订单价格
  185. * @param
  186. * @return void
  187. */
  188. public function editPriceOrderAdmin(array $data): array
  189. {
  190. $order = Order::where('id', $data['id'])->first();
  191. if (empty($order)) {
  192. return Result::error("没有信息数据");
  193. }
  194. $order->price = $data['price'];
  195. $order->save();
  196. return Result::success($order);
  197. }
  198. /**
  199. *拒绝订单
  200. * @param
  201. * @return void
  202. */
  203. public function rejectOrderAdmin(array $data): array
  204. {
  205. $order = Order::where('id', $data['id'])->first();
  206. if (empty($order)) {
  207. return Result::error("没有信息数据");
  208. }
  209. Db::beginTransaction();
  210. try {
  211. $order->status = 2; //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
  212. $order->ad_status = 2;
  213. $order->reason = $data['reason'];
  214. $order->bhtime = date('Y-m-d H:i:s');
  215. $order->save();
  216. OrderAd::where('order_id', $data['id'])
  217. ->update(['status' => 2]);
  218. Db::commit();
  219. } catch (\Exception $e) {
  220. Db::rollBack();
  221. return Result::error("操作失败");
  222. }
  223. return Result::success($order);
  224. }
  225. /**
  226. * 结束订单
  227. * @param
  228. * @return void
  229. */
  230. public function endOrderAdmin(array $data): array
  231. {
  232. $order = Order::where('id', $data['id'])->first();
  233. if (empty($order)) {
  234. return Result::error("没有信息数据");
  235. }
  236. Db::beginTransaction();
  237. try {
  238. $order->status = 7;
  239. $order->jstime = date('Y-m-d H:i:s');
  240. $order->save();
  241. // 获取 order_ad 表中的记录
  242. $orderAds = OrderAd::where('order_id', $data['id'])
  243. ->update(['status' => 7]);
  244. // 在ad表中删除相同pid的数据
  245. Ad::where('order_id', $data['id'])->delete();
  246. Db::commit();
  247. } catch (\Exception $e) {
  248. Db::rollBack();
  249. return Result::error("操作失败" . $e->getMessage());
  250. }
  251. return Result::success($order);
  252. }
  253. /**
  254. * 删除订单
  255. * @param
  256. * @return void
  257. */
  258. public function delOrderAdmin(array $data): array
  259. {
  260. // 获取订单信息
  261. $order = Order::where('id', $data['id'])->first();
  262. if (empty($order)) {
  263. return Result::error("没有信息数据");
  264. }
  265. Db::beginTransaction();
  266. try {
  267. // 获取 order_ad 表中的记录
  268. OrderAd::where('order_id', $data['id'])->delete();
  269. // 删除 ad 表中的记录
  270. Ad::where('order_id', $order['id'])->delete();
  271. // 提交事务
  272. Db::commit();
  273. } catch (\Exception $e) {
  274. // 回滚事务
  275. Db::rollBack();
  276. // 返回错误信息
  277. return Result::error($e->getMessage());
  278. }
  279. // 返回成功信息
  280. return Result::success("删除成功");
  281. }
  282. /**
  283. * 审核订单
  284. * @param
  285. * @return void
  286. */
  287. public function applyOrderStatusAdmin(array $data): array
  288. {
  289. $order = Order::where('id', $data['id'])
  290. ->where('status', 6)
  291. ->first();
  292. if (empty($order)) {
  293. return Result::error("没有信息数据");
  294. }
  295. Db::beginTransaction();
  296. try {
  297. $order->status = 1;
  298. //判断是否在周期范围内
  299. $ad_status = 8; // 待生效
  300. if ($order->starttime < date('Y-m-d H:i:s') && date('Y-m-d H:i:s') < $order->endtime) {
  301. // 条件满足时的逻辑
  302. $ad_status = 1;
  303. }
  304. $order->ad_status = 1;
  305. $order->shtime = date('Y-m-d H:i:s');
  306. $order->save();
  307. // 批量更新 order_ad 表中的状态
  308. OrderAd::where('order_id', $data['id'])
  309. ->where('status', 6)
  310. ->update(['status' => 1]);
  311. //判断的当前时间是否在订单的开始时间之后,并且小于等于订单的结束时间
  312. if (time() >= strtotime($order->sttime) && time() < strtotime($order->edtime)) {
  313. $ad_status = 1; //审核生效
  314. } else {
  315. $ad_status = 2; //审核
  316. }
  317. $ads = [];
  318. $orderAds = $orderAds::where('order_id', $data['id'])->get();
  319. foreach ($orderAds as $orderAd) {
  320. $ads[] = [
  321. 'name' => $orderAd->name,
  322. 'pid' => $orderAd->pid,
  323. 'areaid' => $orderAd->areaid,
  324. 'amount' => $orderAd->amount,
  325. 'introduce' => $orderAd->introduce,
  326. 'hits' => $orderAd->hits,
  327. 'admin_user_id' => $orderAd->admin_user_id,
  328. 'fromtime' => $orderAd->fromtime,
  329. 'totime' => $orderAd->totime,
  330. 'text_name' => $orderAd->text_name,
  331. 'text_url' => $orderAd->text_url,
  332. 'text_title' => $orderAd->text_title,
  333. 'image_src' => $orderAd->image_src,
  334. 'image_url' => $orderAd->image_url,
  335. 'image_alt' => $orderAd->image_alt,
  336. 'video_src' => $orderAd->video_src,
  337. 'video_url' => $orderAd->video_url,
  338. 'video_auto' => $orderAd->video_auto,
  339. 'video_loop' => $orderAd->video_loop,
  340. 'status' => $ad_status,
  341. 'order_id' => $orderAd->order_id,
  342. ];
  343. }
  344. Ad::insert($ads);
  345. Db::commit();
  346. } catch (\Exception $e) {
  347. Db::rollBack();
  348. return Result::error($e->getMessage());
  349. }
  350. return Result::success($order);
  351. }
  352. /*
  353.  * 根据用户条件及网站搜索没有广告的广告位
  354.  * @param
  355.  * @return void
  356. */
  357. public function getWebsiteAd(array $data): array
  358. {
  359. $where = [
  360. 'ad_place.width' => $data['width'],
  361. 'ad_place.height' => $data['height'],
  362. ];
  363. $start = Carbon::parse($data['starttime']);
  364. $end = Carbon::parse($data['endtime']);
  365. $status = [
  366. 0 => '1',
  367. 1 => '4',
  368. 2 => '6',
  369. ];
  370. $ads = Ad::where('fromtime', '<=', $start)->where('totime', '>=', $end)->select('pid')->get()->all();
  371. $orderads = OrderAd::where('fromtime', '<=', $start)->where('totime', '>=', $end)->whereIn('status', $status)->select('pid')->get()->all();
  372. $pids = array_merge($ads, $orderads);
  373. $ad_pids = array_unique($pids);
  374. if (!empty($ad_pids)) {
  375. $pid = [];
  376. foreach ($ad_pids as $val) {
  377. array_push($pid, $val['pid']);
  378. }
  379. $placeids = AdPlace::whereNotIn('id', $pid)->where($where)->select('id', 'website_id')->get()->all();
  380. if (!isset($data['website_id'])) {
  381. $website_id = [];
  382. foreach ($placeids as $v) {
  383. array_push($website_id, $v['website_id']);
  384. }
  385. $result = Website::whereIn('id', $website_id)->get();
  386. } else {
  387. $place_id = [];
  388. foreach ($placeids as $val) {
  389. array_push($place_id, $val['id']);
  390. }
  391. $rep = AdPlace::where($where)
  392. ->whereIn('ad_place.id', $place_id)
  393. ->where('ad_place.website_id', $data['website_id'])
  394. ->leftJoin('website', 'ad_place.website_id', 'website.id')
  395. ->select('ad_place.*', 'website.website_name', 'website.id')
  396. ->selectSub('website.id', 'webid')
  397. ->selectSub('ad_place.id', 'pid')
  398. ->orderBy("website.id", "asc")
  399. ->limit($data['pageSize'])
  400. ->offset(($data['page'] - 1) * $data['pageSize'])
  401. ->get();
  402. $count = count($rep);
  403. $result = [
  404. 'rows' => $rep->toArray(),
  405. 'count' => $count,
  406. ];
  407. }
  408. } else {
  409. if (isset($data['website_id'])) {
  410. $rep = AdPlace::where($where)
  411. ->where('ad_place.website_id', $data['website_id'])
  412. ->leftJoin('website', 'ad_place.website_id', 'website.id')
  413. ->select('ad_place.*', 'website.website_name', 'website.id')
  414. ->selectSub('website.id', 'webid')
  415. ->selectSub('ad_place.id', 'pid')
  416. ->orderBy("website.id", "asc")
  417. ->limit($data['pageSize'])
  418. ->offset(($data['page'] - 1) * $data['pageSize'])
  419. ->get();
  420. $count = count($rep);
  421. $result = [
  422. 'rows' => $rep->toArray(),
  423. 'count' => $count,
  424. ];
  425. } else {
  426. $place_all = AdPlace::where($where)->select('website_id')->get()->all();
  427. $place_allads = [];
  428. foreach ($place_all as $v) {
  429. array_push($place_allads, $v['website_id']);
  430. }
  431. $result = Website::whereIn('id', $place_allads)->get();
  432. }
  433. }
  434. if (empty($data)) {
  435. return Result::error("暂时没有符合您条件的广告位");
  436. }
  437. $startTime = strtotime($data['starttime']);
  438. $endTime = strtotime($data['endtime']);
  439. $time = ($endTime - $startTime) / (24 * 60 * 60);
  440. $roundedValue = round($time, 2);
  441. $days = number_format($roundedValue, 2, '.', '');
  442. $count = count($rep);
  443. $result['days'] = $days;
  444. return Result::success($result);
  445. }
  446. /**
  447.  * 添加广告订单
  448.  * @param
  449.  * @return void
  450. */
  451. public function addAD(array $data): array
  452. {
  453. date_default_timezone_set('Asia/Shanghai');
  454. $time = time();
  455. $startTime = strtotime($data['starttime']);
  456. $endTime = strtotime($data['endtime']);
  457. $con_time = ($endTime - $startTime) / (24 * 60 * 60);
  458. $roundedValue = round($con_time, 2);
  459. $days = number_format($roundedValue, 2, '.', '');
  460. $timestamp = date('YmdHis', $time);
  461. $catetime = date('Y-m-d H:i:s', $time);
  462. $randomNumber = mt_rand(1000, 9999);
  463. $ordernum = $randomNumber . $timestamp; // 时间戳与随机数拼接
  464. // var_dump(($time));
  465. Db::beginTransaction();
  466. try {
  467. $order = [
  468. 'order_num' => $ordernum,
  469. 'sttime' => $data['starttime'],
  470. 'edtime' => $data['endtime'],
  471. 'user_id' => $data['user_id'],
  472. 'cttime' => $catetime,
  473. 'height' => $data['height'],
  474. 'width' => $data['width'],
  475. 'days' => $days,
  476. ];
  477. $orderid = Order::insertGetId($order);
  478. $adplace = $data['pid'];
  479. if (is_array($data['pid'])) {
  480. $adplace = AdPlace::whereIn('id', $data['pid'])->select('website_id', 'id')->get();
  481. foreach ($adplace as $key => $ads) {
  482. $order_ad[$key] = [
  483. 'order_id' => $orderid,
  484. 'order_num' => $ordernum,
  485. 'name' => $data['name'],
  486. 'fromtime' => $data['starttime'],
  487. 'totime' => $data['endtime'],
  488. 'image_src' => $data['imgsrc'],
  489. 'image_url' => $data['imgurl'],
  490. 'pid' => $ads['id'],
  491. 'website_id' => $ads['website_id'],
  492. ];
  493. // $log = [
  494. // 'order_id' => $orderid,
  495. // 'user_id' => $data['user_id'],
  496. // 'pid' => $ads['id'],
  497. // 'website_id' => $ads['website_id'],
  498. // 'action' => '添加',
  499. // 'time' => $catetime
  500. // ];
  501. }
  502. } else {
  503. $order_ad = [
  504. 'order_id' => $orderid,
  505. 'order_num' => $ordernum,
  506. 'name' => $data['name'],
  507. 'website_id' => $adplace['website_id'],
  508. 'fromtime' => $data['starttime'],
  509. 'totime' => $data['endtime'],
  510. 'image_src' => $data['imgsrc'],
  511. 'image_url' => $data['imgurl'],
  512. 'pid' => $adplace,
  513. ];
  514. // $log = [
  515. // 'order_id' => $orderid,
  516. // 'user_id' => $data['user_id'],
  517. // 'pid' => $adplace,
  518. // 'website_id' => $ads['website_id'],
  519. // 'action' => '添加',
  520. // 'time' => $catetime
  521. // ];
  522. }
  523. $orderad_id = OrderAd::insert($order_ad);
  524. Db::commit();
  525. } catch (\Exception $e) {
  526. Db::rollBack();
  527. return Result::error($e->getMessage());
  528. }
  529. // $log = AdLog::insert($log);
  530. $result = [
  531. 'order_id' => $orderid,
  532. 'orderad_id' => $orderad_id,
  533. 'name' => $data['name'],
  534. '$ordernum' => $ordernum,
  535. ];
  536. return Result::success($result);
  537. }
  538. /**
  539.  * 获取订单列表
  540.  * @param
  541.  * @return void
  542. */
  543. public function getOrderList(array $data): array
  544. {
  545. $where = [
  546. 'user_id' => $data['user_id'],
  547. 'user_del' => 2,
  548. ];
  549. if (isset($data['status'])) {
  550. $where['status'] = $data['status'];
  551. }
  552. $orders = Order::where($where)
  553. ->orderBy("id", "asc")
  554. ->limit($data['pageSize'])
  555. ->offset(($data['page'] - 1) * $data['pageSize'])
  556. ->get();
  557. if (empty($orders)) {
  558. return Result::error("您暂时还没有下单");
  559. } else {
  560. $count = count($orders);
  561. $data = [
  562. 'rows' => $orders->toArray(),
  563. 'count' => $count,
  564. ];
  565. }
  566. return Result::success($data);
  567. }
  568. /**
  569.  * 获取订单详情
  570.  * @param
  571.  * @return void
  572. */
  573. public function getOrderDetail(array $data): array
  574. {
  575. $order = Order::where('id', $data['order_id'])->first();
  576. $orderads = OrderAd::where('order_ad.order_id', $data['order_id'])
  577. ->leftJoin('website', 'order_ad.website_id', 'website.id')
  578. ->select('order_ad.*', 'website.website_name', 'website.id')
  579. ->selectSub('website.id', 'webid')
  580. ->selectSub('order_ad.id', 'oid')
  581. ->orderBy("website.id", "asc")
  582. ->limit($data['pageSize'])
  583. ->offset(($data['page'] - 1) * $data['pageSize'])
  584. ->get();
  585. if (empty($order)) {
  586. return Result::error("订单id错误");
  587. }
  588. $result = [
  589. 'order' => $order,
  590. 'orderads' => $orderads,
  591. ];
  592. return Result::success($result);
  593. }
  594. /**
  595.  * 撤回订单
  596.  * @param
  597.  * @return void
  598. */
  599. public function cancelOrder(array $data): array
  600. {
  601. date_default_timezone_set('Asia/Shanghai');
  602. $time = time();
  603. $timestamp = date('YmdHis', $time);
  604. Db::beginTransaction();
  605. try {
  606. $order = Order::where('id', $data['order_id'])->where('status', 6)->where('edtime', '>=', $timestamp)->update(['status' => 3, 'ad_status' => '3']);
  607. $ads = OrderAd::where('order_id', $data['order_id'])->where('status', 6)->where('totime', '>=', $timestamp)->update(['status' => 3]);
  608. Db::commit();
  609. } catch (\Exception $e) {
  610. Db::rollBack();
  611. return Result::error($e->getMessage());
  612. }
  613. $result = [
  614. 'order' => $order,
  615. 'ads' => $ads,
  616. ];
  617. return Result::success($result);
  618. }
  619. /**
  620.  * 删除订单
  621.  * @param
  622.  * @return void
  623. */
  624. public function delOrderAD(array $data): array
  625. {
  626. $data['status'] = [
  627. 0 => 2,
  628. 1 => 3,
  629. 2 => 5,
  630. 3 => 7,
  631. ];
  632. date_default_timezone_set('Asia/Shanghai');
  633. $time = time();
  634. $timestamp = date('YmdHis', $time);
  635. $where = [
  636. ['user_id', '=', $data['user_id']],
  637. ['id', '=', $data['order_id']],
  638. ];
  639. $time = [['edtime', '<=', $timestamp]];
  640. $order = Order::where($where)->where($time)->update(['user_del' => 1]);
  641. if (empty($order)) {
  642. $order = Order::where($where)->whereIn('status', $data['status'])->update(['user_del' => 1]);
  643. }
  644. //
  645. if ($order == 0) {
  646. return Result::error("订单id错误");
  647. }
  648. return Result::success($order);
  649. }
  650. }