123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2017/12/5
- * Time: 15:07
- */
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use PHPExcel;
- use PHPExcel_Writer_Excel2007;
- class Order extends Model
- {
- public $timestamps = false;
- protected $table = "order";
-
- public static function olist(){
- $result = Order::orderBy('id', 'desc')->get();
- return json_decode(json_encode($result),true);
- }
- public static function mjOrderAdd($orderList){
- $orderList["method"] = "maijiayun.order.add";
- var_dump($orderList);exit;
- $result = self::mjApi($orderList);
- return $result;
- }
- public static function mjApi($params = array()){
- echo 1;
- $accessKey = "B1E69297B5DA44DAB35099A5F28F41D9"; //erp 生成的 accessKey
- $accessSecret = "4sN2LbylhOglelMP";
- $params["timestamp"] = time()."000";
- $params["version"] = "v1";
- $reqparams = $params;
- ksort($reqparams);
- $sign = "";
- foreach($reqparams as $k=>$val){
- if(is_array($val)){
- $val = json_encode($val,320);
- }
- $sign.=$k.$val;
- }
- $params["accessKey"] = $accessKey;
- $params["token"] = strtoupper(sha1($accessKey.$sign.$accessSecret));
- $param = json_encode($params);
- echo 2;
- $ch = curl_init();
- $headers = array("Content-type:application/json;charset='utf-8'","Accept:application/json", "Cache-Control: no-cache", "Pragma: no-cache");
- curl_setopt($ch, CURLOPT_URL, "https://api.erp.maijiayun.cn"); //api 地址
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $response = curl_exec($ch);
- curl_close($ch);
- $response = json_decode($response, true);
- if (!$response || !is_array($response)) {
- return false;
- }
- if (!array_key_exists("isOk", $response)) {
- return false;
- } else {
- return $response;
- }
- }
- # 生成外部订单号
- public static function createOuterCode(){
- $order_sn = rand(100, 9999). substr(time(), 5, 5). rand(10, 9999);
- return $order_sn;
- }
- /**
- * 导出excel
- * @param $data
- * @param string
- */
- public static function export_excel($data, $filename = '未命名.xlsx', $indexKey, $title) {
- if( !is_array($indexKey)) return false;
- $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');
- //初始化PHPExcel()
- $objPHPExcel = new PHPExcel();
- $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
-
- //接下来就是写数据到表格里面去
- $objActSheet = $objPHPExcel->getActiveSheet();
- foreach($title as $k=>$item){
- $objActSheet->setCellValue($header_arr[$k].'1',$item);
- }
- $startRow = 2;
- foreach ($data as $row) {
- foreach ($indexKey as $key => $value){
- //这里是设置单元格的内容
- $objActSheet->setCellValue($header_arr[$key].$startRow,$row[$value]);
- }
- $startRow++;
- }
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
- header("Content-Type:application/force-download");
- header("Content-Type:application/vnd.ms-execl");
- header("Content-Type:application/octet-stream");
- header("Content-Type:application/download");;
- header('Content-Disposition:attachment;filename='.$filename.'');
- header("Content-Transfer-Encoding:binary");
- $objWriter->save('php://output');
- exit();
- }
- }
|