Notify.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use wxpay;
  6. use addons\epay\library\Service;
  7. /**
  8. * 支付回调
  9. */
  10. class Notify extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. // 支付回调
  15. public function notify() {
  16. // require_once($_SERVER['DOCUMENT_ROOT'] . "/Plugins/WxPay/WxPay.php");
  17. $wxPay = new wxpay\WxPay();
  18. //验证是否是微信发送
  19. $flag = $wxPay->WxPayNotifyCheck();
  20. // error_log(print_r($flag, 1), 3, 'post.txt');
  21. // LL($flag,'./log1.txt');
  22. //验证成功
  23. if ($flag['status']) {
  24. if ($flag['data']['return_code'] == 'SUCCESS' && $flag['data']['result_code'] == 'SUCCESS') {
  25. $total_fee = trim($flag['data']['total_fee']) / 100; //支付的金额, 单位:分转成元
  26. $order_sn = trim($flag['data']['out_trade_no']);//商家订单号
  27. $PayResult = Db::name('rechar_order');
  28. $where['order_no'] = $order_sn;
  29. $order_info = $PayResult->where($where)->find();
  30. if ($order_info['money'] != $total_fee) {
  31. $r_arr['return_code'] = 'FAIL';
  32. $r_arr['return_msg'] = '回调失败';
  33. echo $wxPay->arrayToXml($r_arr);
  34. die;
  35. }
  36. if ($order_info['status'] == 1) {
  37. $r_arr['return_code'] = 'SUCCESS';
  38. $r_arr['return_msg'] = '回调成功';
  39. echo $wxPay->arrayToXml($r_arr);
  40. die;
  41. }
  42. //构建支付订单处理结果信息
  43. $_data['transaction_id'] = trim($flag['data']['transaction_id']); //微信交易凭证
  44. $_data['status'] = 1;
  45. $_data['updatetime'] = time();
  46. //支付订单类型
  47. if ($order_info['purpose'] == 1) {
  48. //查询订单
  49. $active_order = Db::name('game_people')->find($order_info['relation_id']);
  50. //开启事务
  51. Db::startTrans();
  52. //修改报名状态
  53. $active_order_rs = Db::name('game_people')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
  54. //活动标题
  55. $active_title = Db::name('game')->where(['id' => $active_order['game_id']])->value('name');
  56. //发送消息
  57. $data = [
  58. 'user_id' => $order_info['user_id'],
  59. 'type' => 1,
  60. 'title' => '比赛通知',
  61. 'content' => '您已成功报名' . $active_title . '比赛',
  62. 'createtime' => time()
  63. ];
  64. $sys_rs = Db::name('sys_msg')->insertGetId($data);
  65. if ($active_order_rs && $sys_rs) {
  66. Db::commit();
  67. } else {
  68. Db::rollback();
  69. $_data['pay_status'] = 1; //回调状态: 1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
  70. }
  71. }
  72. $PayResult->where($where)->setField($_data);
  73. $r_arr['return_code'] = 'SUCCESS';
  74. $r_arr['return_msg'] = '回调成功';
  75. echo $wxPay->arrayToXml($r_arr);
  76. die;
  77. }
  78. }
  79. $r_arr['return_code'] = 'FAIL';
  80. $r_arr['return_msg'] = '回调失败';
  81. echo $wxPay->arrayToXml($r_arr);
  82. file_put_contents('wx_pay_error_logs.txt', date('Y-m-d H:i:s').'支付失败!'.json_encode($flag), FILE_APPEND);
  83. die;
  84. }
  85. /**
  86. * 支付回调
  87. */
  88. public function notify1() {
  89. $paytype = $this->request->param('paytype');
  90. $pay = Service::checkNotify($paytype);
  91. // Log::record("=======================", 'info');
  92. // Log::record("pay:", 'info');
  93. // Log::record($pay, 'info');
  94. // Log::record("=======================", 'info');
  95. if (!$pay) {
  96. echo '签名错误';
  97. return;
  98. }
  99. $data = $pay->verify();
  100. $time = time();
  101. try {
  102. $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
  103. $out_trade_no = $data['out_trade_no'];
  104. Db::startTrans();
  105. try{
  106. $orderModel = new \app\common\model\RecharOrder();
  107. $userModel = new \app\common\model\User();
  108. $orderInfo = $orderModel->where(["order_no"=>$out_trade_no])->find();
  109. $userInfo = $userModel->where(["id"=>$orderInfo["user_id"]])->find();
  110. $res1 = false;
  111. $res2 = false;
  112. $res3 = false;
  113. if($orderInfo['status'] == 0) {
  114. // 修改订单状态
  115. $res1 = $orderModel->update(["status"=>1,"updatetime"=>$time],["order_no"=>$out_trade_no, 'status' => 0]);
  116. // 充值后
  117. switch($orderInfo['purpose']) {
  118. case 1:
  119. // 修改用户为已缴纳认证费
  120. $userInfo->recharge_auth = 1;
  121. $res2 = $userInfo->save();
  122. $res3 = true;
  123. break;
  124. case 2:
  125. // 添加有眼缘记录--单次付费
  126. $data = [];
  127. $data['user_id'] = $userInfo->id;
  128. $data['fate_user_id'] = $orderInfo->fate_user_id;
  129. if(!\app\common\model\UserFate::where($data)->find()) {
  130. $data['createtime'] = $time;
  131. $res2 = \app\common\model\UserFate::insert($data);
  132. } else {
  133. $res2 = true;
  134. }
  135. // 返利
  136. $preuser_id = $userInfo->pre_user_id;
  137. if($userInfo->vip_duetime < $time) {
  138. $memo = '用户充值获得收益!';
  139. $profit = $payamount * config('site.userProfitRate') * 0.01;
  140. } else {
  141. $memo = '会员充值获得收益!';
  142. $profit = $payamount * config('site.vipProfitRate') * 0.01;
  143. }
  144. if($profit>=0.01 && $preuser_id > 0) {
  145. $res3 = \app\common\model\User::profit($profit,$preuser_id,$memo);
  146. } else {
  147. $res3 = true;
  148. }
  149. break;
  150. case 3:
  151. // 获取vip配置信息
  152. $vip_config_id = $orderInfo['vip_config_id'];
  153. $vipConfigInfo = \app\admin\model\vip\Config::where(['id'=>$vip_config_id])->find();
  154. // 计算vip到期时间
  155. if($userInfo->vip_duetime < $time) {
  156. $duetime = strtotime ( '+'.intval($vipConfigInfo['time']).' month' );
  157. } else {
  158. $duetime = strtotime ( '+'.intval($vipConfigInfo['time']).' month',$userInfo->vip_duetime);
  159. }
  160. // 修改用户为vip
  161. if($userInfo->vip_duetime <= time()) {
  162. $userInfo->view_count = $vipConfigInfo->give_times; // 今日剩余次数
  163. $userInfo->view_date = date('Y-m-d'); // 次数最后更新日期
  164. }
  165. $userInfo->vip_duetime = $duetime;
  166. $res2 = $userInfo->save();
  167. // 添加查看次数
  168. $data = [];
  169. $data['user_id'] = $userInfo->id;
  170. $data['end_date'] = date("Y-m-d",$duetime);
  171. $data['times'] = $vipConfigInfo->give_times;
  172. $data['createtime'] = time();
  173. $res3 = \app\common\model\GiveFateLog::insert($data);
  174. break;
  175. case 4:
  176. // 获取钻石配置信息
  177. $vip_config_id = $orderInfo['vip_config_id'];
  178. $vipConfigInfo = Db::name('diamond')->where(['id'=>$vip_config_id])->find();
  179. //修改用户钻石余额
  180. $diamond = $userInfo['diamond'] + $vipConfigInfo['number'];
  181. $res2 = Db::name('user')->where(['id' => $userInfo['id'], 'diamond' => $userInfo['diamond']])->setField('diamond', $diamond);
  182. // 添加钻石明细
  183. $diamond_log = Db::name('user_diamond_log')->where(['user_id' => $userInfo['id']])->order('id', 'desc')->find();
  184. if (!$diamond_log && $userInfo['diamond'] > 0) {
  185. $res3 = false;
  186. break;
  187. }
  188. if ($diamond_log && $diamond_log['after'] != $userInfo['diamond']) {
  189. $res3 = false;
  190. break;
  191. }
  192. $data = [];
  193. $data['user_id'] = $userInfo['id'];
  194. $data['diamond'] = $vipConfigInfo['number'];
  195. $data['before'] = $userInfo['diamond'];
  196. $data['after'] = $diamond;
  197. $data['memo'] = '充值';
  198. $data['createtime'] = time();
  199. $res3 = Db::name('user_diamond_log')->insertGetId($data);
  200. break;
  201. }
  202. }
  203. if($res1 && $res2 !== false && $res3) {
  204. Db::commit();
  205. } else {
  206. Db::rollback();
  207. }
  208. }catch (ValidateException $e) {
  209. Db::rollback();
  210. $this->error($e->getMessage());
  211. } catch (PDOException $e) {
  212. Db::rollback();
  213. $this->error($e->getMessage());
  214. } catch (Exception $e) {
  215. Db::rollback();
  216. $this->error($e->getMessage());
  217. }
  218. //你可以在此编写订单逻辑
  219. } catch (Exception $e) {
  220. }
  221. echo $pay->success();
  222. }
  223. //自动取消超时未支付的活动订单
  224. public function cancelorder() {
  225. set_time_limit(0);
  226. $where = array(
  227. 'status' => 0,
  228. 'createtime' => ['lt', time() - 1920], //32分钟之前
  229. );
  230. $active_order = Db::name('active_order');
  231. $list = $active_order->where($where)->limit(200)->select();
  232. if (!$list) {
  233. echo 'mei shu ju';
  234. die;
  235. }
  236. $active_people = Db::name('active_people');
  237. $active_people_modify = Db::name('active_people_modify');
  238. $active = Db::name('active');
  239. foreach ($list as &$v) {
  240. //开启事务
  241. Db::startTrans();
  242. //修改订单信息
  243. $rs = $active_order->where(['id' => $v['id'], 'status' => 0])->setField('status', 3);
  244. if (!$rs) {
  245. Db::rollback();
  246. continue;
  247. }
  248. //修改活动人员
  249. $rt = $active_people->where(['order_id' => $v['id'], 'status' => 0])->setField(['status' => 3, 'modifystatus' => 0]);
  250. if (!$rt) {
  251. Db::rollback();
  252. continue;
  253. }
  254. //修改活动人员修改记录
  255. $res = $active_people_modify->where(['order_id' => $v['id'], 'status' => 0])->setField('status', 2);
  256. if ($res === false) {
  257. Db::rollback();
  258. continue;
  259. }
  260. //减少活动已报名人数
  261. $active_info = $active->find($v['active_id']);
  262. $currentperson = $active_info['currentperson'] - $v['number'];
  263. $active_rs = $active->where(['id' => $v['active_id'], 'currentperson' => $active_info['currentperson']])->setField('currentperson', $currentperson);
  264. if (!$active_rs) {
  265. Db::rollback();
  266. continue;
  267. }
  268. Db::commit();
  269. }
  270. echo 'wan bi';
  271. die;
  272. }
  273. //消息推送 我报名参加活动的前一天会提前推送消息,时间 地点 及一些提醒
  274. public function sysmsg() {
  275. set_time_limit(0);
  276. $where = array(
  277. 'starttime' => ['elt', time() + 86400], //活动开始前一天
  278. 'msgstatus' => 0,
  279. 'status' => ['neq', 3]
  280. );
  281. $active = Db::name('active');
  282. $list = $active->where($where)->limit(200)->select();
  283. if (!$list) {
  284. echo 'mei shu ju';
  285. die;
  286. }
  287. $active_order = Db::name('active_order');
  288. $sys_msg = Db::name('sys_msg'); //系统消息
  289. $data['type'] = 1;
  290. $data['title'] = '活动通知';
  291. $data['createtime'] = time();
  292. foreach ($list as &$v) {
  293. //修改活动消息通知状态
  294. $active->where(['id' => $v['id']])->setField('msgstatus', 1);
  295. //发送通知
  296. $data['content'] = '您报名的' . $v['title'] . '活动即将开始,请规划好您的时间。活动集合时间:' . date('Y-m-d H:i', $v['collectiontime']) . ',活动集合地点:' . $v['collectionplace'];
  297. //查询报名用户id
  298. $user_ids = $active_order->where(['active_id' => $v['id'], 'status' => 1])->column('user_id');
  299. if ($user_ids) {
  300. foreach ($user_ids as &$va) {
  301. $data['user_id'] = $va;
  302. $sys_msg->insertGetId($data);
  303. }
  304. }
  305. }
  306. echo 'wan bi';
  307. die;
  308. }
  309. //每年1月1重置免费次数
  310. public function resetfreenumber() {
  311. set_time_limit(0);
  312. //每年开始时间
  313. $time = strtotime(date('Y-1-1 0:0:0', time()));
  314. $where = array(
  315. 'freenumbertime' => ['lt', $time]
  316. );
  317. $user = Db::name('user');
  318. $list = $user->where($where)->limit(200)->select();
  319. if (!$list) {
  320. echo 'mei shu ju';
  321. die;
  322. }
  323. $vip = Db::name('vip');
  324. foreach ($list as &$v) {
  325. $free = $vip->find($v['growthlevel']);
  326. $user->where(['id' => $v['id'], 'freenumber' => $v['freenumber']])->setField(['freenumber' => $free['free'], 'freenumbertime' => time()]);
  327. }
  328. echo 'wan bi';
  329. die;
  330. }
  331. //自动结束已完成订单
  332. public function finishorder() {
  333. set_time_limit(0);
  334. $where = array(
  335. 'status' => 1,
  336. 'endtime' => ['lt', time()]
  337. );
  338. $active = Db::name('active');
  339. $list = $active->where($where)->limit(100)->select();
  340. if (!$list) {
  341. echo 'mei shu ju';
  342. die;
  343. }
  344. $active_order = Db::name('active_order');
  345. $active_people = Db::name('active_people');
  346. $active_people_modify = Db::name('active_people_modify');
  347. $active_refund = Db::name('active_refund');
  348. foreach ($list as &$v) {
  349. //开启事务
  350. Db::startTrans();
  351. //活动结束
  352. $active_rs = $active->where(['id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'updatetime' => time()]);
  353. if (!$active_rs) {
  354. Db::rollback();
  355. continue;
  356. }
  357. //修改活动订单状态
  358. $order_rs = $active_order->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'updatetime' => time()]);
  359. if ($order_rs === false) {
  360. Db::rollback();
  361. continue;
  362. }
  363. //修改活动人员状态
  364. $people_rs = $active_people->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'modifystatus' => 0, 'updatetime' => time()]);
  365. if ($people_rs === false) {
  366. Db::rollback();
  367. continue;
  368. }
  369. //修改活动人员信息修改表
  370. $people_modify_rs = $active_people_modify->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
  371. if ($people_modify_rs === false) {
  372. Db::rollback();
  373. continue;
  374. }
  375. //修改活动申请取消表
  376. $refund_rs = $active_refund->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
  377. if ($refund_rs === false) {
  378. Db::rollback();
  379. continue;
  380. }
  381. Db::commit();
  382. }
  383. echo 'wan bi';
  384. die;
  385. }
  386. //自动取消未成行订单
  387. public function cancelminpeopleorder() {
  388. set_time_limit(0);
  389. $where = array(
  390. 'status' => 0,
  391. 'signupendtime' => ['lt', time()]
  392. );
  393. $active = Db::name('active');
  394. $list = $active->where($where)->limit(100)->select();
  395. if (!$list) {
  396. echo 'mei shu ju';
  397. die;
  398. }
  399. $active_order = Db::name('active_order');
  400. $active_people = Db::name('active_people');
  401. $active_people_modify = Db::name('active_people_modify');
  402. $active_refund = Db::name('active_refund');
  403. $user_coupon = Db::name('user_coupon'); //用户优惠券表
  404. $sys_msg = Db::name('sys_msg'); //消息通知
  405. foreach ($list as &$v) {
  406. //开启事务
  407. Db::startTrans();
  408. //活动结束
  409. $active_rs = $active->where(['id' => $v['id'], 'status' => 0])->setField(['status' => 3, 'updatetime' => time()]);
  410. if (!$active_rs) {
  411. Db::rollback();
  412. continue;
  413. }
  414. //修改活动人员状态
  415. $people_rs = $active_people->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 3, 'modifystatus' => 0, 'updatetime' => time()]);
  416. if ($people_rs === false) {
  417. Db::rollback();
  418. continue;
  419. }
  420. //修改活动人员信息修改表
  421. $people_modify_rs = $active_people_modify->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
  422. if ($people_modify_rs === false) {
  423. Db::rollback();
  424. continue;
  425. }
  426. //修改活动申请取消表
  427. $refund_rs = $active_refund->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
  428. if ($refund_rs === false) {
  429. Db::rollback();
  430. continue;
  431. }
  432. //查询活动订单
  433. $active_order_list = $active_order->where(['active_id' => $v['id'], 'status' => 1])->select();
  434. if ($active_order_list) {
  435. //活动订单修改信息
  436. $order_data['status'] = 3; //状态:0=待付款,1=待出行,2=已完成,3=已取消
  437. $order_data['updatetime'] = time();
  438. foreach ($active_order_list as &$vv) {
  439. //退还支付金额
  440. if ($vv['price'] > 0) {
  441. $order_data['refundstatus'] = 1; //退款状态:0=无需退款,1=退款成功,2=退款失败
  442. $order_data['refundprice'] = $vv['price'];//退款金额
  443. $order_data['refundtime'] = time();
  444. if ($vv['paytype'] == 0) {
  445. //余额支付, 退回余额
  446. $rs = create_log($vv['price'], '活动取消返还', $vv['user_id'], 3, $vv['id']);
  447. if ($rs != 1) {
  448. $order_data['refundstatus'] = 2;
  449. }
  450. } elseif ($vv['paytype'] == 1) {
  451. //微信支付, 退回微信
  452. //扣除用户成长值
  453. $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
  454. $balance = floor($paygrowth * $vv['price']);
  455. if ($balance > 0) {
  456. $paygrowth_rs = create_growth_log(-$balance, '活动取消扣除', $vv['user_id'], 4, $vv['id']);
  457. }
  458. //退款单号
  459. $order_data['refund_no'] = $vv['order_sn'];
  460. //调用微信退款
  461. $wxData['transaction_id'] = $vv['transaction_id'];
  462. $wxData['out_refund_no'] = $order_data['refund_no'];
  463. $wxData['total_fee'] = (int)($vv['price'] * 100);//1 微信支付 单位为分
  464. $wxData['refund_fee'] = (int)($vv['price'] * 100);//1 微信支付 单位为分
  465. $wxData['refund_desc'] = '活动取消返还';
  466. // require_once("Plugins/WxPay/WxPay.php");
  467. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  468. $back = $wxPay->WxPayRefund($wxData);
  469. if($back['return_code'] != 'SUCCESS' || $back['result_code'] != 'SUCCESS') {
  470. $order_data['refundstatus'] = 2;
  471. }
  472. }
  473. }
  474. //修改活动订单状态
  475. $order_rs = $active_order->where(['id' => $vv['id'], 'status' => 1])->setField($order_data);
  476. if ($order_rs === false) {
  477. Db::rollback();
  478. continue;
  479. }
  480. //上级优惠券设为过期
  481. $user_coupon->where(['active_id' => $vv['id'], 'status' => 0])->setField('endtime', time() - 1);
  482. //发送消息
  483. $data = [
  484. 'user_id' => $vv['user_id'],
  485. 'type' => 1,
  486. 'title' => '活动通知',
  487. 'content' => '您报名的' . $v['title'] . '活动已取消',
  488. 'createtime' => time()
  489. ];
  490. $sys_msg->insertGetId($data);
  491. }
  492. }
  493. Db::commit();
  494. }
  495. echo 'wan bi';
  496. die;
  497. }
  498. //自动上架活动
  499. public function showactive() {
  500. set_time_limit(0);
  501. $time = time();
  502. $where = array(
  503. 'showstatus' => 0,
  504. 'is_autoshow' => 1,
  505. 'showtime' => ['elt', $time]
  506. );
  507. $active = Db::name('active');
  508. $list = $active->where($where)->limit(200)->select();
  509. if (!$list) {
  510. echo 'mei shu ju';
  511. die;
  512. }
  513. foreach ($list as &$v) {
  514. $active->where(['id' => $v['id'], 'showstatus' => 0])->setField(['showstatus' => 1]);
  515. }
  516. echo 'wan bi';
  517. die;
  518. }
  519. //视频转码
  520. public function transcode() {
  521. set_time_limit(0);
  522. $where = array(
  523. 'transcode_status' => 0
  524. );
  525. $hu_video = Db::name('video');
  526. $list = $hu_video->where($where)->limit(50)->select();
  527. if (!$list) {
  528. echo 'mei shu ju';
  529. die;
  530. }
  531. $url = 'http://api.trans.gitv.tv/upload';
  532. $data['cp_id'] = config('cp_id');
  533. $data['media_type'] = 'mp4';
  534. foreach ($list as &$v) {
  535. $data['uri'] = urlencode(config('upload.cdnurl') . $v['videofile']);
  536. $data['file_name'] = urlencode($v['title']);
  537. $request_url = $url . '?' . http_build_query($data);
  538. $rs = file_get_contents($request_url);
  539. if (!$rs) {
  540. continue;
  541. }
  542. $rs = json_decode($rs);
  543. if ($rs['code'] == 'A000000') {
  544. $hu_video->where(['id' => $v['id'], 'transcode_status' => 0])->setField(['transcode_status' => 1, 'task_id' => $rs['task_id']]);
  545. }
  546. }
  547. echo 'wan bi';
  548. die;
  549. }
  550. //视频转码回执
  551. public function transcodecallback() {
  552. $cp_id = input('cp_id', 0, 'intval');
  553. $file_url = input('file_url', '', 'trim');
  554. $task_id = input('task_id', '', 'trim');
  555. if ($cp_id != config('cp_id')) {
  556. $this->error('错误1');
  557. }
  558. $info = Db::name('video')->where(['task_id' => $task_id])->find();
  559. if (!$info) {
  560. $this->error('错误2');
  561. }
  562. if ($info['transcode_status'] != 1) {
  563. $this->success('已完成');
  564. }
  565. $file_url = urldecode($file_url);
  566. $rs = Db::name('video')->where(['id' => $info['id'], 'transcode_status' => 1])->setField(['transcode_status' => 2, 'file_url' => $file_url]);
  567. if (!$rs) {
  568. $this->error('失败');
  569. }
  570. $this->success('成功');
  571. }
  572. //视频注入
  573. public function inject() {
  574. set_time_limit(0);
  575. $where = array(
  576. 'transcode_status' => 2,
  577. 'inject_status' => 0
  578. );
  579. $hu_video = Db::name('video');
  580. $list = $hu_video->where($where)->limit(50)->select();
  581. if (!$list) {
  582. echo 'mei shu ju';
  583. die;
  584. }
  585. $url = 'http://api.gs.gitv.tv/upload';
  586. $data['cp_id'] = config('cp_id');
  587. $data['bit_id'] = 5;
  588. $data['file_type'] = 'm3u8';
  589. foreach ($list as &$v) {
  590. $data['album_id'] = (string)$v['id'];
  591. $data['video_id'] = (string)$v['id'];
  592. $data['uri'] = $v['file_url'];
  593. $rs = httpRequest($url, 'POST', $data);
  594. if (!$rs) {
  595. continue;
  596. }
  597. $rs = json_decode($rs);
  598. if ($rs['code'] == 'A000000') {
  599. $hu_video->where(['id' => $v['id'], 'inject_status' => 0])->setField(['inject_status' => 1]);
  600. }
  601. }
  602. echo 'wan bi';
  603. die;
  604. }
  605. //视频注入回执
  606. public function injectcallback() {
  607. $cp_id = input('cp_id', 0, 'intval');
  608. $album_id = input('album_id', '', 'trim'); //专辑 ID
  609. $video_id = input('video_id', '', 'trim'); //剧集 ID
  610. $code = input('code', '', 'trim'); //状态码
  611. if ($cp_id != config('cp_id')) {
  612. $this->error('错误1');
  613. }
  614. $info = Db::name('video')->where(['id' => $video_id])->find();
  615. if (!$info) {
  616. $this->error('错误2');
  617. }
  618. if ($info['inject_status'] != 1) {
  619. $this->success('已完成');
  620. }
  621. if ($code == 'A000000') {
  622. $inject_status = 2;
  623. } else {
  624. $inject_status = 3;
  625. }
  626. $rs = Db::name('video')->where(['id' => $info['id'], 'inject_status' => 1])->setField(['inject_status' => $inject_status]);
  627. if (!$rs) {
  628. $this->error('失败');
  629. }
  630. $this->success('成功');
  631. }
  632. //视频注入结果查询
  633. public function injectquery() {
  634. set_time_limit(0);
  635. $time = strtotime(date('Y-m-d', time()));
  636. $where = array(
  637. 'inject_status' => 1,
  638. 'updatetime' => ['egt', $time]
  639. );
  640. $hu_video = Db::name('video');
  641. // $list = $hu_video->where($where)->count('id');
  642. $list = $hu_video->where($where)->limit(50)->select();
  643. if (!$list) {
  644. echo 'mei shu ju';
  645. die;
  646. }
  647. /*$starttime = date('Ymd000000', time());
  648. $endtime = date('Ymd235959', time());
  649. // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/injectResult/v1/queryAdd?cspId=' . config('cspid') . '&startTime='.$starttime.'&endTime='.$endtime;
  650. $url = 'http://jscp.agency.gitv.tv/injectResult/v1/queryAdd?cspId=' . config('cspid') . '&startTime='.$starttime.'&endTime='.$endtime;
  651. $header = [
  652. 'Content-Type: application/json'
  653. ];
  654. $rs = httpRequest($url, 'POST', [], $header);
  655. if (!$rs) {
  656. echo 'cuo wu1';
  657. die;
  658. }
  659. $list = json_decode($rs, true);
  660. if ($list['code'] != 'A000000') {
  661. echo 'cuo wu2';
  662. die;
  663. }
  664. foreach ($list['data'] as &$v) {
  665. if ($v['taskStatus'] == 2) {
  666. $hu_video->where(['id' => $v['cpTvId'], 'inject_status' => 1])->setField(['inject_status' => 2]);
  667. }
  668. }*/
  669. $header = [
  670. 'Content-Type: application/json'
  671. ];
  672. //生成ftp文件
  673. $content = [
  674. 'cpPrvdName' => '健康e家',
  675. 'cpPrvCode' => '41000144',
  676. 'cpPrvType' => '1006',
  677. 'ChnName' => '健康',
  678. 'ChnCode' => '1000020',
  679. 'actors' => '无',
  680. 'directors' => '无',
  681. 'contentYear' => date('Y'),
  682. 'tags' => '',
  683. 'contentTime' => date('Y-m-d H:i:s'),
  684. 'formatType' => '超清'
  685. ];
  686. //增量接口
  687. $insert_url = 'http://test.meta.unso.gitv.tv/sendMeta';
  688. $method = 'POST';
  689. foreach ($list as &$v) {
  690. //查询华为注入结果
  691. $url = 'http://jscp.agency.gitv.tv/injectResult/v1/queryTv?cspId=' . config('cspid') . '&cpAlbumId=' . $v['id'] . '&cpTvId=' . $v['id'];
  692. $rs = httpRequest($url, 'GET', [], $header);
  693. if (!$rs) {
  694. continue;
  695. }
  696. $rs = json_decode($rs, true);
  697. if ($rs['code'] != 'A000000') {
  698. continue;
  699. }
  700. $data = $rs['data'][0];
  701. if ($data['taskStatus'] == 2) {
  702. /*//生成ftp文件
  703. $content['contentId'] = $v['movieid'];
  704. $content['extraContentID'] = $v['movieid'];
  705. $content['content'] = $v['title'];
  706. $content['intent'] = [
  707. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  708. 'package' => 'com.huxiu.heh.tv',
  709. 'component' => [
  710. 'pkg' => 'com.huxiu.heh.tv',
  711. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  712. ],
  713. 'extras' => [
  714. // 'cmd' => '',
  715. // 'from' => '',
  716. // 'media_id' => ''
  717. 'type_id' => $v['video_type_id'],
  718. 'id' => $v['id']
  719. ]
  720. ];
  721. $content['isEffective'] = $v['status'];
  722. $content['pic'] = one_domain_image($v['image']);
  723. $content['isPaid'] = $v['is_pay'];
  724. $content = json_encode($content, 320);
  725. $filename = 'shipin_'.date('Ymd').'_'.date('His').'_increment'.'.json';
  726. error_log(print_r($content, 1) . PHP_EOL, 3, './jiankang/' . $filename);
  727. //调用增量注入接口
  728. $postfields = [
  729. 'priKey' => config('cspid'),
  730. 'data' => [$content]
  731. ];
  732. $rt = httpRequest($insert_url, $method, $postfields, $header);
  733. if (!$rt) {
  734. continue;
  735. }
  736. $rt = json_decode($rt, true);
  737. if ($rt['code'] != 'A000000') {
  738. continue;
  739. }*/
  740. //查询中兴注入结果
  741. $url2 = 'http://jscp.agency.gitv.tv/injectResult/v1/queryTv?cspId=' . config('cspid_zx') . '&cpAlbumId=' . $v['id'] . '&cpTvId=' . $v['id'];
  742. $rs2 = httpRequest($url2, 'GET', [], $header);
  743. if (!$rs2) {
  744. continue;
  745. }
  746. $rs2 = json_decode($rs2, true);
  747. if ($rs2['code'] != 'A000000') {
  748. continue;
  749. }
  750. $data2 = $rs2['data'][0];
  751. if ($data2['taskStatus'] == 2) {
  752. $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 2, 'seriesid' => $data['seriesId'], 'programid' => $data['programId'], 'movieid' => $data['movieId']]);
  753. } elseif ($data2['taskStatus'] == -1 || $data2['taskStatus'] == -3 || $data2['taskStatus'] == -4) {
  754. $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 3, 'seriesid' => $data['seriesId'], 'programid' => $data['programId'], 'movieid' => $data['movieId']]);
  755. }
  756. } elseif ($data['taskStatus'] == -1 || $data['taskStatus'] == -3 || $data['taskStatus'] == -4) {
  757. $hu_video->where(['id' => $v['id'], 'inject_status' => 1])->setField(['inject_status' => 3, 'seriesid' => $data['seriesId'], 'programid' => $data['programId'], 'movieid' => $data['movieId']]);
  758. }
  759. }
  760. echo 'wan bi';
  761. die;
  762. }
  763. //视频统一搜索生成ftp文件
  764. public function videosearch() {
  765. set_time_limit(0);
  766. // $time = strtotime(date('Y-m-d', time()));
  767. $where = array(
  768. 'inject_status' => 2,
  769. 'search_status' => 0,
  770. // 'updatetime' => ['egt', $time]
  771. );
  772. $hu_video = Db::name('video');
  773. $list = $hu_video->where($where)->limit(50)->select();
  774. if (!$list) {
  775. echo 'mei shu ju';
  776. die;
  777. }
  778. $header = [
  779. 'Content-Type: application/json'
  780. ];
  781. //生成ftp文件
  782. $data_content = [
  783. 'cpPrvdName' => '健康e家',
  784. 'cpPrvCode' => '41000144',
  785. 'cpPrvType' => '1006',
  786. 'ChnName' => '健康',
  787. 'ChnCode' => '1000020',
  788. 'actors' => '无',
  789. 'directors' => '无',
  790. 'contentYear' => date('Y'),
  791. 'tags' => '',
  792. 'contentTime' => date('Y-m-d H:i:s'),
  793. 'formatType' => '超清'
  794. ];
  795. //增量接口
  796. $insert_url = 'http://test.meta.unso.gitv.tv/sendMeta';
  797. $method = 'POST';
  798. foreach ($list as &$v) {
  799. //生成ftp文件
  800. $content = $data_content;
  801. $content['contentId'] = $v['movieid'];
  802. $content['extraContentID'] = $v['movieid'];
  803. $content['content'] = $v['title'];
  804. $intent = json_encode([
  805. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  806. 'package' => 'com.huxiu.heh.tv',
  807. 'component' => [
  808. 'pkg' => 'com.huxiu.heh.tv',
  809. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  810. ],
  811. 'extras' => [
  812. // 'cmd' => '',
  813. // 'from' => '',
  814. // 'media_id' => ''
  815. 'type_id' => $v['video_type_id'],
  816. 'id' => $v['id']
  817. ]
  818. ], 320);
  819. $content['intent'] = "$intent";
  820. $content['isEffective'] = $v['status'];
  821. $content['pic'] = one_domain_image($v['image']);
  822. $content['isPaid'] = $v['is_pay'];
  823. $content = json_encode($content, 320);
  824. $filename = 'shipin_'.date('Ymd').'_'.date('His').'_increment'.'.json';
  825. error_log(print_r($content, 1) . PHP_EOL, 3, './jiankang/' . $filename);
  826. //调用增量注入接口
  827. /*$postfields = [
  828. 'priKey' => config('cspid'),
  829. 'data' => [$content]
  830. ];
  831. $rt = httpRequest($insert_url, $method, $postfields, $header);
  832. if (!$rt) {
  833. continue;
  834. }
  835. $rt = json_decode($rt, true);
  836. if ($rt['code'] != 'A000000') {
  837. continue;
  838. }*/
  839. $hu_video->where(['id' => $v['id'], 'search_status' => 0])->setField(['search_status' => 1]);
  840. }
  841. echo 'wan bi';
  842. die;
  843. }
  844. //订购关系同步地址
  845. public function ordersync() {
  846. $data = file_get_contents('php://input');
  847. if (!$data) {
  848. $this->error('参数缺失');
  849. }
  850. $jsonxml = json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA));
  851. $data = json_decode($jsonxml, true);
  852. if (!$data) {
  853. $this->error('参数缺失');
  854. }
  855. $phoneNumber = $data['orderRelationSyncRequest']['phoneNumber']; //手机号
  856. $apppId = $data['orderRelationSyncRequest']['apppId']; //订购的HDC业务产品编码
  857. if ($apppId != config('product_code')) {
  858. echo 'meiyou';
  859. exit;
  860. }
  861. //用户增值产品包当前订购快照
  862. $content = [
  863. 'UserID' => $phoneNumber,
  864. 'prod_code' => $apppId,
  865. 'prod_name' => '月包会员',
  866. 'eff_time' => date('Y-m-d H:i:s', time()),
  867. 'exp_time' => date('Y-m-d H:i:s', time() + 30 * 86400),
  868. 'price' => 2900
  869. ];
  870. $content = join(json_decode('"\u0001"', true), $content);
  871. $filename = date('Ymd').'_'.config('data_cp_id').'_userefforderdata_1.dat';
  872. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userefforderdata_1.chk';
  873. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  874. error_log('', 3, './dashuju/' . $check_filename);
  875. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userefforderdata.finish';
  876. error_log('', 3, './dashuju/' . $finish_filename);
  877. //用户增值产品包订购行为数据
  878. $user_id = Db::name('user')->where(['mobile' => $phoneNumber])->value('id');
  879. $order_info = Db::name('rechar_order')->where(['user_id' => $user_id, 'purpose' => 3, 'pay_type' => 'zhuowang', 'status' => 1])->order('id desc')->find();
  880. $content = [
  881. 'orderid' => $order_info['order_no'],
  882. 'order_time' => date('Y-m-d H:i:s', time()),
  883. 'order_type' => 1,
  884. 'UserID' => $phoneNumber,
  885. 'prod_code' => $apppId,
  886. 'prod_name' => '月包会员',
  887. 'eff_time' => date('Y-m-d H:i:s', time()),
  888. 'exp_time' => date('Y-m-d H:i:s', time() + 30 * 86400),
  889. 'csource' => 99,
  890. 'trace_id' => '',
  891. 'price' => 2900,
  892. 'paytype' => 0,
  893. 'cpid' => config('data_cp_id'),
  894. 'albumid' => '',
  895. 'albumname' => ''
  896. ];
  897. $content = join(json_decode('"\u0001"', true), $content);
  898. $filename = date('Ymd').'_'.config('data_cp_id').'_userorderdata_1.dat';
  899. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userorderdata_1.chk';
  900. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  901. error_log('', 3, './dashuju/' . $check_filename);
  902. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userorderdata.finish';
  903. error_log('', 3, './dashuju/' . $finish_filename);
  904. }
  905. //(补漏)视频注入中兴
  906. public function injectzx() {
  907. set_time_limit(0);
  908. $hu_video = Db::name('video');
  909. $list = $hu_video->where(['id' => 107])->limit(50)->select();
  910. if (!$list) {
  911. echo 'mei shu ju';
  912. die;
  913. }
  914. $cspid = config('cspid_zx');
  915. $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
  916. foreach ($list as &$params) {
  917. //内容同步
  918. $videofile = $params['videofile'];
  919. $videofile = explode('/', $videofile);
  920. $video_url = $videofile[3];
  921. $data = [
  922. // 'cspId' => $cspid,
  923. 'cpAlbumId' => $params['id'],
  924. 'albumName' => $params['title'],
  925. 'tvSets' => 1,
  926. 'updateToSet' => 1,
  927. 'isPurchase' => $params['is_pay'],
  928. 'isEffective' => $params['status'],
  929. 'isOnline' => $params['status'],
  930. 'albumTypes' => '健康',
  931. 'picBox' => config('upload.cdnurl') . $params['image'],
  932. 'albumUpdateTime' => date('YmdHis', time()),
  933. 'albumCreateTime' => date('YmdHis', time()),
  934. 'tvlist' => [
  935. [
  936. 'cpAlbumId' => $params['id'],
  937. 'cpTvId' => $params['id'],
  938. 'tvName' => $params['title'],
  939. 'tvIsEffective' => $params['status'],
  940. 'tvIsOnline' => $params['status'],
  941. 'isPurchase' => $params['is_pay'],
  942. 'playOrder' => 1,
  943. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  944. ]
  945. ]
  946. ];
  947. $data = json_encode($data, 320);
  948. $header = [
  949. 'Content-Type: application/json'
  950. ];
  951. $rs = httpRequest($url, 'POST', $data, $header);
  952. if ($rs) {
  953. $rs = json_decode($rs, true);
  954. if ($rs['code'] != 'A000000') {
  955. continue;
  956. }
  957. }
  958. }
  959. echo 'wan bi';
  960. die;
  961. }
  962. //(补漏)删除注入中兴视频
  963. public function delinjectzx() {
  964. set_time_limit(0);
  965. $hu_video = Db::name('video');
  966. $list = $hu_video->where(['id' => 107])->limit(1)->order('id')->select();
  967. if (!$list) {
  968. echo 'mei shu ju';
  969. die;
  970. }
  971. $cspid = config('cspid_zx');
  972. $url = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . $cspid . '/';
  973. foreach ($list as &$params) {
  974. //内容同步
  975. $videofile = $params['videofile'];
  976. $videofile = explode('/', $videofile);
  977. $video_url = $videofile[3];
  978. $data = [
  979. // 'cspId' => $cspid,
  980. 'cpAlbumId' => $params['id'],
  981. 'albumName' => $params['title'],
  982. 'tvSets' => 1,
  983. 'updateToSet' => 1,
  984. 'isPurchase' => $params['is_pay'],
  985. 'isEffective' => 0,
  986. 'isOnline' => 2,
  987. 'albumTypes' => '健康',
  988. 'picBox' => config('upload.cdnurl') . $params['image'],
  989. 'albumUpdateTime' => date('YmdHis', time()),
  990. // 'albumCreateTime' => date('YmdHis', time()),
  991. 'tvlist' => [
  992. [
  993. 'cpAlbumId' => $params['id'],
  994. 'cpTvId' => $params['id'],
  995. 'tvName' => $params['title'],
  996. 'tvIsEffective' => 0,
  997. 'tvIsOnline' => 2,
  998. 'isPurchase' => $params['is_pay'],
  999. 'playOrder' => 1,
  1000. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  1001. ]
  1002. ]
  1003. ];
  1004. $data = json_encode($data, 320);
  1005. $header = [
  1006. 'Content-Type: application/json'
  1007. ];
  1008. $rs = httpRequest($url, 'POST', $data, $header);
  1009. if ($rs) {
  1010. $rs = json_decode($rs, true);
  1011. if ($rs['code'] != 'A000000') {
  1012. continue;
  1013. }
  1014. }
  1015. }
  1016. echo 'wan bi';
  1017. die;
  1018. }
  1019. //媒资数据专辑粒度
  1020. public function mediadataalbum() {
  1021. $hu_video = Db::name('video');
  1022. $list = $hu_video->where(['inject_status' => 2, 'mediaalbum_status' => 0])->order('id')->select();
  1023. if (!$list) {
  1024. echo 'mei shu ju';
  1025. die;
  1026. }
  1027. foreach ($list as $key => &$param) {
  1028. $content = [
  1029. 'Updatetype' => 1,
  1030. 'cpid' => config('data_cp_id'),
  1031. 'channelid' => '1000035',
  1032. 'albumid' => $param['id'],
  1033. 'albumname' => $param['title'],
  1034. 'albumnum' => 1,
  1035. 'tag' => '',
  1036. 'onlinetime' => '',
  1037. 'bref' => '',
  1038. 'onebref' => '',
  1039. 'cornersign' => $param['is_pay'],
  1040. 'director' => '',
  1041. 'actor' => '',
  1042. 'year' => '',
  1043. 'area' => '',
  1044. 'language' => '',
  1045. 'score' => '',
  1046. 'picurl' => config('upload.cdnurl') . $param['image'],
  1047. 'picurl_v' => '',
  1048. 'gotourl' => json_encode([
  1049. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  1050. 'package' => 'com.huxiu.heh.tv',
  1051. 'component' => [
  1052. 'pkg' => 'com.huxiu.heh.tv',
  1053. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  1054. ],
  1055. 'extras' => [
  1056. // 'cmd' => '',
  1057. // 'from' => '',
  1058. // 'media_id' => ''
  1059. 'type_id' => $param['video_type_id'],
  1060. 'id' => $param['id']
  1061. ]
  1062. ], 320),
  1063. 'is_politics' => '',
  1064. 'second_type' => ''
  1065. ];
  1066. $content = join(json_decode('"\u0001"', true), $content);
  1067. $filename = date('Ymd').'_'.config('data_cp_id').'_albumsdata_1.dat';
  1068. $check_filename = date('Ymd').'_'.config('data_cp_id').'_albumsdata_1.chk';
  1069. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1070. error_log('', 3, './dashuju/' . $check_filename);
  1071. if ($key == count($list) - 1) {
  1072. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_albumsdata.finish';
  1073. error_log('', 3, './dashuju/' . $finish_filename);
  1074. }
  1075. $hu_video->where(['id' => $param['id'], 'mediaalbum_status' => 0])->setField('mediaalbum_status', 1);
  1076. }
  1077. echo 'wan bi';
  1078. }
  1079. //媒资数据节目/内容粒度
  1080. public function mediadatavideo() {
  1081. $hu_video = Db::name('video');
  1082. $list = $hu_video->where(['inject_status' => 2, 'mediavideo_status' => 0])->order('id')->select();
  1083. if (!$list) {
  1084. echo 'mei shu ju';
  1085. die;
  1086. }
  1087. foreach ($list as $key => &$param) {
  1088. $content = [
  1089. 'Updatetype' => 1,
  1090. 'cpid' => config('data_cp_id'),
  1091. 'channelid' => '1000035',
  1092. 'albumid' => $param['id'],
  1093. 'albumname' => $param['title'],
  1094. 'videoid' => $param['id'],
  1095. 'videoname' => $param['title'],
  1096. 'videonum' => 1,
  1097. 'Contenttype' => 1,
  1098. 'duration' => '',
  1099. 'quality' => ''
  1100. ];
  1101. $content = join(json_decode('"\u0001"', true), $content);
  1102. $filename = date('Ymd').'_'.config('data_cp_id').'_videosdata_1.dat';
  1103. $check_filename = date('Ymd').'_'.config('data_cp_id').'_videosdata_1.chk';
  1104. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1105. error_log('', 3, './dashuju/' . $check_filename);
  1106. if ($key == count($list) - 1) {
  1107. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_videosdata.finish';
  1108. error_log('', 3, './dashuju/' . $finish_filename);
  1109. }
  1110. $hu_video->where(['id' => $param['id'], 'mediavideo_status' => 0])->setField('mediavideo_status', 1);
  1111. }
  1112. }
  1113. //产品包
  1114. public function product() {
  1115. $content = [
  1116. 'prod_code' => config('product_code'),
  1117. 'prod_name' => '月包会员',
  1118. 'prod_type' => 0,
  1119. 'cpid' => config('data_cp_id')
  1120. ];
  1121. $content = join(json_decode('"\u0001"', true), $content);
  1122. $filename = date('Ymd').'_'.config('data_cp_id').'_productsdata_1.dat';
  1123. $check_filename = date('Ymd').'_'.config('data_cp_id').'_productsdata_1.chk';
  1124. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1125. error_log('', 3, './dashuju/' . $check_filename);
  1126. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_productsdata.finish';
  1127. error_log('', 3, './dashuju/' . $finish_filename);
  1128. //连接ftp
  1129. $host = config('data_ftp_ip');
  1130. $port = config('data_ftp_port');
  1131. $username = config('data_ftp_user');
  1132. $password = config('data_ftp_pwd');
  1133. $conn = ftp_connect($host, $port) or die("Could not connect");
  1134. //登录
  1135. ftp_login($conn,$username,$password);
  1136. //开启被动模式
  1137. ftp_pasv($conn, true);
  1138. //利用ftp创建目录
  1139. /*$path = "home/2021-12-08";
  1140. $this->make_directory($conn,$path);
  1141. //利用ftp选择进入目录
  1142. ftp_chdir($conn,$path);*/
  1143. //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
  1144. if(ftp_put($conn,$filename,'./dashuju/' . $filename,FTP_BINARY)){
  1145. //上传成功
  1146. }
  1147. if(ftp_put($conn,$check_filename,'./dashuju/' . $check_filename,FTP_BINARY)){
  1148. //上传成功
  1149. }
  1150. if(ftp_put($conn,$finish_filename,'./dashuju/' . $finish_filename,FTP_BINARY)){
  1151. //上传成功
  1152. }
  1153. ftp_close($conn);
  1154. //注意上传端的ftp权限设置
  1155. echo 'wanbi';
  1156. }
  1157. //产品包和媒资所属关系
  1158. public function productmediarelation() {
  1159. $hu_video = Db::name('video');
  1160. $list = $hu_video->where(['inject_status' => 2, 'productmedia_status' => 0])->order('id')->select();
  1161. if (!$list) {
  1162. echo 'mei shu ju';
  1163. die;
  1164. }
  1165. foreach ($list as $key => &$param) {
  1166. $content = [
  1167. 'Updatetype' => 1,
  1168. 'prod_code' => config('product_code'),
  1169. 'cpid' => config('data_cp_id'),
  1170. 'albumid' => $param['id']
  1171. ];
  1172. $content = join(json_decode('"\u0001"', true), $content);
  1173. $filename = date('Ymd').'_'.config('data_cp_id').'_productalbumdata_1.dat';
  1174. $check_filename = date('Ymd').'_'.config('data_cp_id').'_productalbumdata_1.chk';
  1175. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1176. error_log('', 3, './dashuju/' . $check_filename);
  1177. if ($key == count($list) - 1) {
  1178. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_productalbumdata.finish';
  1179. error_log('', 3, './dashuju/' . $finish_filename);
  1180. }
  1181. $hu_video->where(['id' => $param['id'], 'productmedia_status' => 0])->setField('productmedia_status', 1);
  1182. }
  1183. }
  1184. //用户观看行为数据文件上传到卓望ftp(每小时第10分钟提供)
  1185. public function uploadpayftp() {
  1186. set_time_limit(0);
  1187. $host = config('pay_ftp_ip');
  1188. $port = config('pay_ftp_port');
  1189. $username = config('pay_ftp_user');
  1190. $password = config('pay_ftp_pwd');
  1191. $filename = date('YmdH', time() - 3600).'_'.config('cp_id').'_userviewdata_1.dat';
  1192. $check_filename = date('YmdH', time() - 3600).'_'.config('cp_id').'_userviewdata_1.chk';
  1193. //判断文件是否存在, 不存在则创建
  1194. if (!file_exists('./dashuju/' . $filename)) {
  1195. @touch('./dashuju/' . $filename);
  1196. }
  1197. if (!file_exists('./dashuju/' . $check_filename)) {
  1198. @touch('./dashuju/' . $check_filename);
  1199. }
  1200. //连接ftp
  1201. $conn = ftp_connect($host, $port) or die("Could not connect");
  1202. //登录
  1203. ftp_login($conn,$username,$password);
  1204. //开启被动模式
  1205. ftp_pasv($conn, true);
  1206. //利用ftp创建目录
  1207. /*$path = "home/2021-12-08";
  1208. $this->make_directory($conn,$path);
  1209. //利用ftp选择进入目录
  1210. ftp_chdir($conn,$path);*/
  1211. //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
  1212. if(ftp_put($conn,$filename,'./dashuju/' . $filename,FTP_BINARY)){
  1213. //上传成功
  1214. }
  1215. if(ftp_put($conn,$check_filename,'./dashuju/' . $check_filename,FTP_BINARY)){
  1216. //上传成功
  1217. }
  1218. ftp_close($conn);
  1219. //注意上传端的ftp权限设置
  1220. echo 'wanbi';
  1221. }
  1222. //大数据文件上传到大数据ftp(每天一点提供)
  1223. public function uploaddataftp() {
  1224. set_time_limit(0);
  1225. $host = config('data_ftp_ip');
  1226. $port = config('data_ftp_port');
  1227. $username = config('data_ftp_user');
  1228. $password = config('data_ftp_pwd');
  1229. $time = date('Ymd', time() - 86400);
  1230. // 专辑粒度媒资
  1231. $albumsdata_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.dat';
  1232. $albumsdata_check_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.chk';
  1233. $albumsdata_finish_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.finish';
  1234. // 节目/内容粒度媒资
  1235. $videosdata_filename = $time.'_'.config('data_cp_id').'_videosdata_1.dat';
  1236. $videosdata_check_filename = $time.'_'.config('data_cp_id').'_videosdata_1.chk';
  1237. $videosdata_finish_filename = $time.'_'.config('data_cp_id').'_videosdata_1.finish';
  1238. // 产品包和媒资所属关系
  1239. $productalbumdata_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.dat';
  1240. $productalbumdata_check_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.chk';
  1241. $productalbumdata_finish_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.finish';
  1242. // 用户增值产品包当前订购快照
  1243. $userefforderdata_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.dat';
  1244. $userefforderdata_check_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.chk';
  1245. $userefforderdata_finish_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.finish';
  1246. // 用户增值产品包订购行为
  1247. $userorderdata_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.dat';
  1248. $userorderdata_check_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.chk';
  1249. $userorderdata_finish_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.finish';
  1250. // 用户观看行为
  1251. $userplaydata_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.dat';
  1252. $userplaydata_check_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.chk';
  1253. $userplaydata_finish_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.finish';
  1254. // 用户收藏行为
  1255. $userfavdata_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.dat';
  1256. $userfavdata_check_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.chk';
  1257. $userfavdata_finish_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.finish';
  1258. //判断文件是否存在, 不存在则创建
  1259. if (!file_exists('./dashuju/' . $albumsdata_filename)) {
  1260. @touch('./dashuju/' . $albumsdata_filename);
  1261. }
  1262. if (!file_exists('./dashuju/' . $albumsdata_check_filename)) {
  1263. @touch('./dashuju/' . $albumsdata_check_filename);
  1264. }
  1265. if (!file_exists('./dashuju/' . $albumsdata_finish_filename)) {
  1266. @touch('./dashuju/' . $albumsdata_finish_filename);
  1267. }
  1268. if (!file_exists('./dashuju/' . $videosdata_filename)) {
  1269. @touch('./dashuju/' . $videosdata_filename);
  1270. }
  1271. if (!file_exists('./dashuju/' . $videosdata_check_filename)) {
  1272. @touch('./dashuju/' . $videosdata_check_filename);
  1273. }
  1274. if (!file_exists('./dashuju/' . $videosdata_finish_filename)) {
  1275. @touch('./dashuju/' . $videosdata_finish_filename);
  1276. }
  1277. if (!file_exists('./dashuju/' . $productalbumdata_filename)) {
  1278. @touch('./dashuju/' . $productalbumdata_filename);
  1279. }
  1280. if (!file_exists('./dashuju/' . $productalbumdata_check_filename)) {
  1281. @touch('./dashuju/' . $productalbumdata_check_filename);
  1282. }
  1283. if (!file_exists('./dashuju/' . $productalbumdata_finish_filename)) {
  1284. @touch('./dashuju/' . $productalbumdata_finish_filename);
  1285. }
  1286. if (!file_exists('./dashuju/' . $userefforderdata_filename)) {
  1287. @touch('./dashuju/' . $userefforderdata_filename);
  1288. }
  1289. if (!file_exists('./dashuju/' . $userefforderdata_check_filename)) {
  1290. @touch('./dashuju/' . $userefforderdata_check_filename);
  1291. }
  1292. if (!file_exists('./dashuju/' . $userefforderdata_finish_filename)) {
  1293. @touch('./dashuju/' . $userefforderdata_finish_filename);
  1294. }
  1295. if (!file_exists('./dashuju/' . $userorderdata_filename)) {
  1296. @touch('./dashuju/' . $userorderdata_filename);
  1297. }
  1298. if (!file_exists('./dashuju/' . $userorderdata_check_filename)) {
  1299. @touch('./dashuju/' . $userorderdata_check_filename);
  1300. }
  1301. if (!file_exists('./dashuju/' . $userorderdata_finish_filename)) {
  1302. @touch('./dashuju/' . $userorderdata_finish_filename);
  1303. }
  1304. if (!file_exists('./dashuju/' . $userplaydata_filename)) {
  1305. @touch('./dashuju/' . $userplaydata_filename);
  1306. }
  1307. if (!file_exists('./dashuju/' . $userplaydata_check_filename)) {
  1308. @touch('./dashuju/' . $userplaydata_check_filename);
  1309. }
  1310. if (!file_exists('./dashuju/' . $userplaydata_finish_filename)) {
  1311. @touch('./dashuju/' . $userplaydata_finish_filename);
  1312. }
  1313. if (!file_exists('./dashuju/' . $userfavdata_filename)) {
  1314. @touch('./dashuju/' . $userfavdata_filename);
  1315. }
  1316. if (!file_exists('./dashuju/' . $userfavdata_check_filename)) {
  1317. @touch('./dashuju/' . $userfavdata_check_filename);
  1318. }
  1319. if (!file_exists('./dashuju/' . $userfavdata_finish_filename)) {
  1320. @touch('./dashuju/' . $userfavdata_finish_filename);
  1321. }
  1322. //连接ftp
  1323. $conn = ftp_connect($host, $port) or die("Could not connect");
  1324. //登录
  1325. ftp_login($conn,$username,$password);
  1326. //开启被动模式
  1327. ftp_pasv($conn, true);
  1328. //利用ftp创建目录
  1329. /*$path = "home/2021-12-08";
  1330. $this->make_directory($conn,$path);
  1331. //利用ftp选择进入目录
  1332. ftp_chdir($conn,$path);*/
  1333. //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
  1334. if(ftp_put($conn,$albumsdata_filename,'./dashuju/' . $albumsdata_filename,FTP_BINARY)){
  1335. //上传成功
  1336. }
  1337. if(ftp_put($conn,$albumsdata_check_filename,'./dashuju/' . $albumsdata_check_filename,FTP_BINARY)){
  1338. //上传成功
  1339. }
  1340. if(ftp_put($conn,$albumsdata_finish_filename,'./dashuju/' . $albumsdata_finish_filename,FTP_BINARY)){
  1341. //上传成功
  1342. }
  1343. if(ftp_put($conn,$videosdata_filename,'./dashuju/' . $videosdata_filename,FTP_BINARY)){
  1344. //上传成功
  1345. }
  1346. if(ftp_put($conn,$videosdata_check_filename,'./dashuju/' . $videosdata_check_filename,FTP_BINARY)){
  1347. //上传成功
  1348. }
  1349. if(ftp_put($conn,$videosdata_finish_filename,'./dashuju/' . $videosdata_finish_filename,FTP_BINARY)){
  1350. //上传成功
  1351. }
  1352. if(ftp_put($conn,$productalbumdata_filename,'./dashuju/' . $productalbumdata_filename,FTP_BINARY)){
  1353. //上传成功
  1354. }
  1355. if(ftp_put($conn,$productalbumdata_check_filename,'./dashuju/' . $productalbumdata_check_filename,FTP_BINARY)){
  1356. //上传成功
  1357. }
  1358. if(ftp_put($conn,$productalbumdata_finish_filename,'./dashuju/' . $productalbumdata_finish_filename,FTP_BINARY)){
  1359. //上传成功
  1360. }
  1361. if(ftp_put($conn,$userefforderdata_filename,'./dashuju/' . $userefforderdata_filename,FTP_BINARY)){
  1362. //上传成功
  1363. }
  1364. if(ftp_put($conn,$userefforderdata_check_filename,'./dashuju/' . $userefforderdata_check_filename,FTP_BINARY)){
  1365. //上传成功
  1366. }
  1367. if(ftp_put($conn,$userefforderdata_finish_filename,'./dashuju/' . $userefforderdata_finish_filename,FTP_BINARY)){
  1368. //上传成功
  1369. }
  1370. if(ftp_put($conn,$userorderdata_filename,'./dashuju/' . $userorderdata_filename,FTP_BINARY)){
  1371. //上传成功
  1372. }
  1373. if(ftp_put($conn,$userorderdata_check_filename,'./dashuju/' . $userorderdata_check_filename,FTP_BINARY)){
  1374. //上传成功
  1375. }
  1376. if(ftp_put($conn,$userorderdata_finish_filename,'./dashuju/' . $userorderdata_finish_filename,FTP_BINARY)){
  1377. //上传成功
  1378. }
  1379. if(ftp_put($conn,$userplaydata_filename,'./dashuju/' . $userplaydata_filename,FTP_BINARY)){
  1380. //上传成功
  1381. }
  1382. if(ftp_put($conn,$userplaydata_check_filename,'./dashuju/' . $userplaydata_check_filename,FTP_BINARY)){
  1383. //上传成功
  1384. }
  1385. if(ftp_put($conn,$userplaydata_finish_filename,'./dashuju/' . $userplaydata_finish_filename,FTP_BINARY)){
  1386. //上传成功
  1387. }
  1388. if(ftp_put($conn,$userfavdata_filename,'./dashuju/' . $userfavdata_filename,FTP_BINARY)){
  1389. //上传成功
  1390. }
  1391. if(ftp_put($conn,$userfavdata_check_filename,'./dashuju/' . $userfavdata_check_filename,FTP_BINARY)){
  1392. //上传成功
  1393. }
  1394. if(ftp_put($conn,$userfavdata_finish_filename,'./dashuju/' . $userfavdata_finish_filename,FTP_BINARY)){
  1395. //上传成功
  1396. }
  1397. ftp_close($conn);
  1398. //注意上传端的ftp权限设置
  1399. echo 'wanbi';
  1400. }
  1401. public function make_directory($ftp_stream, $dir){
  1402. // if directory already exists or can be immediately created return true
  1403. if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true;
  1404. // otherwise recursively try to make the directory
  1405. if (!$this->make_directory($ftp_stream, dirname($dir))) return false;
  1406. // final step to create the directory
  1407. return ftp_mkdir($ftp_stream, $dir);
  1408. }
  1409. public function ftp_is_dir($ftp_stream, $dir){
  1410. // get current directory
  1411. $original_directory = ftp_pwd($ftp_stream);
  1412. // test if you can change directory to $dir
  1413. // suppress errors in case $dir is not a file or not a directory
  1414. if ( @ftp_chdir( $ftp_stream, $dir ) ) {
  1415. // If it is a directory, then change the directory back to the original directory
  1416. ftp_chdir( $ftp_stream, $original_directory );
  1417. return true;
  1418. } else {
  1419. return false;
  1420. }
  1421. }
  1422. }