CouponRedeemCodes.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\store\model\coupon;
  3. use app\common\library\helper;
  4. use app\common\model\coupon\CouponRedeemCodes as RedeemCodesModel;
  5. /**
  6. * 优惠券生成兑换码记录模型
  7. * @package app\common\model
  8. */
  9. class CouponRedeemCodes extends RedeemCodesModel
  10. {
  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. /**
  23. * 校验码是否用过
  24. * @param $code
  25. * @return bool
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public function checkExistedCode($code){
  31. $m = new self();
  32. if ($m->where('redeem_code',$code)->find()){
  33. return true;
  34. }
  35. return false;
  36. }
  37. public function getAllList($genId){
  38. return $this->alias('rc')
  39. ->leftJoin('coupon cp', 'rc.coupon_id = cp.coupon_id')
  40. ->leftJoin('coupon_gen_redeem_codes gc', 'rc.coupon_gen_redeem_codes_id = gc.id')
  41. ->where('coupon_gen_redeem_codes_id',$genId)
  42. ->field('rc.id,rc.redeem_code,rc.coupon_id,gc.give_channel,cp.name,cp.coupon_type')->paginate(15);
  43. }
  44. public function redeemCodesExport($param,$all=false){
  45. $ids = $param['ids'];
  46. $data['header'] = ['序号','优惠券名称','兑换码', '发放渠道'];
  47. $data['filename'] = '优惠券兑换码导出';
  48. $data['data'] = [];
  49. $items = $this->alias('rc')
  50. ->leftJoin('coupon cp', 'rc.coupon_id = cp.coupon_id')
  51. ->leftJoin('coupon_gen_redeem_codes gc', 'rc.coupon_gen_redeem_codes_id = gc.id');
  52. if ($all == true){
  53. $items = $items->where('rc.coupon_gen_redeem_codes_id',$param['id']);
  54. }
  55. if (count($ids) > 0){
  56. $items = $items->whereIn('rc.id',$ids);
  57. }
  58. $items = $items->field('(rc.id+70000000) as id,cp.name,rc.redeem_code,gc.give_channel')->select()->toArray();
  59. //$items = [];
  60. $data['data'] = $items;
  61. return $data;
  62. }
  63. }