OrderService.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\service\order;
  3. use app\model\Order;
  4. use app\model\OrderSheet;
  5. use app\model\SysDept;
  6. use support\Db;
  7. use support\Redis;
  8. class OrderService
  9. {
  10. /**
  11. * @Desc 自动确认收货
  12. * @Author Gorden
  13. * @Date 2024/4/11 16:09
  14. *
  15. * @return void
  16. */
  17. public static function AutomaticReceipt()
  18. {
  19. try {
  20. Db::beginTransaction();
  21. $timeUnix = strtotime("-7 days");
  22. $orders = Order::where('order_status_system', 'SIGNED')
  23. ->where('order_addtimes', '<', $timeUnix)
  24. ->get();
  25. foreach ($orders as $order) {
  26. // 订单主表
  27. Order::where('order_id', $order->order_id)->update([
  28. // 'order_is_complete' => 'Y',
  29. 'order_status_system' => 'CONFIRM'
  30. ]);
  31. // 订单详情表
  32. OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CONFIRM']);
  33. // 7天后自动完成 order_is_complete=Y
  34. $redis = Redis::connection();
  35. $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days"));
  36. $redis->sadd($key, $order->order_id);
  37. }
  38. Db::commit();
  39. } catch (\Exception $e) {
  40. Db::rollBack();
  41. }
  42. }
  43. public static function checkPayingOrder()
  44. {
  45. try {
  46. Db::beginTransaction();
  47. $timeUnix = strtotime("-30 minutes");
  48. $orders = Order::where('order_status_system', 'PAYING')
  49. ->where('order_addtimes', '<', $timeUnix)
  50. ->get();
  51. foreach ($orders as $order) {
  52. // 订单主表
  53. Order::where('order_id', $order->order_id)->update([
  54. 'order_category' => 'CANCEL',
  55. 'order_status_system' => 'CANCEL',
  56. 'order_status_payment' => 'CANCEL'
  57. ]);
  58. // 订单详情表
  59. OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CANCEL']);
  60. }
  61. Db::commit();
  62. } catch (\Exception $e) {
  63. Db::rollBack();
  64. }
  65. }
  66. public static function generateWriteOffData($params) {
  67. return [
  68. 'charge'=>[
  69. 'charge_amount'=>1,
  70. 'charge_content'=>$params['order_remark'] ?? '',
  71. 'charge_user_id'=>$params['write_off_member_id'],
  72. 'charge_premises'=>$params['dept_premises_id'],
  73. ],
  74. 'member_id'=>$params['join_order_member_id']
  75. ];
  76. }
  77. }