SoftController.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class SoftController extends DooController {
  6. public $webPath="http://cld.smartcost.com.cn/upload/emailAnnex/";
  7. function __construct() {
  8. }
  9. function longleTest(){
  10. $this->render ( "/test", array() );
  11. }
  12. function categoryApi(){
  13. Doo::loadModel ( 'L_category' );
  14. $L_category = new L_category ();
  15. $category=$L_category->getCategoryBySoft();
  16. header ( 'Content-Type:text/html;charset=utf-8' );
  17. echo json_encode(array('status'=>1,'categoryList'=>$category),JSON_UNESCAPED_UNICODE);die;
  18. }
  19. function productApi(){
  20. Doo::loadModel ( 'product' );
  21. $product = new product ();
  22. $product=$product->getProudct();
  23. header ( 'Content-Type:text/html;charset=utf-8' );
  24. echo json_encode(array('status'=>1,'productList'=>$product),JSON_UNESCAPED_UNICODE);die;
  25. }
  26. function addLockApi(){
  27. $longleList=isset($_POST['longle'])?$_POST['longle']:"";
  28. //echo $longleList.'dddd';die;
  29. header ( 'Content-Type:text/html;charset=utf-8' );
  30. if($longleList!=""){
  31. Doo::loadModel ( 'longle' );
  32. Doo::loadModel ( 'longle_log' );
  33. //$exlArray=$this->_format_excel_to_array(DOO::conf()->SITE_PATH."upload/".iconv("UTF-8", "GB2312", $path));
  34. //file_put_contents ( "protected/config/longle.bak", $longleList );
  35. $longleList=json_decode($longleList,TRUE);
  36. if (!is_array($longleList)){
  37. echo json_encode(array('status'=>2,'msg'=>'锁数据不正确'),JSON_UNESCAPED_UNICODE);die;
  38. }
  39. //数组格式化,新增字段需要在这新增
  40. $longleList=$this->array_unique_fb($longleList);
  41. //$category=$L_category->getCategoryById($cid);
  42. try {
  43. Doo::db()->beginTransaction();
  44. foreach ($longleList as $key=>$value){
  45. //锁记录
  46. $longle = new longle ();
  47. $longle->key_num=$value['key_num'];
  48. $longle->product=$value['product'];
  49. $longle->make_day=$value['make_day'];
  50. $longle->alloted_time=$value['alloted_time'];
  51. $longle->status=1;
  52. $longle->statusT="生成";
  53. $longle->cid=$value['cid'];
  54. $longle->category=$value['title'];
  55. $longle->SerialNumber=$value['serialnumber'];
  56. $longle->version=$value['version'];
  57. $longle->licences=$value['licences'];
  58. $lid=$longle->insert();
  59. //锁日志记录
  60. $longle_log=new longle_log();
  61. $longle_log->lid=$lid;
  62. $longle_log->status=1;
  63. $longle_log->statusT="生成";
  64. $longle_log->operator='软件生成';
  65. $longle_log->product=$longle->product;
  66. $longle_log->category='总部';
  67. $longle_log->dateline=date("Y-m-d");
  68. $id=$longle_log->insert();
  69. }
  70. //记录日常行为
  71. Doo::loadModel("action_log");
  72. $action_log=new action_log();
  73. $action_log->action='总部<b href="javascript:void(0)" >软件</b>生成<a href="javascript:void(0)" onclick="showLook(\''.$longleList[0]['key_num'].'\')">'.$longleList[0]['key_num'].'</a>等<b>'.count($longleList).'</b>个锁';
  74. $action_log->sid=43;
  75. $action_log->cid=12;
  76. $action_log->class=$action_log->iconGenerate;
  77. $action_log->updatetime=date("Y-m-d");
  78. $action_log->time=date("H:i");
  79. $action_log->status=11;
  80. $action_log->insert();
  81. Doo::db()->commit();
  82. } catch (Exception $e) {
  83. echo json_encode(array('status'=>2,'msg'=>'数据录入发生异常'),JSON_UNESCAPED_UNICODE);
  84. //print $e->getMessage();
  85. die;
  86. }
  87. echo json_encode(array('status'=>1,'msg'=>'入库'.count($longleList).'个'),JSON_UNESCAPED_UNICODE);die;
  88. }else{
  89. echo json_encode(array('status'=>2,'msg'=>'请求参数不正确或者为空'),JSON_UNESCAPED_UNICODE);die;
  90. }
  91. }
  92. function updateLockApi(){
  93. /* $serialnumber = $this->get_args ( 'serialnumber' ) ? $this->get_args ( 'serialnumber' ) : "";
  94. $alloted_time = $this->get_args ( 'alloted_time' ) ? $this->get_args ( 'alloted_time' ) : '';
  95. $product = $this->get_args ( 'product' ) ? $this->get_args ( 'product' ) : "";
  96. //$status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 0;//5升级 10延期
  97. $UpdateStr = $this->get_args ( 'UpdateStr' ) ? $this->get_args ( 'UpdateStr' ) : "";
  98. $UpdateFile = $this->get_args ( 'UpdateFile' ) ? $this->get_args ( 'UpdateFile' ) : "";
  99. $AuthorizeStr = $this->get_args ( 'AuthorizeStr' ) ? $this->get_args ( 'AuthorizeStr' ) : "";
  100. $AuthorizeFile = $this->get_args ( 'AuthorizeFile' ) ? $this->get_args ( 'AuthorizeFile' ) : "";
  101. $version = $this->get_args ( 'version' ) ? $this->get_args ( 'version' ) : "";
  102. $licences = $this->get_args ( 'licences' ) ? $this->get_args ( 'licences' ) : ""; */
  103. $longleList=isset($_POST['longle'])?$_POST['longle']:"";
  104. //$longleList='[{"serialnumber":"168600076BAA3300","product":"全国专业+固化清单全功能+广东专业+全国项目专业+内蒙养护+定额排版+贵州标后预算+广东项目专业+标后预算+广东算量+结算决算-全功能+全国算量+全国专业(新定额)+广东专业","alloted_time":"","version":"","licences":"","UpdateStr":"0E5343205570646174652046696C655C53634C6F630A000000000100002B305E9593E44844FE8FAC07873FF470D991DDEC5D6828EBF41F373588739F5C18D13441D73894F6BD6C430BBE6E167AC62554F6997CA615B5A13E5DFC7AF2D60A1AA47820FA2ED268100ED71072943393C8B75D3314D074DE9798FF75F80E7AE562AEC80E022189B518C84ABC7D68F01DF1BA532ED68FDC77BE9BAC4A15B4D144CAD0CE4880D94CEBA12C409006C0DAD2B65E2AACDFE9425EEB4E95CF08027308FAB81DFA8CFE9BD8AC95D3602B439CE41BBB38CA9E8378D1C7229320ACA1545F0705E8B34DB048E7C12E68145F1A961D12442801897FC7FCFBF311AACC242C17F318AADE449B5F8A61A1C657304D74B385D99B7A69CE957CF2D36F138A681E","length":"285","key_num":"SC-Z11051"}]';//
  105. //print_r($longleList);
  106. file_put_contents ( "protected/config/longle.bak", $longleList );
  107. $longleList=json_decode($longleList,TRUE);
  108. // $file=isset($_POST['file'])?$_POST['file']:"";
  109. // file_put_contents("protected/config/sites.txt",$file);
  110. header ( 'Content-Type:text/html;charset=utf-8' );
  111. if (!is_array($longleList)){
  112. echo json_encode(array('status'=>2,'msg'=>'锁数据不正确'),JSON_UNESCAPED_UNICODE);die;
  113. }
  114. //数组格式化,新增字段需要在这新增
  115. //$longleList=$this->array_unique_update($longleList);
  116. $serialnumber=$longleList[0]['serialnumber'];
  117. $alloted_time=$longleList[0]['alloted_time'];
  118. $product=$longleList[0]['product'];
  119. $UpdateStr=$longleList[0]['UpdateStr'];
  120. $UpdateFile='';//$longleList[0]['UpdateFile'];
  121. $AuthorizeStr='';//$longleList[0]['AuthorizeStr'];
  122. $AuthorizeFile='';//$longleList[0]['AuthorizeFile'];
  123. $version=$longleList[0]['version'];
  124. $licences=$longleList[0]['licences'];
  125. $length=$longleList[0]['length'];
  126. $key_num='';
  127. if(isset($longleList[0]['key_num'])) {
  128. $key_num=$longleList[0]['key_num'];
  129. }
  130. Doo::loadModel ( 'longle' );
  131. $longle = new longle ();
  132. if (empty($serialnumber)){
  133. echo json_encode(array('status'=>2,'msg'=>'未找到该锁信息-serialnumber'),JSON_UNESCAPED_UNICODE);
  134. die;
  135. }
  136. if(!empty($key_num)){
  137. $linfo = $longle->getLongleByKeyNumDetail( $key_num,$serialnumber );
  138. }else{
  139. $linfo = $longle->getLongleBySerialNumber( $serialnumber );
  140. }
  141. //$linfo = $longle->getLongleBySerialNumber( $serialnumber );
  142. if (empty($linfo)){
  143. echo json_encode(array('status'=>2,'msg'=>'未找到该锁信息-serialnumber2'),JSON_UNESCAPED_UNICODE);
  144. die;
  145. }
  146. $save_path = DOO::conf ()->SITE_PATH . "upload/longle/";
  147. $webSite = '/upload/longle/';
  148. $file_name = $linfo['key_num'].' - '.$serialnumber.'.' . $this->_GetFileEXT ( $_FILES ["file"] ['name'] );
  149. if (! @move_uploaded_file ( $_FILES ["file"] ["tmp_name"], $save_path . $file_name )){
  150. echo json_encode(array('status'=>2,'msg'=>'未找到上传文件'),JSON_UNESCAPED_UNICODE);die;
  151. }else{
  152. $UpdateFile = $webSite . $file_name;
  153. }
  154. $strFile=file_get_contents($save_path . $file_name);
  155. $strFile=substr($strFile , 0 , $length);
  156. file_put_contents($save_path . $file_name,$strFile);
  157. Doo::loadModel ( 'longle_log' );
  158. $longle_log = new longle_log ();
  159. Doo::loadModel ( 'client' );
  160. $clientobj = new client ();
  161. Doo::loadModel ( "action_log" );
  162. if ($product != ""){
  163. $longle->product = $product;
  164. }
  165. $longle->statusT = "升级";
  166. $longle_log->product = $product;
  167. $longle_log->statusT = "升级";
  168. $longle_log->client = $linfo ['client'];
  169. $longle_log->clientid = $linfo ['clientid'];
  170. $clientname = $clientobj->getOne ( array (
  171. 'where' => "cid= '" . $linfo ['clientid'] . "'",
  172. 'asArray' => TRUE
  173. ) );
  174. // 日常行为
  175. $action_log = new action_log ();
  176. $action_log->action = '软件 为<a href="javascript:void(0)" onclick="showClick(\'' . $linfo ['clientid'] . '\')">' . $linfo ['client'] . '</a>(' . $clientname ['companyname'] . ')升级为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a>';
  177. $action_log->sid = 32;
  178. $action_log->cid = 12;
  179. $action_log->updatetime = date ( "Y-m-d" );
  180. $action_log->time = date ( "H:i" );
  181. $action_log->class = $action_log->iconUpdate;
  182. $action_log->status = 7;
  183. $action_log->insert ();
  184. if(!empty($alloted_time)){
  185. $longle->alloted_time = $alloted_time;
  186. }
  187. if(!empty($version)){
  188. $longle->version=$version;
  189. }
  190. if(!empty($licences)){
  191. $longle->licences=$licences;
  192. }
  193. if(!empty($AuthorizeStr)){
  194. $longle->AuthorizeStr=$AuthorizeStr;
  195. }
  196. if(!empty($AuthorizeFile)){
  197. $longle->AuthorizeFile=$AuthorizeFile;
  198. }
  199. if(!empty($UpdateStr)){
  200. $longle->UpdateStr=$UpdateStr;
  201. }
  202. if(!empty($UpdateFile)){
  203. $longle->UpdateFile=$UpdateFile;
  204. }
  205. $longle->status = 5;
  206. $longle->lid = $linfo['lid'];
  207. $longle->update ();
  208. $longle_log->lid = $linfo['lid'];
  209. $longle_log->status = 5;
  210. $longle_log->operator = '软件';
  211. // 责任人
  212. $longle_log->category = '总部';
  213. $longle_log->dateline = date ( "Y-m-d" );
  214. $longle_log->insert ();
  215. echo json_encode(array('status'=>1,'msg'=>'变更成功'),JSON_UNESCAPED_UNICODE);
  216. die;
  217. }
  218. function longleBySerialnumber(){
  219. //$longleList=isset($_POST['longle'])?$_POST['longle']:'{"serialnumber":"1657000186160000"}';
  220. $longleList=isset($_POST['longle'])?$_POST['longle']:'';
  221. //file_put_contents ( "protected/config/longle2.bak", $longleList );
  222. $longleList=json_decode($longleList,TRUE);
  223. header ( 'Content-Type:text/html;charset=utf-8' );
  224. if (!is_array($longleList)){
  225. echo json_encode(array('status'=>2,'msg'=>'JSON结构不正确'),JSON_UNESCAPED_UNICODE);die;
  226. }
  227. $serialnumber=$longleList['serialnumber'];
  228. Doo::loadModel ( 'longle' );
  229. $longle = new longle ();
  230. $list = $longle->getLongleBySerialNumberList( $serialnumber );
  231. if (empty($list)){
  232. echo json_encode(array('status'=>2,'msg'=>'为找到该序列号'.$serialnumber.'相关的锁信息'),JSON_UNESCAPED_UNICODE);die;
  233. }
  234. header ( 'Content-Type:text/html;charset=utf-8' );
  235. echo json_encode(array('status'=>1,'longleList'=>$list),JSON_UNESCAPED_UNICODE);die;
  236. }
  237. function syncLongleData(){
  238. //$longleList='{"serialnumber":"1676000455CBB200","licences":"0","version":"","AuthorizeStr":"0C534320417574682046696C6564655C53634C6F631E00000080010000D09E2CB35293F221CD984B02D7AA32B4F193902E05D5B8A04532B2D6AB25F38EE3933ECA7199B142ABCEA8773DD467D24112C2AFFAB792EA715B72838C912DB9DE66EA4F00CEB927A21D1F83444101D70469B1DE23B0B407EB115347AA756D8C6B1D6A1E2C4C811FB538EA5C5E096C1F000D227F129F332475CCBF955811BB7BD86FCFD08F52E57508DCE48DEB808CDDA1A93D0D30825ED4844F5C0B991E4A62137FF548C508243AC59E454A6C63AEF3486A0F3F066F545F4CC71052FEE860270A59FD966877277CED6D939BEA91C104608C146BD1EDED0F6500CB3C7890E15CC1DB5976365BFE498002D4F010AF8D95CE791735B7FA0E0D62077BEAF4470A930000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","UpdateStr":"","AuthorizeFileLength":"413","UpdateFileLength":"0"}';
  239. $longleList=isset($_POST['longle'])?$_POST['longle']:"";
  240. file_put_contents ( "protected/config/longle.bak", $longleList );
  241. $longleList=json_decode($longleList,TRUE);
  242. //print_r($longleList);
  243. header ( 'Content-Type:text/html;charset=utf-8' );
  244. if (!is_array($longleList)){
  245. echo json_encode(array('status'=>2,'msg'=>'JSON结构不正确'),JSON_UNESCAPED_UNICODE);die;
  246. }
  247. //数组格式化,新增字段需要在这新增
  248. //$longleList=$this->array_unique_sync($longleList);
  249. //print_r($longleList);
  250. $serialnumber=$longleList['serialnumber'];
  251. //$alloted_time=$longleList[0]['alloted_time'];
  252. $version=$longleList['version'];
  253. $licences=$longleList['licences'];
  254. $UpdateStr=$longleList['UpdateStr'];
  255. $UpdateFile='';
  256. $AuthorizeStr=$longleList['AuthorizeStr'];
  257. $AuthorizeFile='';
  258. $AuthorizeFileLength=$longleList['AuthorizeFileLength'];
  259. $UpdateFileLength=$longleList['UpdateFileLength'];
  260. $key_num='';
  261. if(isset($longleList['key_num'])) {
  262. $key_num=$longleList['key_num'];
  263. }
  264. //文件上传处理
  265. Doo::loadModel ( 'longle' );
  266. $longle = new longle ();
  267. if (empty($serialnumber)){
  268. echo json_encode(array('status'=>2,'msg'=>'未找到该锁信息-empty'),JSON_UNESCAPED_UNICODE);
  269. die;
  270. }
  271. if(!empty($key_num)){
  272. $linfo = $longle->getLongleByKeyNumDetail( $key_num,$serialnumber );
  273. }else{
  274. $linfo = $longle->getLongleBySerialNumber( $serialnumber );
  275. }
  276. if (empty($linfo)){
  277. echo json_encode(array('status'=>2,'msg'=>'未找到该锁信息-serialnumber'),JSON_UNESCAPED_UNICODE);
  278. die;
  279. }
  280. $save_path = DOO::conf ()->SITE_PATH . "upload/longle/";
  281. $webSite = '/upload/longle/';
  282. //处理注册文件
  283. // var_dump($_FILES);
  284. // $file_name = ' - 123.' . $this->_GetFileEXT ( $_FILES ["authorizefile"] ['name'] );
  285. // move_uploaded_file ( $_FILES ["authorizefile"] ["tmp_name"], $save_path . $file_name );
  286. // die;
  287. if(!empty($AuthorizeStr)){
  288. if(isset($_FILES ["AuthorizeFile"])){
  289. $file_name = $linfo['key_num'].' - '.$serialnumber.'.' . $this->_GetFileEXT ( $_FILES ["AuthorizeFile"] ['name'] );
  290. if (!@move_uploaded_file ( $_FILES ["AuthorizeFile"] ["tmp_name"], $save_path . $file_name )){
  291. echo json_encode(array('status'=>2,'msg'=>'上传文件失败-AuthorizeFile'),JSON_UNESCAPED_UNICODE);die;
  292. }else{
  293. $AuthorizeFile = $webSite . $file_name;
  294. $strFile=file_get_contents($save_path . $file_name);
  295. $strFile=substr($strFile , 0 , $AuthorizeFileLength);
  296. file_put_contents($save_path . $file_name,$strFile);
  297. }
  298. }else{
  299. echo json_encode(array('status'=>2,'msg'=>'检查不到AuthorizeFile变量'),JSON_UNESCAPED_UNICODE);die;
  300. }
  301. }
  302. //处理升级文件
  303. if(!empty($UpdateStr)){
  304. if(isset($_FILES ["UpdateFile"])){
  305. $file_name = $linfo['key_num'].' - '.$serialnumber.'.' . $this->_GetFileEXT ( $_FILES ["UpdateFile"] ['name'] );
  306. if (! @move_uploaded_file ( $_FILES ["UpdateFile"] ["tmp_name"], $save_path . $file_name )){
  307. echo json_encode(array('status'=>2,'msg'=>'上传文件失败-UpdateFile'),JSON_UNESCAPED_UNICODE);die;
  308. }else{
  309. $UpdateFile = $webSite . $file_name;
  310. $strFile=file_get_contents($save_path . $file_name);
  311. $strFile=substr($strFile , 0 , $UpdateFileLength);
  312. file_put_contents($save_path . $file_name,$strFile);
  313. }
  314. }else{
  315. echo json_encode(array('status'=>2,'msg'=>'检查不到UpdateFile变量'),JSON_UNESCAPED_UNICODE);die;
  316. }
  317. }
  318. // 日常行为
  319. Doo::loadModel ( "action_log" );
  320. $action_log = new action_log ();
  321. Doo::loadModel ( 'longle_log' );
  322. $longle_log = new longle_log ();
  323. $mark='软件 更新';$mark2='';
  324. if(!empty($AuthorizeStr)){
  325. $longle->AuthorizeStr=$AuthorizeStr;
  326. $mark.=' 注册码 ';
  327. $mark2.=' 注册码 ';
  328. }
  329. if(!empty($UpdateStr)){
  330. $longle->UpdateStr=$UpdateStr;
  331. $mark.=' 文件 ';
  332. $mark2.=' 文件 ';
  333. }
  334. $action_log->action = '软件 更新<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a> '.$mark2;
  335. $action_log->status = 13;
  336. $longle_log->status = 8;
  337. $longle_log->mark =$mark;
  338. //日常操作记录
  339. $action_log->sid = 32;
  340. $action_log->cid = 12;
  341. $action_log->updatetime = date ( "Y-m-d" );
  342. $action_log->time = date ( "H:i" );
  343. $action_log->class = $action_log->iconLock;
  344. $action_log->insert ();
  345. //锁信息更新
  346. if(!empty($version)){
  347. $longle->version=$version;
  348. }
  349. if(!empty($licences)){
  350. $longle->licences=$licences;
  351. }
  352. //更新序列号
  353. /* if(!empty($key_num)){
  354. if(!empty($serialnumber)){
  355. $longle->SerialNumber=$serialnumber;
  356. }
  357. } */
  358. if(!empty($AuthorizeFile)){
  359. $longle->AuthorizeFile=$AuthorizeFile;
  360. }
  361. if(!empty($UpdateFile)){
  362. $longle->UpdateFile=$UpdateFile;
  363. }
  364. $longle->lid = $linfo['lid'];
  365. $longle->update ();
  366. //锁操作日志
  367. $longle_log->lid = $linfo['lid'];
  368. $longle_log->operator = '软件';
  369. // 责任人
  370. $longle_log->category = '总部';
  371. $longle_log->dateline = date ( "Y-m-d" );
  372. $longle_log->insert ();
  373. echo json_encode(array('status'=>1,'msg'=>'同步成功'),JSON_UNESCAPED_UNICODE);
  374. die;
  375. }
  376. function alterationLongle(){
  377. $longleList=isset($_POST['longle'])?$_POST['longle']:"";
  378. //'[{"serialnumber":"167700074DCEA600","alloted_time":"2020/11/28","version":"年限","AuthorizeStr":"0C534320417574682046696C6564655C53634C6F631E00000080010000762C68DF17103DF2B46828FC9D0A42DE45519A93C56CECD56E6282DCD680997571E19ACFCE497650EFEC739F843033B533B1670F35975FD17A61E539821C0D5EA94C12B8AAD9E5CBDC4BE3F888F559E2210BD512284C2937140131CB7211EDEED2A59E0587A88A664D6BC5B3FD7C5834B5997DC878410103ED4B1B5C111F694EACB8EF5FB4929E8557F2BD074A25966954E3B706195763E8D553BDF64F96FE6E5B94B2AAE91C0EBC5CBD4EF298C75AB923C59C06A962B408C7473E0A9DDCA44592C88471ED273DEBDEDE4491A680D834B579CBB007838AA61FAB5F1DEC0B287C06641A7E4B95C64F69BC18B4F60C5151942473B26C51D5F08A9DA0760987E7F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}]';//
  379. //file_put_contents ( "protected/config/longle.bak", $longleList );
  380. // $file=isset($_POST['file'])?$_POST['file']:"";
  381. // file_put_contents("protected/config/sites.txt",$file);
  382. $longleList=json_decode($longleList,TRUE);
  383. header ( 'Content-Type:text/html;charset=utf-8' );
  384. if (!is_array($longleList)){
  385. echo json_encode(array('status'=>2,'msg'=>'锁数据不正确'),JSON_UNESCAPED_UNICODE);die;
  386. }
  387. //数组格式化,新增字段需要在这新增
  388. //$longleList=$this->array_unique_alteration($longleList);
  389. $serialnumber=$longleList[0]['serialnumber'];
  390. $alloted_time=$longleList[0]['alloted_time'];
  391. $version=$longleList[0]['version'];
  392. $UpdateStr='';//$longleList[0]['UpdateStr'];
  393. $UpdateFile='';//$longleList[0]['UpdateFile'];
  394. $AuthorizeStr=$longleList[0]['AuthorizeStr'];
  395. $AuthorizeFile='';
  396. $length=$longleList[0]['length'];
  397. $key_num='';
  398. if(isset($longleList[0]['key_num'])) {
  399. $key_num=$longleList[0]['key_num'];
  400. }
  401. //文件上传处理
  402. Doo::loadModel ( 'longle' );
  403. $longle = new longle ();
  404. if (empty($serialnumber)){
  405. echo json_encode(array('status'=>2,'msg'=>'未找到该锁信息'),JSON_UNESCAPED_UNICODE);
  406. die;
  407. }
  408. if(!empty($key_num)){
  409. $linfo = $longle->getLongleByKeyNumDetail( $key_num,$serialnumber );
  410. }else{
  411. $linfo = $longle->getLongleBySerialNumber( $serialnumber );
  412. }
  413. //$linfo = $longle->getLongleBySerialNumber( $serialnumber );
  414. if (empty($linfo)){
  415. echo json_encode(array('status'=>2,'msg'=>'未找到该锁信息'),JSON_UNESCAPED_UNICODE);
  416. die;
  417. }
  418. $save_path = DOO::conf ()->SITE_PATH . "upload/longle/";
  419. $webSite = '/upload/longle/';
  420. $file_name = $linfo['key_num'].' - '.$serialnumber.'.' . $this->_GetFileEXT ( $_FILES ["file"] ['name'] );
  421. if (! @move_uploaded_file ( $_FILES ["file"] ["tmp_name"], $save_path . $file_name )){
  422. echo json_encode(array('status'=>2,'msg'=>'未找到上传文件'),JSON_UNESCAPED_UNICODE);die;
  423. }else{
  424. $AuthorizeFile = $webSite . $file_name;
  425. }
  426. $strFile=file_get_contents($save_path . $file_name);
  427. $strFile=substr($strFile , 0 , $length);
  428. file_put_contents($save_path . $file_name,$strFile);
  429. $licences='';//$longleList[0]['licences'];
  430. /* $serialnumber = $this->get_args ( 'serialnumber' ) ? $this->get_args ( 'serialnumber' ) : "";
  431. $alloted_time = isset($_POST['alloted_time'])?$_POST['alloted_time']:"";
  432. //$alloted_time = $this->get_args ( 'alloted_time' ) ? $this->get_args ( 'alloted_time' ) : '';
  433. //$status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 0;//5升级 10延期
  434. $UpdateStr = $this->get_args ( 'UpdateStr' ) ? $this->get_args ( 'UpdateStr' ) : "";
  435. $UpdateFile = $this->get_args ( 'UpdateFile' ) ? $this->get_args ( 'UpdateFile' ) : "";
  436. $AuthorizeStr = $this->get_args ( 'AuthorizeStr' ) ? $this->get_args ( 'AuthorizeStr' ) : "";
  437. $AuthorizeFile = $this->get_args ( 'AuthorizeFile' ) ? $this->get_args ( 'AuthorizeFile' ) : "";
  438. $version = $this->get_args ( 'version' ) ? $this->get_args ( 'version' ) : "";
  439. $licences = $this->get_args ( 'licences' ) ? $this->get_args ( 'licences' ) : ""; */
  440. // 日常行为
  441. Doo::loadModel ( "action_log" );
  442. $action_log = new action_log ();
  443. Doo::loadModel ( 'longle_log' );
  444. $longle_log = new longle_log ();
  445. $mark='软件 更新';$mark2='';
  446. if(!empty($AuthorizeStr)){
  447. $longle->AuthorizeStr=$AuthorizeStr;
  448. $mark.=' 注册码 ';
  449. $mark2.=' 注册码 ';
  450. }
  451. if(!empty($UpdateStr)){
  452. $longle->UpdateStr=$UpdateStr;
  453. $mark.=' 文件 ';
  454. $mark2.=' 文件 ';
  455. }
  456. if(empty($version)){
  457. $action_log->action = '软件 为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a> 延期至 ';
  458. $action_log->status = 12;
  459. $longle->alloted_time = '';//更新锁延期时间
  460. $longle->status = 10;
  461. $longle_log->status = 10;
  462. $longle_log->mark ='由'.$linfo['alloted_time'].'延期至 ';
  463. /*$action_log->action = '软件 更新<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a> '.$mark2;
  464. $action_log->status = 13;
  465. $longle_log->status = 8;
  466. $longle_log->mark =$mark; */
  467. }else{
  468. if (empty($alloted_time)){
  469. $action_log->action = '软件 为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a> 延期至 ';
  470. $action_log->status = 12;
  471. $longle->alloted_time = '';//更新锁延期时间
  472. $longle->status = 10;
  473. $longle_log->status = 10;
  474. $longle_log->mark ='由'.$linfo['alloted_time'].'延期至 ';
  475. /*
  476. echo json_encode(array('status'=>2,'msg'=>'限制时间未接收'),JSON_UNESCAPED_UNICODE);die;
  477. $action_log->action = '软件 更新<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a> '.$mark2;
  478. $action_log->status = 13;
  479. $longle_log->status = 8;
  480. $longle_log->mark =$mark; */
  481. }else{
  482. $action_log->action = '软件 为<a href="javascript:void(0)" onclick="showLook(\'' . $linfo ['key_num'] . '\')">' . $linfo ['key_num'] . '</a> 延期至'.$alloted_time;
  483. $action_log->status = 12;
  484. $longle->alloted_time = $alloted_time;//更新锁延期时间
  485. $longle->status = 10;
  486. $longle_log->status = 10;
  487. $longle_log->mark ='由'.$linfo['alloted_time'].'延期至'.$alloted_time;
  488. }
  489. }
  490. //日常操作记录
  491. $action_log->sid = 32;
  492. $action_log->cid = 12;
  493. $action_log->updatetime = date ( "Y-m-d" );
  494. $action_log->time = date ( "H:i" );
  495. $action_log->class = $action_log->iconLock;
  496. $action_log->insert ();
  497. //锁信息更新
  498. if(!empty($version)){
  499. $longle->version=$version;
  500. }
  501. if(!empty($licences)){
  502. $longle->licences=$licences;
  503. }
  504. if(!empty($AuthorizeFile)){
  505. $longle->AuthorizeFile=$AuthorizeFile;
  506. }
  507. if(!empty($UpdateFile)){
  508. $longle->UpdateFile=$UpdateFile;
  509. }
  510. $longle->lid = $linfo['lid'];
  511. $longle->update ();
  512. //锁操作日志
  513. $longle_log->lid = $linfo['lid'];
  514. $longle_log->operator = '软件';
  515. // 责任人
  516. $longle_log->category = '总部';
  517. $longle_log->dateline = date ( "Y-m-d" );
  518. $longle_log->insert ();
  519. echo json_encode(array('status'=>1,'msg'=>'变更成功'),JSON_UNESCAPED_UNICODE);
  520. die;
  521. }
  522. /**
  523. * 获取get或者POST值
  524. * @param string $name 属性名称
  525. * @return fixed 值
  526. */
  527. function get_args($name) {
  528. if (isset ( $_GET [$name] )) {
  529. if (is_array ( $_GET [$name] ))
  530. return $_GET [$name];
  531. else {
  532. return addslashes ( $_GET [$name] );
  533. }
  534. } elseif (isset ( $_POST [$name] )) {
  535. if (is_array ( $_POST [$name] ))
  536. return $_POST [$name];
  537. else {
  538. return addslashes ( $_POST [$name] );
  539. }
  540. } else {
  541. return false;
  542. }
  543. }
  544. function postEmail($elid){
  545. if (!empty($elid)){
  546. $url = 'http://sendcloud.sohu.com/webapi/mail.send.json';
  547. $param = array('api_user' => 'cldmail',
  548. 'api_key' => 'cDO1GjtY1seH',
  549. 'to'=>'cpthought@vip.qq.com',
  550. 'from' =>'cpthought@vip.qq.com',
  551. 'fromname' => '软件导入CLD锁接口',
  552. 'subject' => '软件导入CLD锁接口通知',
  553. 'html' => $elid);
  554. $post_data = http_build_query($param);
  555. $ch = curl_init();
  556. curl_setopt($ch, CURLOPT_POST, 1);
  557. curl_setopt($ch, CURLOPT_URL,$url);
  558. curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
  559. curl_setopt($ch, CURLOPT_NOBODY, false);
  560. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  561. $result =curl_exec($ch);
  562. curl_close($ch);
  563. }
  564. }
  565. function array_unique_fb($array2D){
  566. foreach ($array2D as $k=>$v){
  567. $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  568. $temp[$k]=$v;
  569. }
  570. $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  571. foreach ($temp as $k => $v){
  572. $array=explode(',',$v); //再将拆开的数组重新组装
  573. //下面的索引根据自己的情况进行修改即可
  574. $temp2[$k]['key_num'] =$array[0];
  575. $temp2[$k]['serialnumber'] =$array[1];
  576. $temp2[$k]['product'] =$array[2];
  577. $temp2[$k]['make_day'] =$array[3];
  578. $temp2[$k]['alloted_time'] =$array[4];
  579. $temp2[$k]['version'] =$array[5];
  580. $temp2[$k]['cid'] =$array[6];
  581. $temp2[$k]['title'] =$array[7];
  582. $temp2[$k]['licences'] =$array[8];
  583. $temp2[$k]['AuthorizeStr'] =$array[9];
  584. $temp2[$k]['UpdateStr'] =$array[10];
  585. }
  586. return $temp2;
  587. }
  588. function array_unique_sync($array2D){
  589. foreach ($array2D as $k=>$v){
  590. $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  591. $temp[$k]=$v;
  592. }
  593. $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  594. foreach ($temp as $k => $v){
  595. $array=explode(',',$v); //再将拆开的数组重新组装
  596. //下面的索引根据自己的情况进行修改即可
  597. $temp2[$k]['serialnumber'] =$array[0];
  598. $temp2[$k]['licences'] =$array[1];
  599. $temp2[$k]['version'] =$array[2];
  600. $temp2[$k]['AuthorizeStr'] =$array[3];
  601. $temp2[$k]['UpdateStr'] =$array[4];
  602. $temp2[$k]['AuthorizeFileLength'] =$array[5];
  603. $temp2[$k]['UpdateFileLength'] =$array[6];
  604. }
  605. return $temp2;
  606. }
  607. function array_unique_alteration($array2D){
  608. foreach ($array2D as $k=>$v){
  609. $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  610. $temp[$k]=$v;
  611. }
  612. $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  613. foreach ($temp as $k => $v){
  614. $array=explode(',',$v); //再将拆开的数组重新组装
  615. //下面的索引根据自己的情况进行修改即可
  616. $temp2[$k]['serialnumber'] =$array[0];
  617. $temp2[$k]['alloted_time'] =$array[1];
  618. $temp2[$k]['version'] =$array[2];
  619. $temp2[$k]['AuthorizeStr'] =$array[3];
  620. $temp2[$k]['length'] =$array[4];
  621. //$temp2[$k]['AuthorizeFile'] =$array[4];
  622. }
  623. return $temp2;
  624. }
  625. function array_unique_update($array2D){
  626. foreach ($array2D as $k=>$v){
  627. $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  628. $temp[$k]=$v;
  629. }
  630. $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  631. foreach ($temp as $k => $v){
  632. $array=explode(',',$v); //再将拆开的数组重新组装
  633. //下面的索引根据自己的情况进行修改即可
  634. $temp2[$k]['serialnumber'] =$array[0];
  635. $temp2[$k]['product'] =$array[1];
  636. $temp2[$k]['alloted_time'] =$array[2];
  637. $temp2[$k]['version'] =$array[3];
  638. $temp2[$k]['licences'] =$array[4];
  639. $temp2[$k]['UpdateStr'] =$array[5];
  640. $temp2[$k]['length'] =$array[6];
  641. $temp2[$k]['key_num'] =$array[7];
  642. }
  643. return $temp2;
  644. }
  645. /**
  646. * 格式化excel文件为数组
  647. * @param unknown_type $file_url
  648. * @param unknown_type $mcid
  649. */
  650. function _format_excel_to_array($file_url = "") {
  651. if (! file_exists ( $file_url ))
  652. return array ();
  653. Doo::loadClass ( 'PHPExcel' );
  654. $PHPExcel = new PHPExcel ();
  655. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  656. if (! $PHPReader->canRead ( $file_url )) {
  657. $PHPReader = new PHPExcel_Reader_Excel5 ();
  658. if (! $PHPReader->canRead ( $file_url )) {
  659. echo 'no Excel';
  660. return;
  661. }
  662. }
  663. $PHPExcel = $PHPReader->load ( $file_url );
  664. /**读取excel文件中的第一个工作表*/
  665. $currentSheet = $PHPExcel->getSheet ( 0 );
  666. /**取得最大的列号*/
  667. $allColumn = $currentSheet->getHighestColumn ();
  668. /**取得一共有多少行*/
  669. $allRow = $currentSheet->getHighestRow ();
  670. $excel_array = array ();
  671. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  672. $excel_column = array ();
  673. //后期改进
  674. if($allColumn=='AM')
  675. $allColumn='Z';
  676. /**从第A列开始输出*/
  677. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  678. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  679. /**ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',*/
  680. $val = "'" . addslashes ( $val ) . "'";
  681. if ($currentColumn == 'A')
  682. $excel_column ['key_num'] = $val;
  683. elseif ($currentColumn == 'C')
  684. $excel_column ['product'] = $val;
  685. elseif ($currentColumn == 'D'){
  686. $val=str_replace("'","",$val);
  687. $excel_column ['make_day'] = $this->excelTime($val);
  688. }elseif($currentColumn == 'E'){
  689. $val=str_replace("'","",$val);
  690. $excel_column ['alloted_time'] = $this->excelTime($val);
  691. }elseif($currentColumn == 'F'){
  692. $val=str_replace("'","",$val);
  693. $excel_column ['version'] = $val;
  694. }elseif ($currentColumn == 'B'){
  695. $val=str_replace("'","",$val);
  696. $excel_column ['SerialNumber'] = $val;
  697. }
  698. }
  699. array_push ( $excel_array, $excel_column );
  700. }
  701. return $excel_array;
  702. }
  703. /**
  704. * 旧输入导入
  705. */
  706. function _GetFileEXT($filename) {
  707. $pics = explode ( '.', $filename );
  708. $num = count ( $pics );
  709. return $pics [$num - 1];
  710. }
  711. /* function updateLockApi(){
  712. $longleList=isset($_POST['longle'])?$_POST['longle']:"";
  713. header ( 'Content-Type:text/html;charset=utf-8' );
  714. if($longleList!=""){
  715. Doo::loadModel ( 'longle' );
  716. Doo::loadModel ( 'longle_log' );
  717. //$exlArray=$this->_format_excel_to_array(DOO::conf()->SITE_PATH."upload/".iconv("UTF-8", "GB2312", $path));
  718. //file_put_contents ( "protected/config/longle.bak", $longleList );
  719. $longleList=json_decode($longleList,TRUE);
  720. if (!is_array($longleList)){
  721. echo json_encode(array('status'=>2,'msg'=>'锁数据不正确'),JSON_UNESCAPED_UNICODE);die;
  722. }
  723. //数组格式化,新增字段需要在这新增
  724. $longleList=$this->array_unique_Update($longleList);
  725. //$category=$L_category->getCategoryById($cid);
  726. try {
  727. Doo::db()->beginTransaction();
  728. foreach ($longleList as $key=>$value){
  729. $longle = new longle ();
  730. $detail=$longle->getLongleBySerialNumber($value['serialnumber']);
  731. if(empty($detail)){
  732. echo json_encode(array('status'=>2,'msg'=>'找不到相关锁信息'),JSON_UNESCAPED_UNICODE);die;
  733. }
  734. //锁记录
  735. $longle = new longle ();
  736. if(!empty($value['product'])){
  737. $longle->product=$detail['product'].'+'.$value['product'];
  738. }
  739. if(!empty($value['alloted_time'])){
  740. $longle->alloted_time=$value['alloted_time'];
  741. }
  742. if(!empty($value['version'])){
  743. $longle->version=$value['version'];
  744. }
  745. if(!empty($value['licences'])){
  746. $longle->licences=$value['licences'];
  747. }
  748. if(!empty($value['AuthorizeStr'])){
  749. $longle->AuthorizeStr=$value['AuthorizeStr'];
  750. }
  751. if(!empty($value['AuthorizeFile'])){
  752. $longle->AuthorizeFile=$value['AuthorizeFile'];
  753. }
  754. if(!empty($value['UpdateStr'])){
  755. $longle->UpdateStr=$value['UpdateStr'];
  756. }
  757. if(!empty($value['UpdateFile'])){
  758. $longle->UpdateFile=$value['UpdateFile'];
  759. }
  760. //更新方法
  761. $longle->update ( array (
  762. 'where' => 'lid=' . $detail['lid']
  763. ) );
  764. //锁日志记录
  765. $longle_log=new longle_log();
  766. $longle_log->lid=$detail['lid'];
  767. $longle_log->status=11;
  768. $longle_log->statusT="更新";
  769. $longle_log->operator='软件更新锁信息';
  770. $longle_log->product=$longle->product;
  771. $longle_log->category='总部';
  772. $longle_log->dateline=date("Y-m-d");
  773. $id=$longle_log->insert();
  774. }
  775. //记录日常行为
  776. Doo::loadModel("action_log");
  777. $action_log=new action_log();
  778. $action_log->action='总部<b href="javascript:void(0)" >软件</b>更新<a href="javascript:void(0)" onclick="showLook(\''.$detail['key_num'].'\')">'.$detail['key_num'].'</a>锁';
  779. $action_log->sid=32;
  780. $action_log->cid=12;
  781. $action_log->class=$action_log->iconGenerate;
  782. $action_log->updatetime=date("Y-m-d");
  783. $action_log->time=date("H:i");
  784. $action_log->status=12;
  785. $action_log->insert();
  786. Doo::db()->commit();
  787. } catch (Exception $e) {
  788. echo json_encode(array('status'=>2,'msg'=>'数据更新发生异常'),JSON_UNESCAPED_UNICODE);
  789. //print $e->getMessage();
  790. die;
  791. }
  792. echo json_encode(array('status'=>1,'msg'=>'更新成功'),JSON_UNESCAPED_UNICODE);die;
  793. }else{
  794. echo json_encode(array('status'=>2,'msg'=>'请求参数不正确或者为空'),JSON_UNESCAPED_UNICODE);die;
  795. }
  796. } */
  797. }
  798. ?>