12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use wxpay;
- use addons\epay\library\Service;
- /**
- * 支付回调
- */
- class Notify extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- // 支付回调
- public function notify() {
- // require_once($_SERVER['DOCUMENT_ROOT'] . "/Plugins/WxPay/WxPay.php");
- $wxPay = new wxpay\WxPay();
- //验证是否是微信发送
- $flag = $wxPay->WxPayNotifyCheck();
- // error_log(print_r($flag, 1), 3, 'post.txt');
- // LL($flag,'./log1.txt');
- //验证成功
- if ($flag['status']) {
- if ($flag['data']['return_code'] == 'SUCCESS' && $flag['data']['result_code'] == 'SUCCESS') {
- $total_fee = trim($flag['data']['total_fee']) / 100; //支付的金额, 单位:分转成元
- $order_sn = trim($flag['data']['out_trade_no']);//商家订单号
- $PayResult = Db::name('rechar_order');
- $where['order_no'] = $order_sn;
- $order_info = $PayResult->where($where)->find();
- if ($order_info['money'] != $total_fee) {
- $r_arr['return_code'] = 'FAIL';
- $r_arr['return_msg'] = '回调失败';
- echo $wxPay->arrayToXml($r_arr);
- die;
- }
- if ($order_info['status'] == 1) {
- $r_arr['return_code'] = 'SUCCESS';
- $r_arr['return_msg'] = '回调成功';
- echo $wxPay->arrayToXml($r_arr);
- die;
- }
- //构建支付订单处理结果信息
- $_data['transaction_id'] = trim($flag['data']['transaction_id']); //微信交易凭证
- $_data['status'] = 1;
- $_data['updatetime'] = time();
- //支付订单类型
- if ($order_info['purpose'] == 1) {
- //查询订单
- $active_order = Db::name('game_people')->find($order_info['relation_id']);
- //开启事务
- Db::startTrans();
- //修改报名状态
- $active_order_rs = Db::name('game_people')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
- //活动标题
- $active_title = Db::name('game')->where(['id' => $active_order['game_id']])->value('name');
- //发送消息
- $data = [
- 'user_id' => $order_info['user_id'],
- 'type' => 1,
- 'title' => '比赛通知',
- 'content' => '您已成功报名' . $active_title . '比赛',
- 'createtime' => time()
- ];
- $sys_rs = Db::name('sys_msg')->insertGetId($data);
- if ($active_order_rs && $sys_rs) {
- Db::commit();
- } else {
- Db::rollback();
- $_data['pay_status'] = 1; //回调状态: 1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
- }
- }
- $PayResult->where($where)->setField($_data);
- $r_arr['return_code'] = 'SUCCESS';
- $r_arr['return_msg'] = '回调成功';
- echo $wxPay->arrayToXml($r_arr);
- die;
- }
- }
- $r_arr['return_code'] = 'FAIL';
- $r_arr['return_msg'] = '回调失败';
- echo $wxPay->arrayToXml($r_arr);
- file_put_contents('wx_pay_error_logs.txt', date('Y-m-d H:i:s').'支付失败!'.json_encode($flag), FILE_APPEND);
- die;
- }
- /**
- * 支付回调
- */
- public function notify1() {
- $paytype = $this->request->param('paytype');
- $pay = Service::checkNotify($paytype);
- // Log::record("=======================", 'info');
- // Log::record("pay:", 'info');
- // Log::record($pay, 'info');
- // Log::record("=======================", 'info');
- if (!$pay) {
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- $time = time();
- try {
- $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
- $out_trade_no = $data['out_trade_no'];
- Db::startTrans();
- try{
- $orderModel = new \app\common\model\RecharOrder();
- $userModel = new \app\common\model\User();
- $orderInfo = $orderModel->where(["order_no"=>$out_trade_no])->find();
- $userInfo = $userModel->where(["id"=>$orderInfo["user_id"]])->find();
- $res1 = false;
- $res2 = false;
- $res3 = false;
- if($orderInfo['status'] == 0) {
- // 修改订单状态
- $res1 = $orderModel->update(["status"=>1,"updatetime"=>$time],["order_no"=>$out_trade_no, 'status' => 0]);
- // 充值后
- switch($orderInfo['purpose']) {
- case 1:
- // 修改用户为已缴纳认证费
- $userInfo->recharge_auth = 1;
- $res2 = $userInfo->save();
- $res3 = true;
- break;
- case 2:
- // 添加有眼缘记录--单次付费
- $data = [];
- $data['user_id'] = $userInfo->id;
- $data['fate_user_id'] = $orderInfo->fate_user_id;
- if(!\app\common\model\UserFate::where($data)->find()) {
- $data['createtime'] = $time;
- $res2 = \app\common\model\UserFate::insert($data);
- } else {
- $res2 = true;
- }
- // 返利
- $preuser_id = $userInfo->pre_user_id;
- if($userInfo->vip_duetime < $time) {
- $memo = '用户充值获得收益!';
- $profit = $payamount * config('site.userProfitRate') * 0.01;
- } else {
- $memo = '会员充值获得收益!';
- $profit = $payamount * config('site.vipProfitRate') * 0.01;
- }
- if($profit>=0.01 && $preuser_id > 0) {
- $res3 = \app\common\model\User::profit($profit,$preuser_id,$memo);
- } else {
- $res3 = true;
- }
- break;
- case 3:
- // 获取vip配置信息
- $vip_config_id = $orderInfo['vip_config_id'];
- $vipConfigInfo = \app\admin\model\vip\Config::where(['id'=>$vip_config_id])->find();
- // 计算vip到期时间
- if($userInfo->vip_duetime < $time) {
- $duetime = strtotime ( '+'.intval($vipConfigInfo['time']).' month' );
- } else {
- $duetime = strtotime ( '+'.intval($vipConfigInfo['time']).' month',$userInfo->vip_duetime);
- }
- // 修改用户为vip
- if($userInfo->vip_duetime <= time()) {
- $userInfo->view_count = $vipConfigInfo->give_times; // 今日剩余次数
- $userInfo->view_date = date('Y-m-d'); // 次数最后更新日期
- }
- $userInfo->vip_duetime = $duetime;
- $res2 = $userInfo->save();
- // 添加查看次数
- $data = [];
- $data['user_id'] = $userInfo->id;
- $data['end_date'] = date("Y-m-d",$duetime);
- $data['times'] = $vipConfigInfo->give_times;
- $data['createtime'] = time();
- $res3 = \app\common\model\GiveFateLog::insert($data);
- break;
- case 4:
- // 获取钻石配置信息
- $vip_config_id = $orderInfo['vip_config_id'];
- $vipConfigInfo = Db::name('diamond')->where(['id'=>$vip_config_id])->find();
- //修改用户钻石余额
- $diamond = $userInfo['diamond'] + $vipConfigInfo['number'];
- $res2 = Db::name('user')->where(['id' => $userInfo['id'], 'diamond' => $userInfo['diamond']])->setField('diamond', $diamond);
- // 添加钻石明细
- $diamond_log = Db::name('user_diamond_log')->where(['user_id' => $userInfo['id']])->order('id', 'desc')->find();
- if (!$diamond_log && $userInfo['diamond'] > 0) {
- $res3 = false;
- break;
- }
- if ($diamond_log && $diamond_log['after'] != $userInfo['diamond']) {
- $res3 = false;
- break;
- }
- $data = [];
- $data['user_id'] = $userInfo['id'];
- $data['diamond'] = $vipConfigInfo['number'];
- $data['before'] = $userInfo['diamond'];
- $data['after'] = $diamond;
- $data['memo'] = '充值';
- $data['createtime'] = time();
- $res3 = Db::name('user_diamond_log')->insertGetId($data);
- break;
- }
- }
- if($res1 && $res2 !== false && $res3) {
- Db::commit();
- } else {
- Db::rollback();
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- //你可以在此编写订单逻辑
- } catch (Exception $e) {
- }
- echo $pay->success();
- }
- //自动取消超时未支付的活动订单
- public function cancelorder() {
- set_time_limit(0);
- $where = array(
- 'status' => 0,
- 'createtime' => ['lt', time() - 1920], //32分钟之前
- );
- $active_order = Db::name('active_order');
- $list = $active_order->where($where)->limit(200)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $active_people = Db::name('active_people');
- $active_people_modify = Db::name('active_people_modify');
- $active = Db::name('active');
- foreach ($list as &$v) {
- //开启事务
- Db::startTrans();
- //修改订单信息
- $rs = $active_order->where(['id' => $v['id'], 'status' => 0])->setField('status', 3);
- if (!$rs) {
- Db::rollback();
- continue;
- }
- //修改活动人员
- $rt = $active_people->where(['order_id' => $v['id'], 'status' => 0])->setField(['status' => 3, 'modifystatus' => 0]);
- if (!$rt) {
- Db::rollback();
- continue;
- }
- //修改活动人员修改记录
- $res = $active_people_modify->where(['order_id' => $v['id'], 'status' => 0])->setField('status', 2);
- if ($res === false) {
- Db::rollback();
- continue;
- }
- //减少活动已报名人数
- $active_info = $active->find($v['active_id']);
- $currentperson = $active_info['currentperson'] - $v['number'];
- $active_rs = $active->where(['id' => $v['active_id'], 'currentperson' => $active_info['currentperson']])->setField('currentperson', $currentperson);
- if (!$active_rs) {
- Db::rollback();
- continue;
- }
- Db::commit();
- }
- echo 'wan bi';
- die;
- }
- //消息推送 我报名参加活动的前一天会提前推送消息,时间 地点 及一些提醒
- public function sysmsg() {
- set_time_limit(0);
- $where = array(
- 'starttime' => ['elt', time() + 86400], //活动开始前一天
- 'msgstatus' => 0,
- 'status' => ['neq', 3]
- );
- $active = Db::name('active');
- $list = $active->where($where)->limit(200)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $active_order = Db::name('active_order');
- $sys_msg = Db::name('sys_msg'); //系统消息
- $data['type'] = 1;
- $data['title'] = '活动通知';
- $data['createtime'] = time();
- foreach ($list as &$v) {
- //修改活动消息通知状态
- $active->where(['id' => $v['id']])->setField('msgstatus', 1);
- //发送通知
- $data['content'] = '您报名的' . $v['title'] . '活动即将开始,请规划好您的时间。活动集合时间:' . date('Y-m-d H:i', $v['collectiontime']) . ',活动集合地点:' . $v['collectionplace'];
- //查询报名用户id
- $user_ids = $active_order->where(['active_id' => $v['id'], 'status' => 1])->column('user_id');
- if ($user_ids) {
- foreach ($user_ids as &$va) {
- $data['user_id'] = $va;
- $sys_msg->insertGetId($data);
- }
- }
- }
- echo 'wan bi';
- die;
- }
- //每年1月1重置免费次数
- public function resetfreenumber() {
- set_time_limit(0);
- //每年开始时间
- $time = strtotime(date('Y-1-1 0:0:0', time()));
- $where = array(
- 'freenumbertime' => ['lt', $time]
- );
- $user = Db::name('user');
- $list = $user->where($where)->limit(200)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $vip = Db::name('vip');
- foreach ($list as &$v) {
- $free = $vip->find($v['growthlevel']);
- $user->where(['id' => $v['id'], 'freenumber' => $v['freenumber']])->setField(['freenumber' => $free['free'], 'freenumbertime' => time()]);
- }
- echo 'wan bi';
- die;
- }
-
- //自动结束已完成订单
- public function finishorder() {
- set_time_limit(0);
- $where = array(
- 'status' => 1,
- 'endtime' => ['lt', time()]
- );
- $active = Db::name('active');
- $list = $active->where($where)->limit(100)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $active_order = Db::name('active_order');
- $active_people = Db::name('active_people');
- $active_people_modify = Db::name('active_people_modify');
- $active_refund = Db::name('active_refund');
- foreach ($list as &$v) {
- //开启事务
- Db::startTrans();
- //活动结束
- $active_rs = $active->where(['id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'updatetime' => time()]);
- if (!$active_rs) {
- Db::rollback();
- continue;
- }
- //修改活动订单状态
- $order_rs = $active_order->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'updatetime' => time()]);
- if ($order_rs === false) {
- Db::rollback();
- continue;
- }
- //修改活动人员状态
- $people_rs = $active_people->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'modifystatus' => 0, 'updatetime' => time()]);
- if ($people_rs === false) {
- Db::rollback();
- continue;
- }
- //修改活动人员信息修改表
- $people_modify_rs = $active_people_modify->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
- if ($people_modify_rs === false) {
- Db::rollback();
- continue;
- }
- //修改活动申请取消表
- $refund_rs = $active_refund->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
- if ($refund_rs === false) {
- Db::rollback();
- continue;
- }
- Db::commit();
- }
- echo 'wan bi';
- die;
- }
-
- //自动取消未成行订单
- public function cancelminpeopleorder() {
- set_time_limit(0);
- $where = array(
- 'status' => 0,
- 'signupendtime' => ['lt', time()]
- );
- $active = Db::name('active');
- $list = $active->where($where)->limit(100)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $active_order = Db::name('active_order');
- $active_people = Db::name('active_people');
- $active_people_modify = Db::name('active_people_modify');
- $active_refund = Db::name('active_refund');
- $user_coupon = Db::name('user_coupon'); //用户优惠券表
- $sys_msg = Db::name('sys_msg'); //消息通知
- foreach ($list as &$v) {
- //开启事务
- Db::startTrans();
- //活动结束
- $active_rs = $active->where(['id' => $v['id'], 'status' => 0])->setField(['status' => 3, 'updatetime' => time()]);
- if (!$active_rs) {
- Db::rollback();
- continue;
- }
- //修改活动人员状态
- $people_rs = $active_people->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 3, 'modifystatus' => 0, 'updatetime' => time()]);
- if ($people_rs === false) {
- Db::rollback();
- continue;
- }
- //修改活动人员信息修改表
- $people_modify_rs = $active_people_modify->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
- if ($people_modify_rs === false) {
- Db::rollback();
- continue;
- }
- //修改活动申请取消表
- $refund_rs = $active_refund->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
- if ($refund_rs === false) {
- Db::rollback();
- continue;
- }
- //查询活动订单
- $active_order_list = $active_order->where(['active_id' => $v['id'], 'status' => 1])->select();
- if ($active_order_list) {
- //活动订单修改信息
- $order_data['status'] = 3; //状态:0=待付款,1=待出行,2=已完成,3=已取消
- $order_data['updatetime'] = time();
- foreach ($active_order_list as &$vv) {
- //退还支付金额
- if ($vv['price'] > 0) {
- $order_data['refundstatus'] = 1; //退款状态:0=无需退款,1=退款成功,2=退款失败
- $order_data['refundprice'] = $vv['price'];//退款金额
- $order_data['refundtime'] = time();
- if ($vv['paytype'] == 0) {
- //余额支付, 退回余额
- $rs = create_log($vv['price'], '活动取消返还', $vv['user_id'], 3, $vv['id']);
- if ($rs != 1) {
- $order_data['refundstatus'] = 2;
- }
- } elseif ($vv['paytype'] == 1) {
- //微信支付, 退回微信
- //扣除用户成长值
- $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
- $balance = floor($paygrowth * $vv['price']);
- if ($balance > 0) {
- $paygrowth_rs = create_growth_log(-$balance, '活动取消扣除', $vv['user_id'], 4, $vv['id']);
- }
- //退款单号
- $order_data['refund_no'] = $vv['order_sn'];
- //调用微信退款
- $wxData['transaction_id'] = $vv['transaction_id'];
- $wxData['out_refund_no'] = $order_data['refund_no'];
- $wxData['total_fee'] = (int)($vv['price'] * 100);//1 微信支付 单位为分
- $wxData['refund_fee'] = (int)($vv['price'] * 100);//1 微信支付 单位为分
- $wxData['refund_desc'] = '活动取消返还';
- // require_once("Plugins/WxPay/WxPay.php");
- $wxPay = new wxpay\WxPay(config('wxchatpay'));
- $back = $wxPay->WxPayRefund($wxData);
- if($back['return_code'] != 'SUCCESS' || $back['result_code'] != 'SUCCESS') {
- $order_data['refundstatus'] = 2;
- }
- }
- }
- //修改活动订单状态
- $order_rs = $active_order->where(['id' => $vv['id'], 'status' => 1])->setField($order_data);
- if ($order_rs === false) {
- Db::rollback();
- continue;
- }
- //上级优惠券设为过期
- $user_coupon->where(['active_id' => $vv['id'], 'status' => 0])->setField('endtime', time() - 1);
- //发送消息
- $data = [
- 'user_id' => $vv['user_id'],
- 'type' => 1,
- 'title' => '活动通知',
- 'content' => '您报名的' . $v['title'] . '活动已取消',
- 'createtime' => time()
- ];
- $sys_msg->insertGetId($data);
- }
- }
- Db::commit();
- }
- echo 'wan bi';
- die;
- }
- //自动上架活动
- public function showactive() {
- set_time_limit(0);
- $time = time();
- $where = array(
- 'showstatus' => 0,
- 'is_autoshow' => 1,
- 'showtime' => ['elt', $time]
- );
- $active = Db::name('active');
- $list = $active->where($where)->limit(200)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- foreach ($list as &$v) {
- $active->where(['id' => $v['id'], 'showstatus' => 0])->setField(['showstatus' => 1]);
- }
- echo 'wan bi';
- die;
- }
- //视频转码
- public function transcode() {
- set_time_limit(0);
- $where = array(
- 'transcode_status' => 0
- );
- $hu_video = Db::name('video');
- $list = $hu_video->where($where)->limit(50)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $url = 'http://api.trans.gitv.tv/upload';
- $data['cp_id'] = config('cp_id');
- $data['media_type'] = 'mp4';
- foreach ($list as &$v) {
- $data['uri'] = urlencode(config('upload.cdnurl') . $v['videofile']);
- $data['file_name'] = urlencode($v['title']);
- $request_url = $url . '?' . http_build_query($data);
- $rs = file_get_contents($request_url);
- if (!$rs) {
- continue;
- }
- $rs = json_decode($rs);
- if ($rs['code'] == 'A000000') {
- $hu_video->where(['id' => $v['id'], 'transcode_status' => 0])->setField(['transcode_status' => 1, 'task_id' => $rs['task_id']]);
- }
- }
- echo 'wan bi';
- die;
- }
- //视频转码回执
- public function transcodecallback() {
- $cp_id = input('cp_id', 0, 'intval');
- $file_url = input('file_url', '', 'trim');
- $task_id = input('task_id', '', 'trim');
- if ($cp_id != config('cp_id')) {
- $this->error('错误1');
- }
- $info = Db::name('video')->where(['task_id' => $task_id])->find();
- if (!$info) {
- $this->error('错误2');
- }
- if ($info['transcode_status'] != 1) {
- $this->success('已完成');
- }
- $file_url = urldecode($file_url);
- $rs = Db::name('video')->where(['id' => $info['id'], 'transcode_status' => 1])->setField(['transcode_status' => 2, 'file_url' => $file_url]);
- if (!$rs) {
- $this->error('失败');
- }
- $this->success('成功');
- }
- //视频注入
- public function inject() {
- set_time_limit(0);
- $where = array(
- 'transcode_status' => 2,
- 'inject_status' => 0
- );
- $hu_video = Db::name('video');
- $list = $hu_video->where($where)->limit(50)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $url = 'http://api.gs.gitv.tv/upload';
- $data['cp_id'] = config('cp_id');
- $data['bit_id'] = 5;
- $data['file_type'] = 'm3u8';
- foreach ($list as &$v) {
- $data['album_id'] = (string)$v['id'];
- $data['video_id'] = (string)$v['id'];
- $data['uri'] = $v['file_url'];
- $rs = httpRequest($url, 'POST', $data);
- if (!$rs) {
- continue;
- }
- $rs = json_decode($rs);
- if ($rs['code'] == 'A000000') {
- $hu_video->where(['id' => $v['id'], 'inject_status' => 0])->setField(['inject_status' => 1]);
- }
- }
- echo 'wan bi';
- die;
- }
- //视频注入回执
- public function injectcallback() {
- $cp_id = input('cp_id', 0, 'intval');
- $album_id = input('album_id', '', 'trim'); //专辑 ID
- $video_id = input('video_id', '', 'trim'); //剧集 ID
- $code = input('code', '', 'trim'); //状态码
- if ($cp_id != config('cp_id')) {
- $this->error('错误1');
- }
- $info = Db::name('video')->where(['id' => $video_id])->find();
- if (!$info) {
- $this->error('错误2');
- }
- if ($info['inject_status'] != 1) {
- $this->success('已完成');
- }
- if ($code == 'A000000') {
- $inject_status = 2;
- } else {
- $inject_status = 3;
- }
- $rs = Db::name('video')->where(['id' => $info['id'], 'inject_status' => 1])->setField(['inject_status' => $inject_status]);
- if (!$rs) {
- $this->error('失败');
- }
- $this->success('成功');
- }
- //视频注入结果查询
- public function injectquery() {
- set_time_limit(0);
- $time = strtotime(date('Y-m-d', time()));
- $where = array(
- 'inject_status' => 1,
- // 'updatetime' => ['egt', $time]
- );
- $hu_video = Db::name('video');
- // $list = $hu_video->where($where)->count('id');
- $list = $hu_video->where($where)->limit(50)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- /*$starttime = date('Ymd000000', time());
- $endtime = date('Ymd235959', time());
- // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/injectResult/v1/queryAdd?cspId=' . config('cspid') . '&startTime='.$starttime.'&endTime='.$endtime;
- $url = 'http://jscp.agency.gitv.tv/injectResult/v1/queryAdd?cspId=' . config('cspid') . '&startTime='.$starttime.'&endTime='.$endtime;
- $header = [
- 'Content-Type: application/json'
- ];
- $rs = httpRequest($url, 'POST', [], $header);
- if (!$rs) {
- echo 'cuo wu1';
- die;
- }
- $list = json_decode($rs, true);
- if ($list['code'] != 'A000000') {
- echo 'cuo wu2';
- die;
- }
- foreach ($list['data'] as &$v) {
- if ($v['taskStatus'] == 2) {
- $hu_video->where(['id' => $v['cpTvId'], 'inject_status' => 1])->setField(['inject_status' => 2]);
- }
- }*/
- $header = [
- 'Content-Type: application/json'
- ];
- //生成ftp文件
- $content = [
- 'cpPrvdName' => '健康e家',
- 'cpPrvCode' => '41000144',
- 'cpPrvType' => '1006',
- 'ChnName' => '健康',
- 'ChnCode' => '1000020',
- 'actors' => '无',
- 'directors' => '无',
- 'contentYear' => date('Y'),
- 'tags' => '',
- 'contentTime' => date('Y-m-d H:i:s'),
- 'formatType' => '超清'
- ];
- //增量接口
- $insert_url = 'http://test.meta.unso.gitv.tv/sendMeta';
- $method = 'POST';
- foreach ($list as &$v) {
- //查询华为注入结果
- $url = 'http://jscp.agency.gitv.tv/injectResult/v1/queryTv?cspId=' . config('cspid') . '&cpAlbumId=' . $v['id'] . '&cpTvId=' . $v['id'];
- $rs = httpRequest($url, 'GET', [], $header);
- if (!$rs) {
- continue;
- }
- $rs = json_decode($rs, true);
- if ($rs['code'] != 'A000000') {
- continue;
- }
- $data = $rs['data'][0];
- if ($data['taskStatus'] == 2) {
- /*//生成ftp文件
- $content['contentId'] = $v['movieid'];
- $content['extraContentID'] = $v['movieid'];
- $content['content'] = $v['title'];
- $content['intent'] = [
- 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
- ],
- 'extras' => [
- // 'cmd' => '',
- // 'from' => '',
- // 'media_id' => ''
- 'type_id' => $v['video_type_id'],
- 'id' => $v['id']
- ]
- ];
- $content['isEffective'] = $v['status'];
- $content['pic'] = one_domain_image($v['image']);
- $content['isPaid'] = $v['is_pay'];
- $content = json_encode($content, 320);
- $filename = 'shipin_'.date('Ymd').'_'.date('His').'_increment'.'.json';
- error_log(print_r($content, 1) . PHP_EOL, 3, './jiankang/' . $filename);
- //调用增量注入接口
- $postfields = [
- 'priKey' => config('cspid'),
- 'data' => [$content]
- ];
- $rt = httpRequest($insert_url, $method, $postfields, $header);
- if (!$rt) {
- continue;
- }
- $rt = json_decode($rt, true);
- if ($rt['code'] != 'A000000') {
- continue;
- }*/
- //查询中兴注入结果
- $url2 = 'http://jscp.agency.gitv.tv/injectResult/v1/queryTv?cspId=' . config('cspid_zx') . '&cpAlbumId=' . $v['id'] . '&cpTvId=' . $v['id'];
- $rs2 = httpRequest($url2, 'GET', [], $header);
- if (!$rs2) {
- continue;
- }
- $rs2 = json_decode($rs2, true);
- if ($rs2['code'] != 'A000000') {
- continue;
- }
- $data2 = $rs2['data'][0];
- if ($data2['taskStatus'] == 2) {
- $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 2, 'seriesid' => $data['seriesId'], 'programid' => $data['programId'], 'movieid' => $data['movieId']]);
- } elseif ($data2['taskStatus'] == -1 || $data2['taskStatus'] == -3 || $data2['taskStatus'] == -4) {
- $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 3, 'seriesid' => $data['seriesId'], 'programid' => $data['programId'], 'movieid' => $data['movieId']]);
- }
- } elseif ($data['taskStatus'] == -1 || $data['taskStatus'] == -3 || $data['taskStatus'] == -4) {
- $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 3, 'seriesid' => $data['seriesId'], 'programid' => $data['programId'], 'movieid' => $data['movieId']]);
- }
- }
- echo 'wan bi';
- die;
- }
- //视频统一搜索生成ftp文件
- public function videosearch() {
- set_time_limit(0);
- // $time = strtotime(date('Y-m-d', time()));
- $where = array(
- 'inject_status' => 2,
- 'search_status' => 0,
- // 'updatetime' => ['egt', $time]
- );
- $hu_video = Db::name('video');
- $list = $hu_video->where($where)->limit(50)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $header = [
- 'Content-Type: application/json'
- ];
- //生成ftp文件
- $data_content = [
- 'cpPrvdName' => '健康e家',
- 'cpPrvCode' => '41000144',
- 'cpPrvType' => '1006',
- 'ChnName' => '健康',
- 'ChnCode' => '1000020',
- 'actors' => '无',
- 'directors' => '无',
- 'contentYear' => date('Y'),
- 'tags' => '',
- 'contentTime' => date('Y-m-d H:i:s'),
- 'formatType' => '超清'
- ];
- //增量接口
- $insert_url = 'http://test.meta.unso.gitv.tv/sendMeta';
- $method = 'POST';
- foreach ($list as &$v) {
- //生成ftp文件
- $content = $data_content;
- $content['contentId'] = $v['movieid'];
- $content['extraContentID'] = $v['movieid'];
- $content['content'] = $v['title'];
- $intent = json_encode([
- 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
- ],
- 'extras' => [
- // 'cmd' => '',
- // 'from' => '',
- // 'media_id' => ''
- 'type_id' => $v['video_type_id'],
- 'id' => $v['id']
- ]
- ], 320);
- $content['intent'] = "$intent";
- $content['isEffective'] = $v['status'];
- $content['pic'] = one_domain_image($v['image']);
- $content['isPaid'] = $v['is_pay'];
- $content = json_encode($content, 320);
- $filename = 'shipin_'.date('Ymd').'_'.date('His').'_increment'.'.json';
- error_log(print_r($content, 1) . PHP_EOL, 3, './jiankang/' . $filename);
- //调用增量注入接口
- /*$postfields = [
- 'priKey' => config('cspid'),
- 'data' => [$content]
- ];
- $rt = httpRequest($insert_url, $method, $postfields, $header);
- if (!$rt) {
- continue;
- }
- $rt = json_decode($rt, true);
- if ($rt['code'] != 'A000000') {
- continue;
- }*/
- $hu_video->where(['id' => $v['id'], 'search_status' => 0])->setField(['search_status' => 1]);
- }
- echo 'wan bi';
- die;
- }
-
- //订购关系同步地址
- public function ordersync() {
- $data = file_get_contents('php://input');
- file_put_contents('chen_tui.txt', $data, FILE_APPEND);
- if (!$data) {
- $this->error('参数缺失');
- }
- $jsonxml = json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA));
- $data = json_decode($jsonxml, true);
- if (!$data) {
- $this->error('参数缺失');
- }
- $phoneNumber = $data['orderRelationSyncRequest']['phoneNumber']; //手机号
- $apppId = $data['orderRelationSyncRequest']['apppId']; //订购的HDC业务产品编码
- if ($apppId != config('product_code')) {
- echo 'meiyou';
- exit;
- }
- //用户增值产品包当前订购快照
- $content = [
- 'UserID' => $phoneNumber,
- 'prod_code' => $apppId,
- 'prod_name' => '月包会员',
- 'eff_time' => date('Y-m-d H:i:s', time()),
- 'exp_time' => date('Y-m-d H:i:s', time() + 30 * 86400),
- 'price' => 2900
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_userefforderdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_userefforderdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userefforderdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- //用户增值产品包订购行为数据
- $user_id = Db::name('user')->where(['mobile' => $phoneNumber])->value('id');
- $order_info = Db::name('rechar_order')->where(['user_id' => $user_id, 'purpose' => 3, 'pay_type' => 'zhuowang', 'status' => 1])->order('id desc')->find();
- $content = [
- 'orderid' => $order_info['order_no'],
- 'order_time' => date('Y-m-d H:i:s', time()),
- 'order_type' => 1,
- 'UserID' => $phoneNumber,
- 'prod_code' => $apppId,
- 'prod_name' => '月包会员',
- 'eff_time' => date('Y-m-d H:i:s', time()),
- 'exp_time' => date('Y-m-d H:i:s', time() + 30 * 86400),
- 'csource' => 99,
- 'trace_id' => '',
- 'price' => 2900,
- 'paytype' => 0,
- 'cpid' => config('data_cp_id'),
- 'albumid' => '',
- 'albumname' => ''
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_userorderdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_userorderdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userorderdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- }
- //(补漏)视频注入中兴
- public function injectzx() {
- set_time_limit(0);
- $hu_video = Db::name('video');
- $list = $hu_video->where(['id' => 107])->limit(50)->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $cspid = config('cspid_zx');
- $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
- foreach ($list as &$params) {
- //内容同步
- $videofile = $params['videofile'];
- $videofile = explode('/', $videofile);
- $video_url = $videofile[3];
- $data = [
- // 'cspId' => $cspid,
- 'cpAlbumId' => $params['id'],
- 'albumName' => $params['title'],
- 'tvSets' => 1,
- 'updateToSet' => 1,
- 'isPurchase' => $params['is_pay'],
- 'isEffective' => $params['status'],
- 'isOnline' => $params['status'],
- 'albumTypes' => '健康',
- 'picBox' => config('upload.cdnurl') . $params['image'],
- 'albumUpdateTime' => date('YmdHis', time()),
- 'albumCreateTime' => date('YmdHis', time()),
- 'tvlist' => [
- [
- 'cpAlbumId' => $params['id'],
- 'cpTvId' => $params['id'],
- 'tvName' => $params['title'],
- 'tvIsEffective' => $params['status'],
- 'tvIsOnline' => $params['status'],
- 'isPurchase' => $params['is_pay'],
- 'playOrder' => 1,
- 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
- ]
- ]
- ];
- $data = json_encode($data, 320);
- $header = [
- 'Content-Type: application/json'
- ];
- $rs = httpRequest($url, 'POST', $data, $header);
- if ($rs) {
- $rs = json_decode($rs, true);
- if ($rs['code'] != 'A000000') {
- continue;
- }
- }
- }
- echo 'wan bi';
- die;
- }
- //(补漏)删除注入中兴视频
- public function delinjectzx() {
- set_time_limit(0);
- $hu_video = Db::name('video');
- $list = $hu_video->where(['id' => 107])->limit(1)->order('id')->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- $cspid = config('cspid_zx');
- $url = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . $cspid . '/';
- foreach ($list as &$params) {
- //内容同步
- $videofile = $params['videofile'];
- $videofile = explode('/', $videofile);
- $video_url = $videofile[3];
- $data = [
- // 'cspId' => $cspid,
- 'cpAlbumId' => $params['id'],
- 'albumName' => $params['title'],
- 'tvSets' => 1,
- 'updateToSet' => 1,
- 'isPurchase' => $params['is_pay'],
- 'isEffective' => 0,
- 'isOnline' => 2,
- 'albumTypes' => '健康',
- 'picBox' => config('upload.cdnurl') . $params['image'],
- 'albumUpdateTime' => date('YmdHis', time()),
- // 'albumCreateTime' => date('YmdHis', time()),
- 'tvlist' => [
- [
- 'cpAlbumId' => $params['id'],
- 'cpTvId' => $params['id'],
- 'tvName' => $params['title'],
- 'tvIsEffective' => 0,
- 'tvIsOnline' => 2,
- 'isPurchase' => $params['is_pay'],
- 'playOrder' => 1,
- 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
- ]
- ]
- ];
- $data = json_encode($data, 320);
- $header = [
- 'Content-Type: application/json'
- ];
- $rs = httpRequest($url, 'POST', $data, $header);
- if ($rs) {
- $rs = json_decode($rs, true);
- if ($rs['code'] != 'A000000') {
- continue;
- }
- }
- }
- echo 'wan bi';
- die;
- }
- //媒资数据专辑粒度
- public function mediadataalbum() {
- $hu_video = Db::name('video');
- $list = $hu_video->where(['inject_status' => 2, 'mediaalbum_status' => 0])->order('id')->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- foreach ($list as $key => &$param) {
- $content = [
- 'Updatetype' => 1,
- 'cpid' => config('data_cp_id'),
- 'channelid' => '1000035',
- 'albumid' => $param['id'],
- 'albumname' => $param['title'],
- 'albumnum' => 1,
- 'tag' => '',
- 'onlinetime' => '',
- 'bref' => '',
- 'onebref' => '',
- 'cornersign' => $param['is_pay'],
- 'director' => '',
- 'actor' => '',
- 'year' => '',
- 'area' => '',
- 'language' => '',
- 'score' => '',
- 'picurl' => config('upload.cdnurl') . $param['image'],
- 'picurl_v' => '',
- 'gotourl' => json_encode([
- 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
- ],
- 'extras' => [
- // 'cmd' => '',
- // 'from' => '',
- // 'media_id' => ''
- 'type_id' => $param['video_type_id'],
- 'id' => $param['id']
- ]
- ], 320),
- 'is_politics' => '',
- 'second_type' => ''
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_albumsdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_albumsdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- if ($key == count($list) - 1) {
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_albumsdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- }
- $hu_video->where(['id' => $param['id'], 'mediaalbum_status' => 0])->setField('mediaalbum_status', 1);
- }
- echo 'wan bi';
- }
- //媒资数据节目/内容粒度
- public function mediadatavideo() {
- $hu_video = Db::name('video');
- $list = $hu_video->where(['inject_status' => 2, 'mediavideo_status' => 0])->order('id')->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- foreach ($list as $key => &$param) {
- $content = [
- 'Updatetype' => 1,
- 'cpid' => config('data_cp_id'),
- 'channelid' => '1000035',
- 'albumid' => $param['id'],
- 'albumname' => $param['title'],
- 'videoid' => $param['id'],
- 'videoname' => $param['title'],
- 'videonum' => 1,
- 'Contenttype' => 1,
- 'duration' => '',
- 'quality' => ''
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_videosdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_videosdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- if ($key == count($list) - 1) {
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_videosdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- }
- $hu_video->where(['id' => $param['id'], 'mediavideo_status' => 0])->setField('mediavideo_status', 1);
- }
- }
- //产品包
- public function product() {
- $content = [
- 'prod_code' => config('product_code'),
- 'prod_name' => '月包会员',
- 'prod_type' => 0,
- 'cpid' => config('data_cp_id')
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_productsdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_productsdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_productsdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- //连接ftp
- $host = config('data_ftp_ip');
- $port = config('data_ftp_port');
- $username = config('data_ftp_user');
- $password = config('data_ftp_pwd');
- $conn = ftp_connect($host, $port) or die("Could not connect");
- //登录
- ftp_login($conn,$username,$password);
- //开启被动模式
- ftp_pasv($conn, true);
- //利用ftp创建目录
- /*$path = "home/2021-12-08";
- $this->make_directory($conn,$path);
- //利用ftp选择进入目录
- ftp_chdir($conn,$path);*/
- //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
- if(ftp_put($conn,$filename,'./dashuju/' . $filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$check_filename,'./dashuju/' . $check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$finish_filename,'./dashuju/' . $finish_filename,FTP_BINARY)){
- //上传成功
- }
- ftp_close($conn);
- //注意上传端的ftp权限设置
- echo 'wanbi';
- }
- //产品包和媒资所属关系
- public function productmediarelation() {
- $hu_video = Db::name('video');
- $list = $hu_video->where(['inject_status' => 2, 'productmedia_status' => 0])->order('id')->select();
- if (!$list) {
- echo 'mei shu ju';
- die;
- }
- foreach ($list as $key => &$param) {
- $content = [
- 'Updatetype' => 1,
- 'prod_code' => config('product_code'),
- 'cpid' => config('data_cp_id'),
- 'albumid' => $param['id']
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_productalbumdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_productalbumdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- if ($key == count($list) - 1) {
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_productalbumdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- }
- $hu_video->where(['id' => $param['id'], 'productmedia_status' => 0])->setField('productmedia_status', 1);
- }
- }
- //用户观看行为数据文件上传到卓望ftp(每小时第10分钟提供)
- public function uploadpayftp() {
- set_time_limit(0);
- $host = config('pay_ftp_ip');
- $port = config('pay_ftp_port');
- $username = config('pay_ftp_user');
- $password = config('pay_ftp_pwd');
- $filename = date('YmdH', time() - 3600).'_'.config('cp_id').'_userviewdata_1.dat';
- $check_filename = date('YmdH', time() - 3600).'_'.config('cp_id').'_userviewdata_1.chk';
- //判断文件是否存在, 不存在则创建
- if (!file_exists('./dashuju/' . $filename)) {
- @touch('./dashuju/' . $filename);
- }
- if (!file_exists('./dashuju/' . $check_filename)) {
- @touch('./dashuju/' . $check_filename);
- }
- //连接ftp
- $conn = ftp_connect($host, $port) or die("Could not connect");
- //登录
- ftp_login($conn,$username,$password);
- //开启被动模式
- ftp_pasv($conn, true);
- //利用ftp创建目录
- /*$path = "home/2021-12-08";
- $this->make_directory($conn,$path);
- //利用ftp选择进入目录
- ftp_chdir($conn,$path);*/
- //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
- if(ftp_put($conn,$filename,'./dashuju/' . $filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$check_filename,'./dashuju/' . $check_filename,FTP_BINARY)){
- //上传成功
- }
- ftp_close($conn);
- //注意上传端的ftp权限设置
- echo 'wanbi';
- }
- //大数据文件上传到大数据ftp(每天一点提供)
- public function uploaddataftp() {
- set_time_limit(0);
- $host = config('data_ftp_ip');
- $port = config('data_ftp_port');
- $username = config('data_ftp_user');
- $password = config('data_ftp_pwd');
- $time = date('Ymd', time() - 86400);
- // 专辑粒度媒资
- $albumsdata_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.dat';
- $albumsdata_check_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.chk';
- $albumsdata_finish_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.finish';
- // 节目/内容粒度媒资
- $videosdata_filename = $time.'_'.config('data_cp_id').'_videosdata_1.dat';
- $videosdata_check_filename = $time.'_'.config('data_cp_id').'_videosdata_1.chk';
- $videosdata_finish_filename = $time.'_'.config('data_cp_id').'_videosdata_1.finish';
- // 产品包和媒资所属关系
- $productalbumdata_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.dat';
- $productalbumdata_check_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.chk';
- $productalbumdata_finish_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.finish';
- // 用户增值产品包当前订购快照
- $userefforderdata_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.dat';
- $userefforderdata_check_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.chk';
- $userefforderdata_finish_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.finish';
- // 用户增值产品包订购行为
- $userorderdata_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.dat';
- $userorderdata_check_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.chk';
- $userorderdata_finish_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.finish';
- // 用户观看行为
- $userplaydata_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.dat';
- $userplaydata_check_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.chk';
- $userplaydata_finish_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.finish';
- // 用户收藏行为
- $userfavdata_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.dat';
- $userfavdata_check_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.chk';
- $userfavdata_finish_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.finish';
- //判断文件是否存在, 不存在则创建
- if (!file_exists('./dashuju/' . $albumsdata_filename)) {
- @touch('./dashuju/' . $albumsdata_filename);
- }
- if (!file_exists('./dashuju/' . $albumsdata_check_filename)) {
- @touch('./dashuju/' . $albumsdata_check_filename);
- }
- if (!file_exists('./dashuju/' . $albumsdata_finish_filename)) {
- @touch('./dashuju/' . $albumsdata_finish_filename);
- }
- if (!file_exists('./dashuju/' . $videosdata_filename)) {
- @touch('./dashuju/' . $videosdata_filename);
- }
- if (!file_exists('./dashuju/' . $videosdata_check_filename)) {
- @touch('./dashuju/' . $videosdata_check_filename);
- }
- if (!file_exists('./dashuju/' . $videosdata_finish_filename)) {
- @touch('./dashuju/' . $videosdata_finish_filename);
- }
- if (!file_exists('./dashuju/' . $productalbumdata_filename)) {
- @touch('./dashuju/' . $productalbumdata_filename);
- }
- if (!file_exists('./dashuju/' . $productalbumdata_check_filename)) {
- @touch('./dashuju/' . $productalbumdata_check_filename);
- }
- if (!file_exists('./dashuju/' . $productalbumdata_finish_filename)) {
- @touch('./dashuju/' . $productalbumdata_finish_filename);
- }
- if (!file_exists('./dashuju/' . $userefforderdata_filename)) {
- @touch('./dashuju/' . $userefforderdata_filename);
- }
- if (!file_exists('./dashuju/' . $userefforderdata_check_filename)) {
- @touch('./dashuju/' . $userefforderdata_check_filename);
- }
- if (!file_exists('./dashuju/' . $userefforderdata_finish_filename)) {
- @touch('./dashuju/' . $userefforderdata_finish_filename);
- }
- if (!file_exists('./dashuju/' . $userorderdata_filename)) {
- @touch('./dashuju/' . $userorderdata_filename);
- }
- if (!file_exists('./dashuju/' . $userorderdata_check_filename)) {
- @touch('./dashuju/' . $userorderdata_check_filename);
- }
- if (!file_exists('./dashuju/' . $userorderdata_finish_filename)) {
- @touch('./dashuju/' . $userorderdata_finish_filename);
- }
- if (!file_exists('./dashuju/' . $userplaydata_filename)) {
- @touch('./dashuju/' . $userplaydata_filename);
- }
- if (!file_exists('./dashuju/' . $userplaydata_check_filename)) {
- @touch('./dashuju/' . $userplaydata_check_filename);
- }
- if (!file_exists('./dashuju/' . $userplaydata_finish_filename)) {
- @touch('./dashuju/' . $userplaydata_finish_filename);
- }
- if (!file_exists('./dashuju/' . $userfavdata_filename)) {
- @touch('./dashuju/' . $userfavdata_filename);
- }
- if (!file_exists('./dashuju/' . $userfavdata_check_filename)) {
- @touch('./dashuju/' . $userfavdata_check_filename);
- }
- if (!file_exists('./dashuju/' . $userfavdata_finish_filename)) {
- @touch('./dashuju/' . $userfavdata_finish_filename);
- }
- //连接ftp
- $conn = ftp_connect($host, $port) or die("Could not connect");
- //登录
- ftp_login($conn,$username,$password);
- //开启被动模式
- ftp_pasv($conn, true);
- //利用ftp创建目录
- /*$path = "home/2021-12-08";
- $this->make_directory($conn,$path);
- //利用ftp选择进入目录
- ftp_chdir($conn,$path);*/
- //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
- if(ftp_put($conn,$albumsdata_filename,'./dashuju/' . $albumsdata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$albumsdata_check_filename,'./dashuju/' . $albumsdata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$albumsdata_finish_filename,'./dashuju/' . $albumsdata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$videosdata_filename,'./dashuju/' . $videosdata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$videosdata_check_filename,'./dashuju/' . $videosdata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$videosdata_finish_filename,'./dashuju/' . $videosdata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$productalbumdata_filename,'./dashuju/' . $productalbumdata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$productalbumdata_check_filename,'./dashuju/' . $productalbumdata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$productalbumdata_finish_filename,'./dashuju/' . $productalbumdata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userefforderdata_filename,'./dashuju/' . $userefforderdata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userefforderdata_check_filename,'./dashuju/' . $userefforderdata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userefforderdata_finish_filename,'./dashuju/' . $userefforderdata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userorderdata_filename,'./dashuju/' . $userorderdata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userorderdata_check_filename,'./dashuju/' . $userorderdata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userorderdata_finish_filename,'./dashuju/' . $userorderdata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userplaydata_filename,'./dashuju/' . $userplaydata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userplaydata_check_filename,'./dashuju/' . $userplaydata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userplaydata_finish_filename,'./dashuju/' . $userplaydata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userfavdata_filename,'./dashuju/' . $userfavdata_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userfavdata_check_filename,'./dashuju/' . $userfavdata_check_filename,FTP_BINARY)){
- //上传成功
- }
- if(ftp_put($conn,$userfavdata_finish_filename,'./dashuju/' . $userfavdata_finish_filename,FTP_BINARY)){
- //上传成功
- }
- ftp_close($conn);
- //注意上传端的ftp权限设置
- echo 'wanbi';
- }
- public function make_directory($ftp_stream, $dir){
- // if directory already exists or can be immediately created return true
- if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true;
- // otherwise recursively try to make the directory
- if (!$this->make_directory($ftp_stream, dirname($dir))) return false;
- // final step to create the directory
- return ftp_mkdir($ftp_stream, $dir);
- }
- public function ftp_is_dir($ftp_stream, $dir){
- // get current directory
- $original_directory = ftp_pwd($ftp_stream);
- // test if you can change directory to $dir
- // suppress errors in case $dir is not a file or not a directory
- if ( @ftp_chdir( $ftp_stream, $dir ) ) {
- // If it is a directory, then change the directory back to the original directory
- ftp_chdir( $ftp_stream, $original_directory );
- return true;
- } else {
- return false;
- }
- }
- }
|