| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\common\model;
- use jobs\JpOrderJob;
- use jobs\ShopOrderJob;
- use think\db\exception\DbEventException;
- use think\Exception;
- use think\facade\Db;
- use think\Model;
- use utils\Queue;
- use function Qcloud\Cos\startWith;
- use function Sodium\library_version_minor;
- class ThirdxzHforderModel extends Model
- {
- protected $name = 'thirdxz_hforder';
- // 话费充值提交
- public function hforderSubmit($uid, $data){
- $prodoct_id = $data['prodoct_id'];
- $type = $data['type'];
- $mobile = $data['mobile'];
- $user_info = Db::name('user')->where('id', $uid)->field('id,xz_num,coupon_num')->find();
- // 老马的下级不能转赠
- if (strpos($user_info['path'], '7493430') !== false){
- sr_throw('失败,请联系上面团队长');
- }
- if ($uid == 7493430){
- sr_throw('失败,请联系上面团队长');
- }
- $hfgoods_info = Db::name('third_xzgoods')->where('prodoct_id', $prodoct_id)->findOrEmpty();
- if (!$hfgoods_info){
- sr_throw('参数错误');
- }
- if ($hfgoods_info['s_type'] != $type){
- sr_throw('参数错误');
- }
- if ($hfgoods_info['cz_type'] != 1){
- sr_throw('参数错误');
- }
- // 手续费
- // $scale = env('XZTHIRD.XZ_EXCHARGE_SCALE', 5);
- $scale = get_user_shouxufei($uid);
- $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value');
- $xz_num = getXzPirceWithPrice($cur_xzmoney, $hfgoods_info['sale_price']);
- $shouxu_num = number_format($xz_num*$scale/100, '2', '.', '');
- $need_num = $xz_num + $shouxu_num;
- // sr_throw($need_num);
- if ($user_info['xz_num'] < $need_num){
- sr_throw('星钻不足,兑换失败');
- }
- if ($user_info['xz_num'] < ($need_num + 10)){
- sr_throw('兑换失败,账户必须还有十个星钻剩余');
- }
- // 抢购值
- $need_couponnum = $hfgoods_info['spec']/10;
- if ($user_info['coupon_num'] < $need_couponnum){
- sr_throw('抢购值不足,需'.$need_couponnum.'个抢购值');
- }
- if (Db::name('thirdxz_hforder')->where('uid', $uid)->whereDay('create_time', 'today')->find()){
- sr_throw('今日已兑换,请明天再来');
- }
- // $limit = 30;
- // // 每天三十份
- // if (Db::name('thirdxz_hforder')->whereDay('create_time', 'today')->count('id') > $limit-1){
- // sr_throw('今日平台限量已达到'.$limit.'份,明日在来哦~~');
- // }
- if (Db::name('thirdxz_hforder')->whereTime('create_time', 'month')->where('status', 2)->where('uid', $uid)->find()){
- sr_throw('充值失败,每个美康用户每月只能兑换一次');
- }
- //
- if (Db::name('thirdxz_hforder')->whereTime('create_time', 'month')->where('status', 2)->where('mobile', $mobile)->find()){
- sr_throw('充值失败,每个手机号码每月只能兑换一次');
- }
- // 添加订单表
- $insert_id = self::insertGetId([
- 'hf_ordersn'=>creathfOrderSn($uid),
- 'third_xzid'=>$hfgoods_info['id'],
- 'prodoct_id'=>$prodoct_id,
- 'create_time'=>sr_getcurtime(time()),
- 'uid'=>$uid,
- 'mobile'=>$mobile,
- 'type'=>$type,
- 'xz_num'=>$xz_num,
- 'shouxu'=>$shouxu_num,
- 'price'=>$hfgoods_info['spec'],
- 'expect_time'=>sr_getcurtime(strtotime('+5 day'), 'Y-m-d')
- ]);
- // 扣除星钻
- edit_user_xz(14, $uid, $need_num, $insert_id, $shouxu_num);
- // 扣除抢购值
- edit_user_couponnum(3, $uid, $need_couponnum);
- }
- }
|