SoftController.php 8.5 KB

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