123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?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 OrderScript extends Model
- {
- public $timestamps = false;
- /**
- * 添加订单
- */
- public static function mjOrderAdd($orderList){
- $orderList["method"] = "maijiayun.order.add";
- //status格式
- $staus_arr = array(
- 0 => '待付款',
- 1 => '已付款待审核',
- 2 => '已审核待发货',
- 3 => '已发货',
- );
- $orderList['status'] = $staus_arr[$orderList['status']];
- $result = self::mjApi($orderList);
- return $result;
- }
- /**
- * 更新订单
- */
- public static function mjOrderUpdate($orderList){
- $orderList["method"] = "maijiayun.order.update";
- $staus_arr = array(
- 0 => '待付款',
- 1 => '已付款待审核',
- 2 => '已审核待发货',
- 3 => '已发货',
- 4 => '已取消',
- );
- $orderList['status'] = $staus_arr[$orderList['status']];
- $result = self::mjApi($orderList);
- return $result;
- }
- /**
- * 取消订单
- */
- public static function mjOrderDel($orderList){
- $orderList["method"] = "maijiayun.order.update";
- $orderList['status'] = '已取消';
- $result = self::mjApi($orderList);
- return $result;
- }
-
- /**
- * 获取订单
- */
- public static function mjOrderGet($order){
- $order["method"] = "maijiayun.order.get";
- $result = self::mjApi($order);
- return $result;
- }
- /**
- * 添加Erp商品
- */
- public static function mjErpGoodsAdd($goods){
- $goods["method"] = "maijiayun.goods.sku.add";
- $result = self::mjApi($goods);
- return $result;
- }
- /**
- * 添加商品
- */
- public static function mjGoodsAdd($goods){
- $goods["method"] = "maijiayun.eshop.goods.add";
- $result = self::mjApi($goods);
- return $result;
- }
-
- /**
- * 更新商品
- */
- public static function mjGoodsUpdate($goods){
- $goods["method"] = "maijiayun.eshop.goods.update";
- $result = self::mjApi($goods);
- return $result;
- }
-
- /**
- * 更新erp商品
- */
- public static function mjErpGoodsUpdate($goods){
- $goods["method"] = "maijiayun.goods.update";
- $result = self::mjApi($goods);
- return $result;
- }
- /**
- * 批量添加sku
- */
- public static function mjBatchSkuAdd($sku){
- $sku["method"] = "maijiayun.eshop.sku.batchAdd"; //批量添加
- //$sku["method"] = "maijiayun.eshop.sku.add";
- $result = self::mjApi($sku);
- return $result;
- }
- /**
- * 添加单个sku
- */
- public static function mjSkuAdd($sku){
- $sku["method"] = "maijiayun.eshop.sku.add";
- $result = self::mjApi($sku);
- return $result;
- }
- /**
- * 修改Erp sku
- */
- public static function mjErpSkuUpdate($sku){
- $sku["method"] = "maijiayun.goods.sku.update";
- $result = self::mjApi($sku);
- return $result;
- }
- /**
- * 修改shop sku
- */
- public static function mjSkuUpdate($sku){
- $sku["method"] = "maijiayun.eshop.sku.update";
- $result = self::mjApi($sku);
- return $result;
- }
- /**
- * 获取 sku 库存
- */
- public static function mjWarehouseSkuGet($sku){
- $sku["method"] = "maijiayun.warehouse.sku.list";
- $result = self::mjApi($sku);
- return $result;
- }
- public static function mjApi($params = array()){
- $accessKey = "B1E69297B5DA44DAB35099A5F28F41D9"; //erp 生成的 accessKey
- $accessSecret = "4sN2LbylhOglelMP";
- //$accessKey = "F82A757089D84F89B1782EDC3A4DA82A"; //erp 生成的 accessKey
- //$accessSecret = "wB2ueW8eQOHXNWcN";
- $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);
- $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);
- Log::scriptLog($params,['mjApi_response'=>$response],"order/mjApi",1,'');
- if (!$response || !is_array($response)) {
- return false;
- }
- if (!array_key_exists("isOk", $response)) {
- return false;
- } elseif( $response['isOk'] == false){
- Log::scriptLog($params,['mjApi_response'=>$response],"order/mjApi",0,'');
- return false;
- } else {
- return $response;
- }
- }
- }
|