Notify.php 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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. file_put_contents('chen_tui.txt', $data, FILE_APPEND);
  848. if (!$data) {
  849. $this->error('参数缺失');
  850. }
  851. $jsonxml = json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA));
  852. $data = json_decode($jsonxml, true);
  853. if (!$data) {
  854. $this->error('参数缺失');
  855. }
  856. $phoneNumber = $data['orderRelationSyncRequest']['phoneNumber']; //手机号
  857. $apppId = $data['orderRelationSyncRequest']['apppId']; //订购的HDC业务产品编码
  858. if ($apppId != config('product_code')) {
  859. echo 'meiyou';
  860. exit;
  861. }
  862. //用户增值产品包当前订购快照
  863. $content = [
  864. 'UserID' => $phoneNumber,
  865. 'prod_code' => $apppId,
  866. 'prod_name' => '月包会员',
  867. 'eff_time' => date('Y-m-d H:i:s', time()),
  868. 'exp_time' => date('Y-m-d H:i:s', time() + 30 * 86400),
  869. 'price' => 2900
  870. ];
  871. $content = join(json_decode('"\u0001"', true), $content);
  872. $filename = date('Ymd').'_'.config('data_cp_id').'_userefforderdata_1.dat';
  873. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userefforderdata_1.chk';
  874. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  875. error_log('', 3, './dashuju/' . $check_filename);
  876. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userefforderdata.finish';
  877. error_log('', 3, './dashuju/' . $finish_filename);
  878. //用户增值产品包订购行为数据
  879. $user_id = Db::name('user')->where(['mobile' => $phoneNumber])->value('id');
  880. $order_info = Db::name('rechar_order')->where(['user_id' => $user_id, 'purpose' => 3, 'pay_type' => 'zhuowang', 'status' => 1])->order('id desc')->find();
  881. $content = [
  882. 'orderid' => $order_info['order_no'],
  883. 'order_time' => date('Y-m-d H:i:s', time()),
  884. 'order_type' => 1,
  885. 'UserID' => $phoneNumber,
  886. 'prod_code' => $apppId,
  887. 'prod_name' => '月包会员',
  888. 'eff_time' => date('Y-m-d H:i:s', time()),
  889. 'exp_time' => date('Y-m-d H:i:s', time() + 30 * 86400),
  890. 'csource' => 99,
  891. 'trace_id' => '',
  892. 'price' => 2900,
  893. 'paytype' => 0,
  894. 'cpid' => config('data_cp_id'),
  895. 'albumid' => '',
  896. 'albumname' => ''
  897. ];
  898. $content = join(json_decode('"\u0001"', true), $content);
  899. $filename = date('Ymd').'_'.config('data_cp_id').'_userorderdata_1.dat';
  900. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userorderdata_1.chk';
  901. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  902. error_log('', 3, './dashuju/' . $check_filename);
  903. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userorderdata.finish';
  904. error_log('', 3, './dashuju/' . $finish_filename);
  905. }
  906. //(补漏)视频注入中兴
  907. public function injectzx() {
  908. set_time_limit(0);
  909. $hu_video = Db::name('video');
  910. $list = $hu_video->where(['id' => 107])->limit(50)->select();
  911. if (!$list) {
  912. echo 'mei shu ju';
  913. die;
  914. }
  915. $cspid = config('cspid_zx');
  916. $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
  917. foreach ($list as &$params) {
  918. //内容同步
  919. $videofile = $params['videofile'];
  920. $videofile = explode('/', $videofile);
  921. $video_url = $videofile[3];
  922. $data = [
  923. // 'cspId' => $cspid,
  924. 'cpAlbumId' => $params['id'],
  925. 'albumName' => $params['title'],
  926. 'tvSets' => 1,
  927. 'updateToSet' => 1,
  928. 'isPurchase' => $params['is_pay'],
  929. 'isEffective' => $params['status'],
  930. 'isOnline' => $params['status'],
  931. 'albumTypes' => '健康',
  932. 'picBox' => config('upload.cdnurl') . $params['image'],
  933. 'albumUpdateTime' => date('YmdHis', time()),
  934. 'albumCreateTime' => date('YmdHis', time()),
  935. 'tvlist' => [
  936. [
  937. 'cpAlbumId' => $params['id'],
  938. 'cpTvId' => $params['id'],
  939. 'tvName' => $params['title'],
  940. 'tvIsEffective' => $params['status'],
  941. 'tvIsOnline' => $params['status'],
  942. 'isPurchase' => $params['is_pay'],
  943. 'playOrder' => 1,
  944. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  945. ]
  946. ]
  947. ];
  948. $data = json_encode($data, 320);
  949. $header = [
  950. 'Content-Type: application/json'
  951. ];
  952. $rs = httpRequest($url, 'POST', $data, $header);
  953. if ($rs) {
  954. $rs = json_decode($rs, true);
  955. if ($rs['code'] != 'A000000') {
  956. continue;
  957. }
  958. }
  959. }
  960. echo 'wan bi';
  961. die;
  962. }
  963. //(补漏)删除注入中兴视频
  964. public function delinjectzx() {
  965. set_time_limit(0);
  966. $hu_video = Db::name('video');
  967. $list = $hu_video->where(['id' => 107])->limit(1)->order('id')->select();
  968. if (!$list) {
  969. echo 'mei shu ju';
  970. die;
  971. }
  972. $cspid = config('cspid_zx');
  973. $url = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . $cspid . '/';
  974. foreach ($list as &$params) {
  975. //内容同步
  976. $videofile = $params['videofile'];
  977. $videofile = explode('/', $videofile);
  978. $video_url = $videofile[3];
  979. $data = [
  980. // 'cspId' => $cspid,
  981. 'cpAlbumId' => $params['id'],
  982. 'albumName' => $params['title'],
  983. 'tvSets' => 1,
  984. 'updateToSet' => 1,
  985. 'isPurchase' => $params['is_pay'],
  986. 'isEffective' => 0,
  987. 'isOnline' => 2,
  988. 'albumTypes' => '健康',
  989. 'picBox' => config('upload.cdnurl') . $params['image'],
  990. 'albumUpdateTime' => date('YmdHis', time()),
  991. // 'albumCreateTime' => date('YmdHis', time()),
  992. 'tvlist' => [
  993. [
  994. 'cpAlbumId' => $params['id'],
  995. 'cpTvId' => $params['id'],
  996. 'tvName' => $params['title'],
  997. 'tvIsEffective' => 0,
  998. 'tvIsOnline' => 2,
  999. 'isPurchase' => $params['is_pay'],
  1000. 'playOrder' => 1,
  1001. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  1002. ]
  1003. ]
  1004. ];
  1005. $data = json_encode($data, 320);
  1006. $header = [
  1007. 'Content-Type: application/json'
  1008. ];
  1009. $rs = httpRequest($url, 'POST', $data, $header);
  1010. if ($rs) {
  1011. $rs = json_decode($rs, true);
  1012. if ($rs['code'] != 'A000000') {
  1013. continue;
  1014. }
  1015. }
  1016. }
  1017. echo 'wan bi';
  1018. die;
  1019. }
  1020. //媒资数据专辑粒度
  1021. public function mediadataalbum() {
  1022. $hu_video = Db::name('video');
  1023. $list = $hu_video->where(['inject_status' => 2, 'mediaalbum_status' => 0])->order('id')->select();
  1024. if (!$list) {
  1025. echo 'mei shu ju';
  1026. die;
  1027. }
  1028. foreach ($list as $key => &$param) {
  1029. $content = [
  1030. 'Updatetype' => 1,
  1031. 'cpid' => config('data_cp_id'),
  1032. 'channelid' => '1000035',
  1033. 'albumid' => $param['id'],
  1034. 'albumname' => $param['title'],
  1035. 'albumnum' => 1,
  1036. 'tag' => '',
  1037. 'onlinetime' => '',
  1038. 'bref' => '',
  1039. 'onebref' => '',
  1040. 'cornersign' => $param['is_pay'],
  1041. 'director' => '',
  1042. 'actor' => '',
  1043. 'year' => '',
  1044. 'area' => '',
  1045. 'language' => '',
  1046. 'score' => '',
  1047. 'picurl' => config('upload.cdnurl') . $param['image'],
  1048. 'picurl_v' => '',
  1049. 'gotourl' => json_encode([
  1050. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  1051. 'package' => 'com.huxiu.heh.tv',
  1052. 'component' => [
  1053. 'pkg' => 'com.huxiu.heh.tv',
  1054. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  1055. ],
  1056. 'extras' => [
  1057. // 'cmd' => '',
  1058. // 'from' => '',
  1059. // 'media_id' => ''
  1060. 'type_id' => $param['video_type_id'],
  1061. 'id' => $param['id']
  1062. ]
  1063. ], 320),
  1064. 'is_politics' => '',
  1065. 'second_type' => ''
  1066. ];
  1067. $content = join(json_decode('"\u0001"', true), $content);
  1068. $filename = date('Ymd').'_'.config('data_cp_id').'_albumsdata_1.dat';
  1069. $check_filename = date('Ymd').'_'.config('data_cp_id').'_albumsdata_1.chk';
  1070. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1071. error_log('', 3, './dashuju/' . $check_filename);
  1072. if ($key == count($list) - 1) {
  1073. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_albumsdata.finish';
  1074. error_log('', 3, './dashuju/' . $finish_filename);
  1075. }
  1076. $hu_video->where(['id' => $param['id'], 'mediaalbum_status' => 0])->setField('mediaalbum_status', 1);
  1077. }
  1078. echo 'wan bi';
  1079. }
  1080. //媒资数据节目/内容粒度
  1081. public function mediadatavideo() {
  1082. $hu_video = Db::name('video');
  1083. $list = $hu_video->where(['inject_status' => 2, 'mediavideo_status' => 0])->order('id')->select();
  1084. if (!$list) {
  1085. echo 'mei shu ju';
  1086. die;
  1087. }
  1088. foreach ($list as $key => &$param) {
  1089. $content = [
  1090. 'Updatetype' => 1,
  1091. 'cpid' => config('data_cp_id'),
  1092. 'channelid' => '1000035',
  1093. 'albumid' => $param['id'],
  1094. 'albumname' => $param['title'],
  1095. 'videoid' => $param['id'],
  1096. 'videoname' => $param['title'],
  1097. 'videonum' => 1,
  1098. 'Contenttype' => 1,
  1099. 'duration' => '',
  1100. 'quality' => ''
  1101. ];
  1102. $content = join(json_decode('"\u0001"', true), $content);
  1103. $filename = date('Ymd').'_'.config('data_cp_id').'_videosdata_1.dat';
  1104. $check_filename = date('Ymd').'_'.config('data_cp_id').'_videosdata_1.chk';
  1105. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1106. error_log('', 3, './dashuju/' . $check_filename);
  1107. if ($key == count($list) - 1) {
  1108. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_videosdata.finish';
  1109. error_log('', 3, './dashuju/' . $finish_filename);
  1110. }
  1111. $hu_video->where(['id' => $param['id'], 'mediavideo_status' => 0])->setField('mediavideo_status', 1);
  1112. }
  1113. }
  1114. //产品包
  1115. public function product() {
  1116. $content = [
  1117. 'prod_code' => config('product_code'),
  1118. 'prod_name' => '月包会员',
  1119. 'prod_type' => 0,
  1120. 'cpid' => config('data_cp_id')
  1121. ];
  1122. $content = join(json_decode('"\u0001"', true), $content);
  1123. $filename = date('Ymd').'_'.config('data_cp_id').'_productsdata_1.dat';
  1124. $check_filename = date('Ymd').'_'.config('data_cp_id').'_productsdata_1.chk';
  1125. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1126. error_log('', 3, './dashuju/' . $check_filename);
  1127. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_productsdata.finish';
  1128. error_log('', 3, './dashuju/' . $finish_filename);
  1129. //连接ftp
  1130. $host = config('data_ftp_ip');
  1131. $port = config('data_ftp_port');
  1132. $username = config('data_ftp_user');
  1133. $password = config('data_ftp_pwd');
  1134. $conn = ftp_connect($host, $port) or die("Could not connect");
  1135. //登录
  1136. ftp_login($conn,$username,$password);
  1137. //开启被动模式
  1138. ftp_pasv($conn, true);
  1139. //利用ftp创建目录
  1140. /*$path = "home/2021-12-08";
  1141. $this->make_directory($conn,$path);
  1142. //利用ftp选择进入目录
  1143. ftp_chdir($conn,$path);*/
  1144. //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
  1145. if(ftp_put($conn,$filename,'./dashuju/' . $filename,FTP_BINARY)){
  1146. //上传成功
  1147. }
  1148. if(ftp_put($conn,$check_filename,'./dashuju/' . $check_filename,FTP_BINARY)){
  1149. //上传成功
  1150. }
  1151. if(ftp_put($conn,$finish_filename,'./dashuju/' . $finish_filename,FTP_BINARY)){
  1152. //上传成功
  1153. }
  1154. ftp_close($conn);
  1155. //注意上传端的ftp权限设置
  1156. echo 'wanbi';
  1157. }
  1158. //产品包和媒资所属关系
  1159. public function productmediarelation() {
  1160. $hu_video = Db::name('video');
  1161. $list = $hu_video->where(['inject_status' => 2, 'productmedia_status' => 0])->order('id')->select();
  1162. if (!$list) {
  1163. echo 'mei shu ju';
  1164. die;
  1165. }
  1166. foreach ($list as $key => &$param) {
  1167. $content = [
  1168. 'Updatetype' => 1,
  1169. 'prod_code' => config('product_code'),
  1170. 'cpid' => config('data_cp_id'),
  1171. 'albumid' => $param['id']
  1172. ];
  1173. $content = join(json_decode('"\u0001"', true), $content);
  1174. $filename = date('Ymd').'_'.config('data_cp_id').'_productalbumdata_1.dat';
  1175. $check_filename = date('Ymd').'_'.config('data_cp_id').'_productalbumdata_1.chk';
  1176. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1177. error_log('', 3, './dashuju/' . $check_filename);
  1178. if ($key == count($list) - 1) {
  1179. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_productalbumdata.finish';
  1180. error_log('', 3, './dashuju/' . $finish_filename);
  1181. }
  1182. $hu_video->where(['id' => $param['id'], 'productmedia_status' => 0])->setField('productmedia_status', 1);
  1183. }
  1184. }
  1185. //用户观看行为数据文件上传到卓望ftp(每小时第10分钟提供)
  1186. public function uploadpayftp() {
  1187. set_time_limit(0);
  1188. $host = config('pay_ftp_ip');
  1189. $port = config('pay_ftp_port');
  1190. $username = config('pay_ftp_user');
  1191. $password = config('pay_ftp_pwd');
  1192. $filename = date('YmdH', time() - 3600).'_'.config('cp_id').'_userviewdata_1.dat';
  1193. $check_filename = date('YmdH', time() - 3600).'_'.config('cp_id').'_userviewdata_1.chk';
  1194. //判断文件是否存在, 不存在则创建
  1195. if (!file_exists('./dashuju/' . $filename)) {
  1196. @touch('./dashuju/' . $filename);
  1197. }
  1198. if (!file_exists('./dashuju/' . $check_filename)) {
  1199. @touch('./dashuju/' . $check_filename);
  1200. }
  1201. //连接ftp
  1202. $conn = ftp_connect($host, $port) or die("Could not connect");
  1203. //登录
  1204. ftp_login($conn,$username,$password);
  1205. //开启被动模式
  1206. ftp_pasv($conn, true);
  1207. //利用ftp创建目录
  1208. /*$path = "home/2021-12-08";
  1209. $this->make_directory($conn,$path);
  1210. //利用ftp选择进入目录
  1211. ftp_chdir($conn,$path);*/
  1212. //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
  1213. if(ftp_put($conn,$filename,'./dashuju/' . $filename,FTP_BINARY)){
  1214. //上传成功
  1215. }
  1216. if(ftp_put($conn,$check_filename,'./dashuju/' . $check_filename,FTP_BINARY)){
  1217. //上传成功
  1218. }
  1219. ftp_close($conn);
  1220. //注意上传端的ftp权限设置
  1221. echo 'wanbi';
  1222. }
  1223. //大数据文件上传到大数据ftp(每天一点提供)
  1224. public function uploaddataftp() {
  1225. set_time_limit(0);
  1226. $host = config('data_ftp_ip');
  1227. $port = config('data_ftp_port');
  1228. $username = config('data_ftp_user');
  1229. $password = config('data_ftp_pwd');
  1230. $time = date('Ymd', time() - 86400);
  1231. // 专辑粒度媒资
  1232. $albumsdata_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.dat';
  1233. $albumsdata_check_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.chk';
  1234. $albumsdata_finish_filename = $time.'_'.config('data_cp_id').'_albumsdata_1.finish';
  1235. // 节目/内容粒度媒资
  1236. $videosdata_filename = $time.'_'.config('data_cp_id').'_videosdata_1.dat';
  1237. $videosdata_check_filename = $time.'_'.config('data_cp_id').'_videosdata_1.chk';
  1238. $videosdata_finish_filename = $time.'_'.config('data_cp_id').'_videosdata_1.finish';
  1239. // 产品包和媒资所属关系
  1240. $productalbumdata_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.dat';
  1241. $productalbumdata_check_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.chk';
  1242. $productalbumdata_finish_filename = $time.'_'.config('data_cp_id').'_productalbumdata_1.finish';
  1243. // 用户增值产品包当前订购快照
  1244. $userefforderdata_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.dat';
  1245. $userefforderdata_check_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.chk';
  1246. $userefforderdata_finish_filename = $time.'_'.config('data_cp_id').'_userefforderdata_1.finish';
  1247. // 用户增值产品包订购行为
  1248. $userorderdata_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.dat';
  1249. $userorderdata_check_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.chk';
  1250. $userorderdata_finish_filename = $time.'_'.config('data_cp_id').'_userorderdata_1.finish';
  1251. // 用户观看行为
  1252. $userplaydata_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.dat';
  1253. $userplaydata_check_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.chk';
  1254. $userplaydata_finish_filename = $time.'_'.config('data_cp_id').'_userplaydata_1.finish';
  1255. // 用户收藏行为
  1256. $userfavdata_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.dat';
  1257. $userfavdata_check_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.chk';
  1258. $userfavdata_finish_filename = $time.'_'.config('data_cp_id').'_userfavdata_1.finish';
  1259. //判断文件是否存在, 不存在则创建
  1260. if (!file_exists('./dashuju/' . $albumsdata_filename)) {
  1261. @touch('./dashuju/' . $albumsdata_filename);
  1262. }
  1263. if (!file_exists('./dashuju/' . $albumsdata_check_filename)) {
  1264. @touch('./dashuju/' . $albumsdata_check_filename);
  1265. }
  1266. if (!file_exists('./dashuju/' . $albumsdata_finish_filename)) {
  1267. @touch('./dashuju/' . $albumsdata_finish_filename);
  1268. }
  1269. if (!file_exists('./dashuju/' . $videosdata_filename)) {
  1270. @touch('./dashuju/' . $videosdata_filename);
  1271. }
  1272. if (!file_exists('./dashuju/' . $videosdata_check_filename)) {
  1273. @touch('./dashuju/' . $videosdata_check_filename);
  1274. }
  1275. if (!file_exists('./dashuju/' . $videosdata_finish_filename)) {
  1276. @touch('./dashuju/' . $videosdata_finish_filename);
  1277. }
  1278. if (!file_exists('./dashuju/' . $productalbumdata_filename)) {
  1279. @touch('./dashuju/' . $productalbumdata_filename);
  1280. }
  1281. if (!file_exists('./dashuju/' . $productalbumdata_check_filename)) {
  1282. @touch('./dashuju/' . $productalbumdata_check_filename);
  1283. }
  1284. if (!file_exists('./dashuju/' . $productalbumdata_finish_filename)) {
  1285. @touch('./dashuju/' . $productalbumdata_finish_filename);
  1286. }
  1287. if (!file_exists('./dashuju/' . $userefforderdata_filename)) {
  1288. @touch('./dashuju/' . $userefforderdata_filename);
  1289. }
  1290. if (!file_exists('./dashuju/' . $userefforderdata_check_filename)) {
  1291. @touch('./dashuju/' . $userefforderdata_check_filename);
  1292. }
  1293. if (!file_exists('./dashuju/' . $userefforderdata_finish_filename)) {
  1294. @touch('./dashuju/' . $userefforderdata_finish_filename);
  1295. }
  1296. if (!file_exists('./dashuju/' . $userorderdata_filename)) {
  1297. @touch('./dashuju/' . $userorderdata_filename);
  1298. }
  1299. if (!file_exists('./dashuju/' . $userorderdata_check_filename)) {
  1300. @touch('./dashuju/' . $userorderdata_check_filename);
  1301. }
  1302. if (!file_exists('./dashuju/' . $userorderdata_finish_filename)) {
  1303. @touch('./dashuju/' . $userorderdata_finish_filename);
  1304. }
  1305. if (!file_exists('./dashuju/' . $userplaydata_filename)) {
  1306. @touch('./dashuju/' . $userplaydata_filename);
  1307. }
  1308. if (!file_exists('./dashuju/' . $userplaydata_check_filename)) {
  1309. @touch('./dashuju/' . $userplaydata_check_filename);
  1310. }
  1311. if (!file_exists('./dashuju/' . $userplaydata_finish_filename)) {
  1312. @touch('./dashuju/' . $userplaydata_finish_filename);
  1313. }
  1314. if (!file_exists('./dashuju/' . $userfavdata_filename)) {
  1315. @touch('./dashuju/' . $userfavdata_filename);
  1316. }
  1317. if (!file_exists('./dashuju/' . $userfavdata_check_filename)) {
  1318. @touch('./dashuju/' . $userfavdata_check_filename);
  1319. }
  1320. if (!file_exists('./dashuju/' . $userfavdata_finish_filename)) {
  1321. @touch('./dashuju/' . $userfavdata_finish_filename);
  1322. }
  1323. //连接ftp
  1324. $conn = ftp_connect($host, $port) or die("Could not connect");
  1325. //登录
  1326. ftp_login($conn,$username,$password);
  1327. //开启被动模式
  1328. ftp_pasv($conn, true);
  1329. //利用ftp创建目录
  1330. /*$path = "home/2021-12-08";
  1331. $this->make_directory($conn,$path);
  1332. //利用ftp选择进入目录
  1333. ftp_chdir($conn,$path);*/
  1334. //开始上传 ftp_put(ftp链接,服务器地址,本地地址,上传模式);
  1335. if(ftp_put($conn,$albumsdata_filename,'./dashuju/' . $albumsdata_filename,FTP_BINARY)){
  1336. //上传成功
  1337. }
  1338. if(ftp_put($conn,$albumsdata_check_filename,'./dashuju/' . $albumsdata_check_filename,FTP_BINARY)){
  1339. //上传成功
  1340. }
  1341. if(ftp_put($conn,$albumsdata_finish_filename,'./dashuju/' . $albumsdata_finish_filename,FTP_BINARY)){
  1342. //上传成功
  1343. }
  1344. if(ftp_put($conn,$videosdata_filename,'./dashuju/' . $videosdata_filename,FTP_BINARY)){
  1345. //上传成功
  1346. }
  1347. if(ftp_put($conn,$videosdata_check_filename,'./dashuju/' . $videosdata_check_filename,FTP_BINARY)){
  1348. //上传成功
  1349. }
  1350. if(ftp_put($conn,$videosdata_finish_filename,'./dashuju/' . $videosdata_finish_filename,FTP_BINARY)){
  1351. //上传成功
  1352. }
  1353. if(ftp_put($conn,$productalbumdata_filename,'./dashuju/' . $productalbumdata_filename,FTP_BINARY)){
  1354. //上传成功
  1355. }
  1356. if(ftp_put($conn,$productalbumdata_check_filename,'./dashuju/' . $productalbumdata_check_filename,FTP_BINARY)){
  1357. //上传成功
  1358. }
  1359. if(ftp_put($conn,$productalbumdata_finish_filename,'./dashuju/' . $productalbumdata_finish_filename,FTP_BINARY)){
  1360. //上传成功
  1361. }
  1362. if(ftp_put($conn,$userefforderdata_filename,'./dashuju/' . $userefforderdata_filename,FTP_BINARY)){
  1363. //上传成功
  1364. }
  1365. if(ftp_put($conn,$userefforderdata_check_filename,'./dashuju/' . $userefforderdata_check_filename,FTP_BINARY)){
  1366. //上传成功
  1367. }
  1368. if(ftp_put($conn,$userefforderdata_finish_filename,'./dashuju/' . $userefforderdata_finish_filename,FTP_BINARY)){
  1369. //上传成功
  1370. }
  1371. if(ftp_put($conn,$userorderdata_filename,'./dashuju/' . $userorderdata_filename,FTP_BINARY)){
  1372. //上传成功
  1373. }
  1374. if(ftp_put($conn,$userorderdata_check_filename,'./dashuju/' . $userorderdata_check_filename,FTP_BINARY)){
  1375. //上传成功
  1376. }
  1377. if(ftp_put($conn,$userorderdata_finish_filename,'./dashuju/' . $userorderdata_finish_filename,FTP_BINARY)){
  1378. //上传成功
  1379. }
  1380. if(ftp_put($conn,$userplaydata_filename,'./dashuju/' . $userplaydata_filename,FTP_BINARY)){
  1381. //上传成功
  1382. }
  1383. if(ftp_put($conn,$userplaydata_check_filename,'./dashuju/' . $userplaydata_check_filename,FTP_BINARY)){
  1384. //上传成功
  1385. }
  1386. if(ftp_put($conn,$userplaydata_finish_filename,'./dashuju/' . $userplaydata_finish_filename,FTP_BINARY)){
  1387. //上传成功
  1388. }
  1389. if(ftp_put($conn,$userfavdata_filename,'./dashuju/' . $userfavdata_filename,FTP_BINARY)){
  1390. //上传成功
  1391. }
  1392. if(ftp_put($conn,$userfavdata_check_filename,'./dashuju/' . $userfavdata_check_filename,FTP_BINARY)){
  1393. //上传成功
  1394. }
  1395. if(ftp_put($conn,$userfavdata_finish_filename,'./dashuju/' . $userfavdata_finish_filename,FTP_BINARY)){
  1396. //上传成功
  1397. }
  1398. ftp_close($conn);
  1399. //注意上传端的ftp权限设置
  1400. echo 'wanbi';
  1401. }
  1402. public function make_directory($ftp_stream, $dir){
  1403. // if directory already exists or can be immediately created return true
  1404. if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true;
  1405. // otherwise recursively try to make the directory
  1406. if (!$this->make_directory($ftp_stream, dirname($dir))) return false;
  1407. // final step to create the directory
  1408. return ftp_mkdir($ftp_stream, $dir);
  1409. }
  1410. public function ftp_is_dir($ftp_stream, $dir){
  1411. // get current directory
  1412. $original_directory = ftp_pwd($ftp_stream);
  1413. // test if you can change directory to $dir
  1414. // suppress errors in case $dir is not a file or not a directory
  1415. if ( @ftp_chdir( $ftp_stream, $dir ) ) {
  1416. // If it is a directory, then change the directory back to the original directory
  1417. ftp_chdir( $ftp_stream, $original_directory );
  1418. return true;
  1419. } else {
  1420. return false;
  1421. }
  1422. }
  1423. }