RealRiceCardList.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\store\model\card;
  3. use app\common\model\card\RealRiceCardList as RealRiceCardListModel;
  4. /**
  5. * 米卡面额模型
  6. * @package app\common\model
  7. */
  8. class RealRiceCardList extends RealRiceCardListModel
  9. {
  10. protected $name = 'real_rice_card_list';
  11. /**
  12. * 批量添加兑换码
  13. * @param $data
  14. * @return bool
  15. * @throws \Exception
  16. */
  17. public function addBatch($data){
  18. $m = new self();
  19. $m->saveAll($data);
  20. return true;
  21. }
  22. public function getActiveTimeAttr($value){
  23. return $value?date('Y-m-d H:i:s',$value):'';
  24. }
  25. public function getAllList($params){
  26. $filter = $this->getQueryFilter($params);
  27. $m = $this->alias('gc')
  28. ->leftJoin('gen_real_rice_cards rg','gc.gen_real_rice_card_id=rg.id')
  29. ->leftJoin('rice_card rc','gc.rice_card_id=rc.id')
  30. ->where('gc.gen_real_rice_card_id',$params['genId']);
  31. if (count($filter)){
  32. $m = $m->where($filter);
  33. }
  34. //调试模式开启兑换码
  35. if (env('APP_DEBUG')){
  36. $fields = 'gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,gc.redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type,rc.name,if(rc.expire_day>0,FROM_UNIXTIME(gc.create_time + (rc.expire_day-1)*86400,"%Y-%m-%d 23:59:59"),"永久有效") as expire_time,rc.describe,rc.card_price,rg.sale_channel';
  37. }else{
  38. $fields = 'gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,concat(left(gc.redeem_code,2),"****",right(gc.redeem_code,2)) as redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type,rc.name,if(rc.expire_day>0,FROM_UNIXTIME(gc.create_time + (rc.expire_day-1)*86400,"%Y-%m-%d 23:59:59"),"永久有效") as expire_time,rc.describe,rc.card_price,rg.sale_channel';
  39. }
  40. //'gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,gc.redeem_code,concat(left(gc.redeem_code,2),"****",right(gc.redeem_code,2)) as mi_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type,rc.name,FROM_UNIXTIME(gc.create_time + rc.expire_day*86400) as expire_time,rc.describe,rc.card_price,rg.sale_channel'
  41. return $m->field($fields)
  42. ->order('id','asc')->paginate(15);
  43. }
  44. //查询
  45. public function getQueryFilter($param){
  46. $filter = [];
  47. if(isset($param['name']) && $param['name']){
  48. $filter[] = ['rc.name','like','%'.$param['name'].'%'];
  49. }
  50. if(isset($param['type']) && $param['type'] > 0){
  51. $filter[] = ['rc.type','=',$param['type']];
  52. }
  53. if(isset($param['export']) && $param['export'] >= 0){
  54. $filter[] = ['gc.been_exported','=',$param['export']];
  55. }
  56. // 创建时间
  57. if (!empty($param['createTime'])) {
  58. $times = between_time($param['createTime']);
  59. $filter[] = ['gc.create_time', '>=', $times['start_time']];
  60. $filter[] = ['gc.create_time', '<', $times['end_time'] + 86400];
  61. }
  62. return $filter;
  63. }
  64. public function updateFrozenStatus($param){
  65. $this->where('id',$param['id'])->update(['frozen_status'=>$param['status']]);
  66. return true;
  67. }
  68. public function updateBeenExported($param){
  69. $this->whereIn('id',$param['ids'])->update(['been_exported'=>1]);
  70. return true;
  71. }
  72. public function redeemCodesExport($param,$all=false){
  73. $ids = $param['ids'];
  74. $data['header'] = ['序号','卡号','米卡名称','米卡售价', '米卡类型','截止日期','激活码','销售渠道','生成时间','是否导出','当前状态','激活时间'];
  75. $data['filename'] = '实体实物兑换卡';
  76. $data['data'] = [];
  77. $m = $this->alias('gc')
  78. ->leftJoin('gen_real_rice_cards rg','gc.gen_real_rice_card_id=rg.id')
  79. ->leftJoin('rice_card rc','gc.rice_card_id=rc.id');
  80. if ($all == true){
  81. $m = $m->where('gc.gen_real_rice_card_id',$param['id']);
  82. }
  83. if (count($ids) > 0){
  84. $m = $m->whereIn('gc.id',$ids);
  85. }
  86. //->where('gc.gen_real_rice_card_id',$param['genId']);
  87. /* if (count($filter)){
  88. $m = $m->where($filter);
  89. }*/
  90. //$lists = $m->field('gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,concat(left(gc.redeem_code,2),"****",right(gc.redeem_code,2)) as redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type as types,rc.name as cname,rc.expire_day,rc.card_price,rg.sale_channel')
  91. $lists = $m->field('gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,gc.redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type as types,rc.name as cname,rc.expire_day,rc.card_price,rg.sale_channel')
  92. ->order('id','asc')->select();
  93. $items = [];
  94. foreach ($lists as $key=>$list){
  95. $temp = [];
  96. $temp['id'] = $key+1;//$list->id;
  97. $temp['card_number'] = $list->card_number;
  98. $temp['name'] = $list->cname;
  99. $temp['card_price'] = $list->card_price;
  100. $temp['type'] = RiceCard::TYPE[$list->types];
  101. $temp['expire_day'] = $list->expire_day>0?date('Y-m-d 23:59:59',strtotime($list->create_time) + ($list->expire_day-1)*86400):'永久有效';
  102. $temp['redeem_code'] = $list->redeem_code;
  103. $temp['sale_channel'] = $list->sale_channel;
  104. $temp['create_time'] = $list->create_time;
  105. $temp['been_exported'] = '是';
  106. $temp['status'] = $list->been_active?'已激活':($list->frozen_status?'已冻结':'未激活');
  107. $temp['active_time'] = $list->active_time;
  108. //$temp['active_time'] = $list->active_time?date('Y-m-d H:i:s',$list->active_time):'-';
  109. $items[] = $temp;
  110. }
  111. $data['data'] = $items;
  112. return $data;
  113. }
  114. }