ThirdxzHforderModel.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\common\model;
  3. use jobs\JpOrderJob;
  4. use jobs\ShopOrderJob;
  5. use think\db\exception\DbEventException;
  6. use think\Exception;
  7. use think\facade\Db;
  8. use think\Model;
  9. use utils\Queue;
  10. use function Qcloud\Cos\startWith;
  11. use function Sodium\library_version_minor;
  12. class ThirdxzHforderModel extends Model
  13. {
  14. protected $name = 'thirdxz_hforder';
  15. // 话费充值提交
  16. public function hforderSubmit($uid, $data){
  17. $prodoct_id = $data['prodoct_id'];
  18. $type = $data['type'];
  19. $mobile = $data['mobile'];
  20. $user_info = Db::name('user')->where('id', $uid)->field('id,xz_num,coupon_num')->find();
  21. // 老马的下级不能转赠
  22. if (strpos($user_info['path'], '7493430') !== false){
  23. sr_throw('失败,请联系上面团队长');
  24. }
  25. if ($uid == 7493430){
  26. sr_throw('失败,请联系上面团队长');
  27. }
  28. $hfgoods_info = Db::name('third_xzgoods')->where('prodoct_id', $prodoct_id)->findOrEmpty();
  29. if (!$hfgoods_info){
  30. sr_throw('参数错误');
  31. }
  32. if ($hfgoods_info['s_type'] != $type){
  33. sr_throw('参数错误');
  34. }
  35. if ($hfgoods_info['cz_type'] != 1){
  36. sr_throw('参数错误');
  37. }
  38. // 手续费
  39. // $scale = env('XZTHIRD.XZ_EXCHARGE_SCALE', 5);
  40. $scale = get_user_shouxufei($uid);
  41. $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value');
  42. $xz_num = getXzPirceWithPrice($cur_xzmoney, $hfgoods_info['sale_price']);
  43. $shouxu_num = number_format($xz_num*$scale/100, '2', '.', '');
  44. $need_num = $xz_num + $shouxu_num;
  45. // sr_throw($need_num);
  46. if ($user_info['xz_num'] < $need_num){
  47. sr_throw('星钻不足,兑换失败');
  48. }
  49. if ($user_info['xz_num'] < ($need_num + 10)){
  50. sr_throw('兑换失败,账户必须还有十个星钻剩余');
  51. }
  52. // 抢购值
  53. $need_couponnum = $hfgoods_info['spec']/10;
  54. if ($user_info['coupon_num'] < $need_couponnum){
  55. sr_throw('抢购值不足,需'.$need_couponnum.'个抢购值');
  56. }
  57. if (Db::name('thirdxz_hforder')->where('uid', $uid)->whereDay('create_time', 'today')->find()){
  58. sr_throw('今日已兑换,请明天再来');
  59. }
  60. // $limit = 30;
  61. // // 每天三十份
  62. // if (Db::name('thirdxz_hforder')->whereDay('create_time', 'today')->count('id') > $limit-1){
  63. // sr_throw('今日平台限量已达到'.$limit.'份,明日在来哦~~');
  64. // }
  65. if (Db::name('thirdxz_hforder')->whereTime('create_time', 'month')->where('status', 2)->where('uid', $uid)->find()){
  66. sr_throw('充值失败,每个美康用户每月只能兑换一次');
  67. }
  68. //
  69. if (Db::name('thirdxz_hforder')->whereTime('create_time', 'month')->where('status', 2)->where('mobile', $mobile)->find()){
  70. sr_throw('充值失败,每个手机号码每月只能兑换一次');
  71. }
  72. // 添加订单表
  73. $insert_id = self::insertGetId([
  74. 'hf_ordersn'=>creathfOrderSn($uid),
  75. 'third_xzid'=>$hfgoods_info['id'],
  76. 'prodoct_id'=>$prodoct_id,
  77. 'create_time'=>sr_getcurtime(time()),
  78. 'uid'=>$uid,
  79. 'mobile'=>$mobile,
  80. 'type'=>$type,
  81. 'xz_num'=>$xz_num,
  82. 'shouxu'=>$shouxu_num,
  83. 'price'=>$hfgoods_info['spec'],
  84. 'expect_time'=>sr_getcurtime(strtotime('+5 day'), 'Y-m-d')
  85. ]);
  86. // 扣除星钻
  87. edit_user_xz(14, $uid, $need_num, $insert_id, $shouxu_num);
  88. // 扣除抢购值
  89. edit_user_couponnum(3, $uid, $need_couponnum);
  90. }
  91. }