ThirdxzDforderModel.php 3.7 KB

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