Order.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. if(!empty($product['store_name'])) {
  19. $list[$k]['store_name'] = $product['store_name'];
  20. }else{
  21. $list[$k]['store_name'] = '';
  22. }
  23. if(!empty($product['image'])) {
  24. $list[$k]['image'] = $product['image'];
  25. }else{
  26. $list[$k]['image'] = '';
  27. }
  28. if(!empty($product['suk'])) {
  29. $list[$k]['suk'] = $product['suk'];
  30. }else{
  31. $list[$k]['suk'] = '';
  32. }
  33. }
  34. return $list;
  35. }
  36. /**
  37. * 获取列表数据
  38. * @param $page
  39. * @param $where
  40. * @param $pageCount
  41. * @param $desc
  42. */
  43. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
  44. $data = $this
  45. ->field("o.*,pf.name as platfrom_name,p.title as pro_title,p.img as pro_img"
  46. .",(select count(*) from table_order_info where o_id = o.id " .
  47. (empty($where['shop_id']) ? '' : (' AND shop_id='.$where['shop_id']) )
  48. . ") as order_count"
  49. )
  50. ->alias("o")
  51. ->join('platform pf',"pf.id=o.platform_id")
  52. ->when(!empty($where),function ($query) use($where){
  53. //分站
  54. if(!empty($where['sassid'])) {
  55. $query->where('o.sassid',$where['sassid']);
  56. }
  57. //店铺信息
  58. if(!empty($where['shop_id'])) {
  59. $query->whereRaw("(SELECT count(*) from table_order_info where o_id = o.id AND shop_id =:shop_id) > 0",
  60. ['shop_id'=>$where['shop_id']]);
  61. }
  62. //用户
  63. if(!empty($where['uid'])) {
  64. $query->where('o.uid',$where['uid']);
  65. }
  66. //搜索订单
  67. if(!empty($where['order_id'])) {
  68. $query->whereLike('o.order_id',"%{$where['order_id']}%");
  69. }
  70. //搜索平台
  71. if(!empty($where['platform_id'])) {
  72. $query->whereLike('o.platform_id',$where['platform_id']);
  73. }
  74. //搜索备注信息
  75. if(!empty($where['mono'])) {
  76. $query->whereLike('o.order_id',"%{$where['mono']}%");
  77. }
  78. //查询日期
  79. if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
  80. $query->whereTime('o.time','between',$where['data']);
  81. }
  82. //订单类型
  83. if(is_numeric($where['orderType'])) {
  84. $query->where('o.status',$where['orderType']);
  85. }
  86. //timeType[今日,昨日,最近7天,最近30天]
  87. if(!empty($where['timeType'])) {
  88. if($where['timeType'] == 'day') {
  89. $query->whereDay('o.time');
  90. }
  91. if($where['timeType'] == 'yesterday') {
  92. $query->whereDay('o.time','yesterday');
  93. }
  94. if($where['timeType'] == 'last7') {
  95. $query->whereTime('o.time','-7 day');
  96. }
  97. if($where['timeType'] == 'last30') {
  98. $query->whereTime('o.time','-30 day');
  99. }
  100. }
  101. })
  102. ->leftJoin('product p',"p.id = o.pro_id")
  103. ->order($desc)
  104. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  105. ->toArray();
  106. //echo $this->getLastSql();
  107. return [$data['total'],$data['data']];
  108. }
  109. }