Usercoupondetail.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\common\model\coupon;
  3. use app\common\library\helper;
  4. use think\facade\Db;
  5. use app\common\model\BaseModel;
  6. use app\common\model\User;
  7. use app\common\model\GoodsSku as GoodsSkuModel;
  8. use app\common\model\Goods as GoodsModel;
  9. /**
  10. * 用户优惠券使用详情模型 已废弃
  11. * @package app\common\model
  12. */
  13. class Usercoupondetail extends BaseModel
  14. {
  15. const COUPON_TYPE = [ 1=>'电子卡', 2=>'实体卡'];
  16. const COUPON_CATEGORY = [1=>'兑换卡', 2=>'储值卡'];
  17. protected $name = 'user_coupon_detail';
  18. /**
  19. * 兑换详细列表
  20. * @param string $dataType 订单类型
  21. * @param array $param
  22. * @return mixed
  23. */
  24. public function getAllList(array $param = [])
  25. {
  26. // 检索查询条件
  27. $filter = $this->getQueryFilter($param);
  28. // 获取数据列表
  29. $query = $this->with([])->where($filter)
  30. ->leftJoin('user', 'user.user_id = detail.user_id')
  31. ->alias('detail')
  32. ->field('detail.*,user.mobile,user.nick_name');
  33. $list = $query->order(['detail.id' => 'desc'])->paginate(15);
  34. foreach($list as $row){
  35. $row->coupon_user = User::field('mobile,nick_name')->where("user_id",$row->coupon_user_id)->find();
  36. $goodsku = GoodsSkuModel::where('goods_sku_id',$row->good_sku_id)->where('goods_id',$row->good_id)->find();
  37. $goods = GoodsModel::field('goods_name')->where("goods_id",$row->good_id)->find();
  38. $row->sku_name = $goodsku->goods_props[0]['value']['name']??'';
  39. $row->good_name = $goods->goods_name??'';
  40. }
  41. return $list;
  42. }
  43. //查询
  44. public function getQueryFilter($param){
  45. if($param['user_coupon_id']>0){
  46. return $param;
  47. }
  48. }
  49. /**
  50. * 获取兑换明细列表
  51. * @param int|null $limit 获取的数量
  52. * @param bool $onlyReceive 只显示可领取
  53. * @return \think\Collection
  54. * @throws BaseException
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. */
  59. public function getList(array $user_coupon_id_arr,int $limit = 15){
  60. // 查询构造器
  61. $query = $this->getNewQuery();
  62. //查询数量
  63. $limit > 0 && $query->limit($limit);
  64. $list = $query->where('user_coupon_id','in',$user_coupon_id_arr)
  65. ->order(['id' => 'desc'])
  66. ->select();
  67. return $list;
  68. }
  69. }