Order.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\model\api;
  3. use app\model\system\ProductAttrValue;
  4. use library\basic\BaseModel;
  5. use think\Model;
  6. /**
  7. * @mixin \think\Model
  8. */
  9. class Order extends BaseModel
  10. {
  11. public function getUserOrderList($uid, $where){
  12. $list = $this->where('status', $where['type'])->where('uid', $uid)
  13. ->order('time DESC')->page((int)$where['page'], (int)$where['limit'])->select()->toArray();
  14. foreach ($list as $k =>$v){
  15. $list[$k]['_time'] = date('Y-m-d H:i:s', $v['time']);
  16. $product = ProductAttrValue::alias('a')->join('product s', 'a.product_id=s.id')
  17. ->where('a.product_id',$v['pro_id'])->where('a.unique',$v['unique'])->field('a.*,s.store_name')->find();
  18. $list[$k]['store_name'] = $product['store_name'];
  19. $list[$k]['image'] = $product['image'];
  20. $list[$k]['suk'] = $product['suk'];
  21. }
  22. return $list;
  23. }
  24. /**
  25. * 获取列表数据
  26. * @param $page
  27. * @param $where
  28. * @param $pageCount
  29. * @param $desc
  30. */
  31. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
  32. $data = $this
  33. ->field("o.*,pf.name as platfrom_name,p.title as pro_title,p.img as pro_img"
  34. .",(select count(*) from table_order_info where o_id = o.id " .
  35. (empty($where['shop_id']) ? '' : (' AND shop_id='.$where['shop_id']) )
  36. . ") as order_count"
  37. )
  38. ->alias("o")
  39. ->join('platform pf',"pf.id=o.platform_id")
  40. ->when(!empty($where),function ($query) use($where){
  41. //分站
  42. if(!empty($where['sassid'])) {
  43. $query->where('o.sassid',$where['sassid']);
  44. }
  45. //店铺信息
  46. if(!empty($where['shop_id'])) {
  47. $query->whereRaw("(SELECT count(*) from table_order_info where o_id = o.id AND shop_id =:shop_id) > 0",
  48. ['shop_id'=>$where['shop_id']]);
  49. }
  50. //用户
  51. if(!empty($where['uid'])) {
  52. $query->where('o.uid',$where['uid']);
  53. }
  54. //搜索订单
  55. if(!empty($where['order_id'])) {
  56. $query->whereLike('o.order_id',"%{$where['order_id']}%");
  57. }
  58. //搜索平台
  59. if(!empty($where['platform_id'])) {
  60. $query->whereLike('o.platform_id',$where['platform_id']);
  61. }
  62. //搜索备注信息
  63. if(!empty($where['mono'])) {
  64. $query->whereLike('o.order_id',"%{$where['mono']}%");
  65. }
  66. //查询日期
  67. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  68. $query->whereTime('o.time','between',$where['data']);
  69. }
  70. //订单类型
  71. if(is_numeric($where['orderType'])) {
  72. $query->where('o.status',$where['orderType']);
  73. }
  74. //timeType[今日,昨日,最近7天,最近30天]
  75. if(!empty($where['timeType'])) {
  76. if($where['timeType'] == 'day') {
  77. $query->whereDay('o.time');
  78. }
  79. if($where['timeType'] == 'yesterday') {
  80. $query->whereDay('o.time','yesterday');
  81. }
  82. if($where['timeType'] == 'last7') {
  83. $query->whereTime('o.time','-7 day');
  84. }
  85. if($where['timeType'] == 'last30') {
  86. $query->whereTime('o.time','-30 day');
  87. }
  88. }
  89. })
  90. ->leftJoin('product p',"p.id = o.pro_id")
  91. ->order($desc)
  92. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  93. ->toArray();
  94. //echo $this->getLastSql();
  95. return [$data['total'],$data['data']];
  96. }
  97. }