OrderService.php 23 KB

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