<?php
/*
 * 愚子方提供解码
 * 联系QQ: 179210540
 * 仅提供学习使用
 */
defined('THINK_PATH') OR exit();
class FengyeAction extends AliziAction {


    public function api(){
       //$json = '{"data":{"adgroup_id":"","adgroup_name":"","advertiser_id":"","account_id":"7982475","order_id":"BA24574030054307","page_name":"2018.10.19-\u5243\u987b\u5200-\u590d\u52363","package_info":"\u5fb7\u56fd4D\u6d6e\u52a8\u4e09\u5200\u5934\u7535\u52a8\u5243\u987b\u5200;\u989c\u8272\uff1a\u571f\u8c6a\u91d1:;","quantity":"1","price":"99.00","total_price":"99","user_name":"\u674e\u6d4b\u8bd5","user_phone":"13265311687","user_province":"\u5e7f\u4e1c\u7701","user_city":"\u5e7f\u5dde\u5e02","user_area":"\u5929\u6cb3\u533a","user_address":"\u5e7f\u4e1c\u7701\u5e7f\u5dde\u5e02\u5929\u6cb3\u533a\u5929\u6cb3\u533a\u6d4b\u8bd5\u4e00\u4e0b","user_ip":"203.195.135.174","order_time":"2018-10-24 13:03:23","user_message":"\u5929\u6cb3\u533a\u6d4b\u8bd5\u4e00\u4e0b","url":"https:\/\/1ce3f57d.fyeds5.com\/?r_id=147577484_0f2ae373f&pagetype=SINGLE&_bid=2759"}}';
		
		$json = file_get_contents("php://input"); 
		$data = json_decode($json, true); 
        @file_put_contents('./Public/Cache/json.json',$json."\n",FILE_APPEND);
        //@file_put_contents('./Public/Cache/data.json',var_export($data,true)."\n",FILE_APPEND);
	
		$Model = M('OrderFengye');
		
		$flag = false;
      	$order = isset($data['data'])?$data['data']:'';
		if($order){
			$orderExist = $Model->where(array('order_id'=>$order['order_id']))->field('id')->find();
			if($orderExist){
				 echo json_encode(array("code"=>0, "msg"=>"success")); exit;
			}else{
				$order['add_time'] = time();
				$flag = $Model->add($order);
				if(!$flag){
				   @file_put_contents('./Public/Cache/sql.json',$Model->_sql()."\n",FILE_APPEND);
				   echo json_encode(array("code"=>1, "msg"=>$Model->getError())); exit;
				}
				echo json_encode(array("code"=>0, "msg"=>"success")); 
			}
		}else{
        	echo json_encode(array("code"=>1, "msg"=>'Empty Data')); 
        }
		
    }


}