BookCourseOrderServer.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\BookCourse;
  4. use app\admin\model\LifeBook;
  5. use app\admin\model\LifeBookCourse;
  6. class BookCourseOrderServer
  7. {
  8. /**
  9. * Notes:获取商品列表
  10. * @param string $keywords
  11. * @param int $page
  12. * @param int $limit
  13. * @return array
  14. * User: ZQ
  15. * Date: 2022/9/13
  16. */
  17. public static function getOrderList(int $page, int $limit, string $keywords)
  18. {
  19. [$list, $count] = BookCourse::getOrderList($page, $limit, $keywords);
  20. if (!empty($list)){
  21. foreach ($list as $k => $v){
  22. $list[$k]['order_create_time'] = date('Y-m-d H:i:s',$v['order_create_time']);
  23. $list[$k]['order_update_time'] = $v['order_update_time'] ? date('Y-m-d H:i:s',$v['order_update_time']) : '';
  24. }
  25. }
  26. return compact('list', 'page', 'limit', 'count');
  27. }
  28. /**
  29. * Notes:获取订单详情
  30. * @param int $order_id
  31. * @return int
  32. * User: QJF
  33. * Date: 2022/10/14
  34. */
  35. public static function getOrderInfo($order_id)
  36. {
  37. BookCourse::affairBegin();
  38. try {
  39. $where = [];
  40. $where['order_id'] = $order_id;
  41. $result = BookCourse::with(['user','Detail'])->where($where)->first();
  42. if (!empty($result)){
  43. foreach ($result['detail'] as $k => $v){
  44. $result['detail'][$k]['book_name'] = LifeBook::where(['life_book_id'=>$v['log_book_id']])->value('life_book_name');
  45. $result['detail'][$k]['course_name'] = LifeBookCourse::where(['course_id'=>$v['log_course_id']])->value('course_name');
  46. }
  47. BookCourse::affairCommit();
  48. return $result;
  49. }else{
  50. return false;
  51. }
  52. }catch (\Exception $exception){
  53. BookCourse::affairRollback();
  54. throw new \Exception($exception->getMessage(), 500);
  55. }
  56. }
  57. //删除订单
  58. public static function delOrder($order_id)
  59. {
  60. BookCourse::affairBegin();
  61. try {
  62. $where = [];
  63. $where['order_id'] = $order_id;
  64. $data['order_is_del'] = 1;
  65. $data['order_update_time'] = time();
  66. $result = BookCourse::where($where)->update($data);
  67. if (!empty($result)){
  68. BookCourse::affairCommit();
  69. return true;
  70. }else{
  71. return false;
  72. }
  73. }catch (\Exception $exception){
  74. BookCourse::affairRollback();
  75. throw new \Exception($exception->getMessage(), 500);
  76. }
  77. }
  78. /**
  79. * Notes:修改订单支付状态
  80. * @param string $order_id
  81. * @param int $order_finish
  82. * @return int
  83. * User: YCP
  84. * Date: 2022/11/28
  85. */
  86. public static function updatePayStatus($order_id, $order_status)
  87. {
  88. BookCourse::affairBegin();
  89. try {
  90. $where = [];
  91. $where['order_id'] = $order_id;
  92. $data = [];
  93. $data['order_status'] = $order_status;
  94. if($order_status == 2){
  95. $data['order_pay_time'] = time();
  96. }else{
  97. $data['order_pay_time'] = "";
  98. }
  99. $result = BookCourse::where($where)->update($data);
  100. if ($result !== false){
  101. BookCourse::affairCommit();
  102. return true;
  103. }
  104. throw new \Exception('操作失败!');
  105. }catch (\Exception $exception){
  106. BookCourse::affairRollback();
  107. throw new \Exception($exception->getMessage(), 500);
  108. }
  109. }
  110. }