SoftController.php 8.5 KB

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