where('uid', $uid)->value('rz_money'); // if (!$total_amount || $total_amount < 1.5) // throw new Exception('认证费用不正确'); $body = '实名认证费用'; break; case 3: // 开通会员 $vip_money = Env::get('app.VIP_MONEY', 38); if (!$vip_money > 0) { throw new Exception('会员配置不存在'); } $body = '开通会员'; $total_amount = $vip_money; $remarks = $data['order_id']; break; case 4: //购买商品 $order_sn = $data['order_id']; // $checkingOrder = Order::checkingOrder($order_sn, $data['money'], $uid); // new $checkingOrder = Order::checkingOrder($order_sn, 0, $uid); if (!$checkingOrder) { throw new Exception('校验订单失败'); } if ($checkingOrder['flag'] !== 200) { throw new Exception($checkingOrder['msg']); } $body = '购买商品'; $total_amount = $checkingOrder['orderPayment']; $remarks = $order_sn; //更改订单支付状态为线下支付待审核状态 if ($this->data['channel'] == 4 && $this->data['order_type'] == 4) { Order::where('order_sn', 'in', $order_sn)->save(['pay_type' => 4, 'status' => 4]); } break; } if (!$body || !$total_amount || $total_amount <= 0) throw new Exception('配置错误'); // 这是测试 线要干掉 // $total_amount = floatval('0.'.mt_rand(1, 3).mt_rand(1, 9));; return [$body, $type == 1 ? $total_amount : bcmul($total_amount, 100, 2), $data['order_type'], $remarks, $data['trade_type'], $data['channel'], isset($data['voucher_img']) ? $data['voucher_img'] : '']; } /** * 保存订单信息 * @param array $param * @param int $pay_way */ public function setPaymentOrder(array $param, int $pay_way = 1) { $insert = [ 'total_fee' => $param['total_amount'], 'trade_type' => $param['trade_type'], 'body' => $param['body'], 'state' => 7, 'out_trade_no' => $param['out_trade_no'], 'pay_way' => $param['pay_way'], 'remarks' => $param['remarks'], 'order_type' => $param['order_type'], 'uid' => $param['uid'], 'voucher_img' => $param['voucher_img'], 'out_trade_no1'=>(isset($param['out_trade_no1'])?$param['out_trade_no1']:(isset($param['']))) ]; Db::name('payment')->insert($insert); } /** * 更改订单状态 * @return mixed */ public function afterPay() { if ($this->pay_status && !empty($this->notify_info)) { $pay_info = Db::name('payment')->where('out_trade_no', $this->notify_info['out_trade_no'])->where('state', 7)->where('pay_way', 2)->findOrEmpty(); if (!empty($pay_info)) { Db::startTrans(); try { Db::name('payment')->where('id', $pay_info['id'])->update(['state' => 6, 'pay_at' => date('Y-m-d H:i:s')]); // 更改订单状态 switch ($pay_info['order_type']) { case 1: // 充值 // $pay_num = Db::name('payment')->where(['uid' => $pay_info['uid'], 'state' => 6, 'order_type' => 1])->count('id'); // set_user_money($pay_info['uid'], $pay_info['total_fee'], 1); // if ($pay_num == 1 && $pay_info['total_fee'] >= 100) { // 首次充值并且金额大于100,送月会员 // $user = Db::name('user')->where('id', $pay_info['uid'])->field('vip,vip_expire_time')->find(); // $date = new \DateTime($user['vip_expire_time']); // $date->add(new \DateInterval(get_vip_datetime_string('monthly_card')['time'])); // $vip_expire_time = $date->format('Y-m-d H:i:s'); // vip到期时间 // $user_update['vip_expire_time'] = $vip_expire_time; // $user_update['vip_type'] = 'monthly_card'; // $user['vip'] < 1 && $user_update['vip'] = get_vip_datetime_string('monthly_card')['vip_type']; // Db::name('user')->where('id', $pay_info['uid'])->update($user_update); // Db::name('vip_log')->insert(['uid' => $pay_info['uid'], 'type' => 2, 'pay_price' => $pay_info['total_fee'], 'vip_expire_time' => $vip_expire_time, 'vip_type' => 'monthly_card']); // } break; case 3: // 充值会员 // CacheServices::set('is_lock_vipdata', 2); // 更改订单状态 // $order = VipOrderModel::where('order_id', $pay_info['remarks'])->find(); // // // 更新viporder为支付状态 // VipOrderModel::where('order_id', $pay_info['remarks'])->save(['status' => 2]); // // $buy_info = Db::name('user')->where('id', $order['user_id'])->find(); // Db::name('user')->where('id', $order['user_id'])->inc('vip_count', 1)->update(); // Db::name('user')->where('id', $order['user_id'])->save(['is_vip' => 1]); // Db::name('user')->where('id', $order['user_id'])->inc('target_inc', 3069)->update(); // $curpid = $buy_info['pid']; // if ($curpid > 0) { // while (1) { // if ($curpid == 0 || empty($curpid)) { // break; // } // $cur_user = Db::name('user')->where('id', $curpid)->find(); // Db::name('user')->where('id', $curpid)->inc('group_vip_count', 1)->update(); // $curpid = $cur_user['pid']; // } // } // //// $val = CacheServices::get('is_lock_vipdata', 0); //// if ($val == 1){ //// return api_error_return('请稍后再试1'); //// } // //// CacheServices::set('is_lock_vipdata', 1); //// Db::startTrans(); //// try { // $level = Db::name('vip_relation_data')->lock(true)->max('level'); // if (empty($level)) { // $level = 1; // } else { // $maxid = Db::name('vip_relation_data')->lock(true)->max('id'); // if ($maxid >= (pow(2, $level) - 1)) { // ++$level; // }; // } // if ($level > 1) { // $curarr = CacheServices::get('vip_level_data' . $level); // if (!$curarr) { // $info = Db::name('vip_level_data')->where(['level' => $level])->find(); // $curarr = explode(',', $info['value']); // CacheServices::set('vip_level_data' . $level, $curarr); // } // // 上一层最大的id // $max_level_info_id = Db::name('vip_relation_data')->where(['level' => $level - 1])->field('id')->lock(true)->max('id'); // $pid = $curarr[$maxid - $max_level_info_id]; // } else { // $pid = 0; // } // // $insertData = [ // 'create_time' => getCurTimeStamp(), // 'pid' => $pid, // 'level' => $level, // 'uid' => $buy_info['id'] // ]; // // Db::name('vip_relation_data')->lock(true)->insertGetId($insertData); //// \utils\Queue::instance()->log('会员VIP订单执行成功' . $buy_info['id'])->do('VipOrderBack')->job(VipOrderJob::class)->push([$level, $buy_info['id'], $pid]); // // break; case 4: //购买商品 // $order = Order::where(['order_sn' => explode(',', $pay_info['remarks'])])->select()->toArray(); // Order::payDoneOrderCallback($order, 3, $pay_info['uid']); $m_goods = new ShopGoodsModel(); $m_user = new UserModel(); $m_shoporder = new ShopOrderModel(); // 更改订单状态 $order = ShopOrderModel::where('order_sn', $pay_info['remarks'])->find(); $nowTime = date('Y-m-d H:i:s', time()); Db::name('shop_order')->where(['order_sn' => $pay_info['remarks']]) ->update(['pay_type' => 2, 'status' => 1, 'updated_time' => $nowTime]); // 增加销量 $orderGoods = OrderGoods::where(['order_id' => $order['order_id']])->select()->toArray(); foreach ($orderGoods as $k => $v) { ShopGoodsModel::where(['goods_id' => $v['goods_id']])->inc('sales_volume', $v['num'])->inc('real_sales_volume', $v['num'])->update(); } // 送积分 edit_user_score(5, $order['user_id'], $order['rebate_score']); edit_user_redscore(1, $order['user_id'], $order['rebate_lock_score']); break; } Db::commit(); echo 'success'; die; } catch (\Exception $e) { Db::rollback(); echo $e->getMessage(); die; } } echo 'success'; die; } echo 'failure'; die; } }