Code.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\shop\model\plus\giftpackage;
  3. use app\common\model\plus\giftpackage\Code as CodeModel;
  4. /**
  5. * 礼包购码
  6. */
  7. class Code extends CodeModel
  8. {
  9. /**
  10. * 生成码,code生成规则,活动id+下标
  11. */
  12. public function geneCode($gift_package_id, $code_type, $total_num){
  13. // 一批一码
  14. if($code_type == 10){
  15. $this->save([
  16. 'gift_package_id' => $gift_package_id,
  17. 'code' => $gift_package_id . '-1',
  18. 'app_id' => self::$app_id
  19. ]);
  20. }else{
  21. // 当前码数量
  22. $count = $this->where('gift_package_id', '=', $gift_package_id)->count();
  23. $data = [];
  24. for($i=0;$i<$total_num;$i++){
  25. $data[] = [
  26. 'gift_package_id' => $gift_package_id,
  27. 'code' => $gift_package_id . '-' . ($count + 1 + $i),
  28. 'app_id' => self::$app_id
  29. ];
  30. }
  31. $this->saveAll($data);
  32. }
  33. }
  34. }