PresellOrderDao.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\order;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\store\order\PresellOrder;
  15. class PresellOrderDao extends BaseDao
  16. {
  17. protected function getModel(): string
  18. {
  19. return PresellOrder::class;
  20. }
  21. /**
  22. * 根据条件搜索预售订单。
  23. *
  24. * 该方法通过接收一个包含搜索条件的数组,动态地构建查询语句来搜索预售订单。
  25. * 可以根据支付方式、支付状态、商家ID和订单ID列表来过滤结果。
  26. *
  27. * @param array $where 包含搜索条件的数组,其中可能包含pay_type、paid、mer_id和order_ids键。
  28. * @return \think\db\Query|null 返回构建的查询对象,或者在没有符合条件的查询时返回null。
  29. */
  30. public function search(array $where)
  31. {
  32. // 获取数据库查询对象
  33. return PresellOrder::getDB()->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
  34. // 如果支付方式被指定且不为空,则添加支付方式的查询条件
  35. $query->whereIn('pay_type', $where['pay_type']);
  36. })->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
  37. // 如果支付状态被指定且不为空,则添加支付状态的查询条件
  38. $query->where('paid', $where['paid']);
  39. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  40. // 如果商家ID被指定且不为空,则添加商家ID的查询条件
  41. $query->where('mer_id', $where['mer_id']);
  42. })->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
  43. // 如果订单ID列表被指定且不为空,则添加订单ID在指定列表中的查询条件
  44. $query->where('order_id','in',$where['order_ids']);
  45. });
  46. }
  47. /**
  48. * 根据用户ID和订单ID查询预售订单信息
  49. *
  50. * 本函数旨在通过用户ID和订单ID从数据库中检索特定的预售订单。它使用了PresellOrder类的数据库访问方法来执行查询。
  51. * 查询条件是用户ID(uid)和订单ID(order_id)匹配,返回的是匹配的订单数据。
  52. *
  53. * @param int $uid 用户ID,用于指定订单所属的用户。
  54. * @param string $orderId 订单ID,用于唯一标识订单。
  55. * @return array|false 返回匹配的预售订单数据,如果找不到则返回false。
  56. */
  57. public function userOrder($uid, $orderId)
  58. {
  59. // 使用PresellOrder类的静态方法getDB来获取数据库实例,并构造查询条件,最后执行查询并返回结果
  60. return PresellOrder::getDB()->where('uid', $uid)->where('order_id', $orderId)->find();
  61. }
  62. /**
  63. * 获取过期未支付的预售订单ID列表
  64. *
  65. * 本函数用于查询数据库中状态为进行中(status=1)、未支付(paid=0)、且结束时间早于指定时间($time)的预售订单ID。
  66. * 这些ID可用于后续的过期订单处理,比如提醒用户、或者自动取消订单等操作。
  67. *
  68. * @param int|string $time 结束时间的判断标准。可以是Unix时间戳或者符合数据库查询格式的日期字符串。
  69. * @return array 过期未支付的预售订单ID列表。
  70. */
  71. public function getTimeOutIds($time)
  72. {
  73. // 使用查询构建器查询符合条件的预售订单,并只返回presell_order_id列
  74. return PresellOrder::getDB()->where('status', 1)->where('paid', 0)
  75. ->where('final_end_time', '<', $time)->column('presell_order_id');
  76. }
  77. /**
  78. * 获取指定日期内的未支付预订单的短信ID列表
  79. *
  80. * 本函数用于查询指定日期内,状态为有效(1)且未支付的预订单的订单ID列表。
  81. * 查询条件基于订单的支付状态和最终开始时间,通过like操作符匹配日期部分。
  82. *
  83. * @param string $date 日期字符串,格式为Y-m-d,用于查询订单的最终开始时间。
  84. * @return array 返回符合条件的预订单ID列表。
  85. */
  86. public function sendSmsIds($date)
  87. {
  88. // 使用预订单模型的数据库查询方法,指定查询条件为状态为1,未支付,且最终开始时间like传入日期字符串加百分号。
  89. // 返回查询结果中订单ID一列的值。
  90. return PresellOrder::getDB()->where('status', 1)->where('paid', 0)
  91. ->whereLike('final_start_time', $date . '%')->column('order_id');
  92. }
  93. }