123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935 |
- <?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.video.detail.VideoDetailActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.video.detail.VideoDetailActivity'
- ],
- '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;
- }*/
- $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 2, '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文件
- $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['contentId'] = $v['movieid'];
- $content['extraContentID'] = $v['movieid'];
- $content['content'] = $v['title'];
- $content['intent'] = [
- 'action' => 'com.huxiu.heh.tv.ui.video.detail.VideoDetailActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.video.detail.VideoDetailActivity'
- ],
- '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;
- }*/
- $hu_video->where(['id' => $v['id'], 'search_status' => 0])->setField(['search_status' => 1]);
- }
- echo 'wan bi';
- die;
- }
- }
|