OrderService.php 23 KB

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