暂无描述

Order.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/12/5
  6. * Time: 15:07
  7. */
  8. namespace App;
  9. use Illuminate\Database\Eloquent\Model;
  10. use PHPExcel;
  11. use PHPExcel_Writer_Excel2007;
  12. class Order extends Model
  13. {
  14. public $timestamps = false;
  15. protected $table = "order";
  16. public static function olist(){
  17. $result = Order::orderBy('id', 'desc')->get();
  18. return json_decode(json_encode($result),true);
  19. }
  20. public static function mjOrderAdd($orderList){
  21. $orderList["method"] = "maijiayun.order.add";
  22. var_dump($orderList);exit;
  23. $result = self::mjApi($orderList);
  24. return $result;
  25. }
  26. public static function mjApi($params = array()){
  27. echo 1;
  28. $accessKey = "B1E69297B5DA44DAB35099A5F28F41D9"; //erp 生成的 accessKey
  29. $accessSecret = "4sN2LbylhOglelMP";
  30. $params["timestamp"] = time()."000";
  31. $params["version"] = "v1";
  32. $reqparams = $params;
  33. ksort($reqparams);
  34. $sign = "";
  35. foreach($reqparams as $k=>$val){
  36. if(is_array($val)){
  37. $val = json_encode($val,320);
  38. }
  39. $sign.=$k.$val;
  40. }
  41. $params["accessKey"] = $accessKey;
  42. $params["token"] = strtoupper(sha1($accessKey.$sign.$accessSecret));
  43. $param = json_encode($params);
  44. echo 2;
  45. $ch = curl_init();
  46. $headers = array("Content-type:application/json;charset='utf-8'","Accept:application/json", "Cache-Control: no-cache", "Pragma: no-cache");
  47. curl_setopt($ch, CURLOPT_URL, "https://api.erp.maijiayun.cn"); //api 地址
  48. curl_setopt($ch, CURLOPT_POST, 1);
  49. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  51. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  52. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  53. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  54. $response = curl_exec($ch);
  55. curl_close($ch);
  56. $response = json_decode($response, true);
  57. if (!$response || !is_array($response)) {
  58. return false;
  59. }
  60. if (!array_key_exists("isOk", $response)) {
  61. return false;
  62. } else {
  63. return $response;
  64. }
  65. }
  66. # 生成外部订单号
  67. public static function createOuterCode(){
  68. $order_sn = rand(100, 9999). substr(time(), 5, 5). rand(10, 9999);
  69. return $order_sn;
  70. }
  71. /**
  72. * 导出excel
  73. * @param $data
  74. * @param string
  75. */
  76. public static function export_excel($data, $filename = '未命名.xlsx', $indexKey, $title) {
  77. if( !is_array($indexKey)) return false;
  78. $header_arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  79. //初始化PHPExcel()
  80. $objPHPExcel = new PHPExcel();
  81. $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  82. //接下来就是写数据到表格里面去
  83. $objActSheet = $objPHPExcel->getActiveSheet();
  84. foreach($title as $k=>$item){
  85. $objActSheet->setCellValue($header_arr[$k].'1',$item);
  86. }
  87. $startRow = 2;
  88. foreach ($data as $row) {
  89. foreach ($indexKey as $key => $value){
  90. //这里是设置单元格的内容
  91. $objActSheet->setCellValue($header_arr[$key].$startRow,$row[$value]);
  92. }
  93. $startRow++;
  94. }
  95. header("Pragma: public");
  96. header("Expires: 0");
  97. header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
  98. header("Content-Type:application/force-download");
  99. header("Content-Type:application/vnd.ms-execl");
  100. header("Content-Type:application/octet-stream");
  101. header("Content-Type:application/download");;
  102. header('Content-Disposition:attachment;filename='.$filename.'');
  103. header("Content-Transfer-Encoding:binary");
  104. $objWriter->save('php://output');
  105. exit();
  106. }
  107. }