SoftController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. header ( 'Content-Type:text/html;charset=utf-8' );
  29. if($longleList!=""){
  30. Doo::loadModel ( 'longle' );
  31. Doo::loadModel ( 'longle_log' );
  32. //$exlArray=$this->_format_excel_to_array(DOO::conf()->SITE_PATH."upload/".iconv("UTF-8", "GB2312", $path));
  33. //file_put_contents ( "protected/config/longle.bak", $longleList );
  34. $longleList=json_decode($longleList,TRUE);
  35. if (!is_array($longleList)){
  36. echo json_encode(array('status'=>2,'msg'=>'锁数据不正确'),JSON_UNESCAPED_UNICODE);die;
  37. }
  38. //数组格式化,新增字段需要在这新增
  39. $longleList=$this->array_unique_fb($longleList);
  40. //$category=$L_category->getCategoryById($cid);
  41. try {
  42. Doo::db()->beginTransaction();
  43. foreach ($longleList as $key=>$value){
  44. //锁记录
  45. $longle = new longle ();
  46. $longle->key_num=$value['key_num'];
  47. $longle->product=$value['product'];
  48. $longle->make_day=$value['make_day'];
  49. $longle->alloted_time=$value['alloted_time'];
  50. $longle->status=1;
  51. $longle->statusT="生成";
  52. $longle->cid=$value['cid'];
  53. $longle->category=$value['title'];
  54. $longle->SerialNumber=$value['serialnumber'];
  55. $longle->version=$value['version'];
  56. $longle->licences=$value['licences'];
  57. $lid=$longle->insert();
  58. //锁日志记录
  59. $longle_log=new longle_log();
  60. $longle_log->lid=$lid;
  61. $longle_log->status=1;
  62. $longle_log->statusT="生成";
  63. $longle_log->operator='软件生成';
  64. $longle_log->product=$longle->product;
  65. $longle_log->category='总部';
  66. $longle_log->dateline=date("Y-m-d");
  67. $id=$longle_log->insert();
  68. }
  69. //记录日常行为
  70. Doo::loadModel("action_log");
  71. $action_log=new action_log();
  72. $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>个锁';
  73. $action_log->sid=43;
  74. $action_log->cid=12;
  75. $action_log->class=$action_log->iconGenerate;
  76. $action_log->updatetime=date("Y-m-d");
  77. $action_log->time=date("H:i");
  78. $action_log->status=11;
  79. $action_log->insert();
  80. Doo::db()->commit();
  81. } catch (Exception $e) {
  82. echo json_encode(array('status'=>2,'msg'=>'数据录入发生异常'),JSON_UNESCAPED_UNICODE);
  83. //print $e->getMessage();
  84. die;
  85. }
  86. echo json_encode(array('status'=>1,'msg'=>'入库'.count($longleList).'个'),JSON_UNESCAPED_UNICODE);die;
  87. }else{
  88. echo json_encode(array('status'=>2,'msg'=>'请求参数不正确或者为空'),JSON_UNESCAPED_UNICODE);die;
  89. }
  90. }
  91. function postEmail($elid){
  92. if (!empty($elid)){
  93. $url = 'http://sendcloud.sohu.com/webapi/mail.send.json';
  94. $param = array('api_user' => 'cldmail',
  95. 'api_key' => 'cDO1GjtY1seH',
  96. 'to'=>'cpthought@vip.qq.com',
  97. 'from' =>'cpthought@vip.qq.com',
  98. 'fromname' => '软件导入CLD锁接口',
  99. 'subject' => '软件导入CLD锁接口通知',
  100. 'html' => $elid);
  101. $post_data = http_build_query($param);
  102. $ch = curl_init();
  103. curl_setopt($ch, CURLOPT_POST, 1);
  104. curl_setopt($ch, CURLOPT_URL,$url);
  105. curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
  106. curl_setopt($ch, CURLOPT_NOBODY, false);
  107. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  108. $result =curl_exec($ch);
  109. curl_close($ch);
  110. }
  111. }
  112. function array_unique_fb($array2D){
  113. foreach ($array2D as $k=>$v){
  114. $v=join(',',$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  115. $temp[$k]=$v;
  116. }
  117. $temp=array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  118. foreach ($temp as $k => $v){
  119. $array=explode(',',$v); //再将拆开的数组重新组装
  120. //下面的索引根据自己的情况进行修改即可
  121. $temp2[$k]['key_num'] =$array[0];
  122. $temp2[$k]['serialnumber'] =$array[1];
  123. $temp2[$k]['product'] =$array[2];
  124. $temp2[$k]['make_day'] =$array[3];
  125. $temp2[$k]['alloted_time'] =$array[4];
  126. $temp2[$k]['version'] =$array[5];
  127. $temp2[$k]['cid'] =$array[6];
  128. $temp2[$k]['title'] =$array[7];
  129. $temp2[$k]['licences'] =$array[8];
  130. }
  131. return $temp2;
  132. }
  133. /**
  134. * 格式化excel文件为数组
  135. * @param unknown_type $file_url
  136. * @param unknown_type $mcid
  137. */
  138. function _format_excel_to_array($file_url = "") {
  139. if (! file_exists ( $file_url ))
  140. return array ();
  141. Doo::loadClass ( 'PHPExcel' );
  142. $PHPExcel = new PHPExcel ();
  143. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  144. if (! $PHPReader->canRead ( $file_url )) {
  145. $PHPReader = new PHPExcel_Reader_Excel5 ();
  146. if (! $PHPReader->canRead ( $file_url )) {
  147. echo 'no Excel';
  148. return;
  149. }
  150. }
  151. $PHPExcel = $PHPReader->load ( $file_url );
  152. /**读取excel文件中的第一个工作表*/
  153. $currentSheet = $PHPExcel->getSheet ( 0 );
  154. /**取得最大的列号*/
  155. $allColumn = $currentSheet->getHighestColumn ();
  156. /**取得一共有多少行*/
  157. $allRow = $currentSheet->getHighestRow ();
  158. $excel_array = array ();
  159. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  160. $excel_column = array ();
  161. //后期改进
  162. if($allColumn=='AM')
  163. $allColumn='Z';
  164. /**从第A列开始输出*/
  165. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  166. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  167. /**ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',*/
  168. $val = "'" . addslashes ( $val ) . "'";
  169. if ($currentColumn == 'A')
  170. $excel_column ['key_num'] = $val;
  171. elseif ($currentColumn == 'C')
  172. $excel_column ['product'] = $val;
  173. elseif ($currentColumn == 'D'){
  174. $val=str_replace("'","",$val);
  175. $excel_column ['make_day'] = $this->excelTime($val);
  176. }elseif($currentColumn == 'E'){
  177. $val=str_replace("'","",$val);
  178. $excel_column ['alloted_time'] = $this->excelTime($val);
  179. }elseif($currentColumn == 'F'){
  180. $val=str_replace("'","",$val);
  181. $excel_column ['version'] = $val;
  182. }elseif ($currentColumn == 'B'){
  183. $val=str_replace("'","",$val);
  184. $excel_column ['SerialNumber'] = $val;
  185. }
  186. }
  187. array_push ( $excel_array, $excel_column );
  188. }
  189. return $excel_array;
  190. }
  191. }
  192. ?>