<?php
/*
本代码由 成都大猿人网络科技有限公司 原创开发
官方网址:www.dayuanren.cn
严禁反编译、逆向等任何形式的侵权行为,违者将追究法律责任
*/
namespace app\common\model;use app\api\controller\Notify;use app\common\library\Createlog;use app\common\library\Notification;use app\common\library\PayWay;use app\common\library\Rechargeapi;use app\common\model\Porder as PorderModel;use think\Exception;use think\Model;use Util\Ispzw;use Util\Isphone;class Porder extends Model{protected $append=["\x73\x74\x61\x74\x75\x73\x5F\x74\x65\x78\x74","\x73\x74\x61\x74\x75\x73\x5F\x74\x65\x78\x74\x32","\x73\x74\x61\x74\x75\x73\x5F\x74\x65\x78\x74\x5F\x63\x6F\x6C\x6F\x72","\x73\x74\x61\x74\x65","\x73\x74\x61\x74\x65\x5F\x74\x65\x78\x74","\x63\x72\x65\x61\x74\x65\x5F\x74\x69\x6D\x65\x5F\x74\x65\x78\x74"];public static function init(){self::event('after_insert',function($porder){$Kh9MC=Porder::prfun() . date('ymd',time());$Kh9MD=$Kh9MC . $porder->id;unset($Kh9tIME);$Kh9tIME=$Kh9MD;$order_number=$Kh9tIME;$porder->where(array('id'=>$porder->id))->update(array('order_number'=>$order_number));});}public static function prfun(){$Kh9vPMC=C('PORDER_PR') . 'AAA';return substr($Kh9vPMC,0,3);}public static function pr(){$Kh9vPMC=C('PORDER_PR') . 'AAA';return substr($Kh9vPMC,0,3);}public function Customer(){return $this->belongsTo('Customer','customer_id');}public function getStatusTextAttr($value,$data){return C('PORDER_STATUS')[$data['status']];}public function getStatusText2Attr($value,$data){return C('ORDER_STUTAS')[$data['status']];}public function getStatusTextColorAttr($value,$data){unset($Kh9tIMC);$Kh9tIMC=$data['status'];$status=$Kh9tIMC;if(in_array($status,array(2,10)))goto Kh9eWjgx2;goto Kh9ldMhx2;Kh9eWjgx2:return "success";goto Kh9x1;Kh9ldMhx2:if(in_array($status,array(3,9,11)))goto Kh9eWjgx3;goto Kh9ldMhx3;Kh9eWjgx3:return 'warning';goto Kh9x1;Kh9ldMhx3:if(in_array($status,array(4,12)))goto Kh9eWjgx4;goto Kh9ldMhx4;Kh9eWjgx4:return 'primary';goto Kh9x1;Kh9ldMhx4:if(in_array($status,array(5,8)))goto Kh9eWjgx5;goto Kh9ldMhx5;Kh9eWjgx5:return "danger";goto Kh9x1;Kh9ldMhx5:return "default";Kh9x1:}public function getStateAttr($value,$data){return self::getState($data['status']);}public function getStateTextAttr($value,$data){return C('ORDER_STATE')[self::getState($data['status'])];}public function getCreateTimeTextAttr($value,$data){return time_format($data['create_time']);}public function getRebateStatusText($is_rebate,$status){if($is_rebate)goto Kh9eWjgx7;goto Kh9ldMhx7;Kh9eWjgx7:return "已返利";goto Kh9x6;Kh9ldMhx7:if(in_array($status,array(5,6)))goto Kh9eWjgx8;goto Kh9ldMhx8;Kh9eWjgx8:return "失败不返";goto Kh9x6;Kh9ldMhx8:if(in_array($status,array(4,12,13)))goto Kh9eWjgx9;goto Kh9ldMhx9;Kh9eWjgx9:return "待返利";goto Kh9x6;Kh9ldMhx9:if(in_array($status,array(7)))goto Kh9eWjgxa;goto Kh9ldMhxa;Kh9eWjgxa:return "取消不返";goto Kh9x6;Kh9ldMhxa:return "充值中";Kh9x6:}public static function getState($status){if(in_array($status,array(4)))goto Kh9eWjgxc;goto Kh9ldMhxc;Kh9eWjgxc:unset($Kh9tIMC);$Kh9tIMC=1;$state=$Kh9tIMC;goto Kh9xb;Kh9ldMhxc:if(in_array($status,array(1,2,3,8,9,10,11)))goto Kh9eWjgxd;goto Kh9ldMhxd;Kh9eWjgxd:unset($Kh9tIMC);$Kh9tIMC=0;$state=$Kh9tIMC;goto Kh9xb;Kh9ldMhxd:if(in_array($status,array(5,6)))goto Kh9eWjgxe;goto Kh9ldMhxe;Kh9eWjgxe:unset($Kh9tIMC);$Kh9tIMC=2;$state=$Kh9tIMC;goto Kh9xb;Kh9ldMhxe:if(in_array($status,array(12,13)))goto Kh9eWjgxf;goto Kh9ldMhxf;Kh9eWjgxf:unset($Kh9tIMC);$Kh9tIMC=3;$state=$Kh9tIMC;goto Kh9xb;Kh9ldMhxf:if(in_array($status,array(7)))goto Kh9eWjgxg;goto Kh9ldMhxg;Kh9eWjgxg:unset($Kh9tIMC);$Kh9tIMC=-1;$state=$Kh9tIMC;goto Kh9xb;Kh9ldMhxg:unset($Kh9tIMC);$Kh9tIMC=0;$state=$Kh9tIMC;Kh9xb:return $state;}public static function getVoucherUrl($porder_id,$status){$Kh9MC=$status==1;if($Kh9MC)goto Kh9eWjgxi;goto Kh9ldMhxi;Kh9eWjgxi:$Kh9MD=C('WEB_URL') . 'yrapi.php/open/voucher/id/';$Kh9ME=$Kh9MD . $porder_id;$Kh9MF=$Kh9ME . '.html';$Kh9MG=$Kh9MF;goto Kh9xh;Kh9ldMhxi:$Kh9MG='';Kh9xh:return $Kh9MG;}public static function getTypeName($type){return M('product_type')->where(array('id'=>$type))->value('type_name');}public static function getCurApiInfos($apiarrstr,$api_cur_index=0,$apiopen=1){$Kh9MC=$apiopen!=1;if($Kh9MC)goto Kh9eWjgxk;goto Kh9ldMhxk;Kh9eWjgxk:return "";goto Kh9xj;Kh9ldMhxk:Kh9xj:unset($Kh9tIMC);$Kh9tIMC=json_decode($apiarrstr,true);$apiarr=$Kh9tIMC;$Kh9MC=!$apiarr;if($Kh9MC)goto Kh9eWjgxm;goto Kh9ldMhxm;Kh9eWjgxm:return "";goto Kh9xl;Kh9ldMhxm:Kh9xl:foreach($apiarr as $k=>$v){$Kh9MC=$api_cur_index==$k;if($Kh9MC)goto Kh9eWjgxo;goto Kh9ldMhxo;Kh9eWjgxo:$Kh9MC=getReapiName($v['reapi_id']) . '-';$Kh9MD=$Kh9MC . getReapiParamName($v['param_id']);return $Kh9MD;goto Kh9xn;Kh9ldMhxo:Kh9xn:}return "";}public static function createOrder($mobile,$product_id,$extparam,$customer_id,$client=1,$remark='',$out_trade_num='',$amount='',$price='',$isfxh5=0){unset($Kh9tIMC);$Kh9tIMC=trim($mobile);$mobile=$Kh9tIMC;unset($Kh9tIMC);$Kh9tIMC=M('product p')->join('product_type pt','p.type=pt.id')->where(array('p.id'=>$product_id,'p.added'=>1))->field('p.*,pt.typec_id')->find();$prd=$Kh9tIMC;$Kh9MC=!$prd;if($Kh9MC)goto Kh9eWjgxq;goto Kh9ldMhxq;Kh9eWjgxq:return rjson(1,'未找到相关产品(产品ID不正确或已下架)');goto Kh9xp;Kh9ldMhxq:Kh9xp:$Kh9MD=(bool)$out_trade_num;if($Kh9MD)goto Kh9eWjgxt;goto Kh9ldMhxt;Kh9eWjgxt:unset($Kh9tIMC);$Kh9tIMC=M('porder')->where(array('out_trade_num'=>$out_trade_num,'status'=>array('gt',1),'customer_id'=>$customer_id))->find();unset($Kh9tIME);$Kh9tIME=$Kh9tIMC;$reod=$Kh9tIME;$Kh9MD=$out_trade_num&&$Kh9tIMC;goto Kh9xs;Kh9ldMhxt:Kh9xs:if($Kh9MD)goto Kh9eWjgxu;goto Kh9ldMhxu;Kh9eWjgxu:return rjson(208,'已经存在相同商户订单号的订单',$reod['order_number']);goto Kh9xr;Kh9ldMhxu:Kh9xr:if(M('mobile_blacklist')->where(array('mobile'=>$mobile,'limit_time'=>array('gt',time())))->find())goto Kh9eWjgxw;goto Kh9ldMhxw;Kh9eWjgxw:return rjson(1,'该号码无法充值-黑名单');goto Kh9xv;Kh9ldMhxw:Kh9xv:$Kh9MC=intval(C('LIMIT_ONE_PORDER'))>0;if($Kh9MC)goto Kh9eWjgxy;goto Kh9ldMhxy;Kh9eWjgxy:unset($Kh9tIMC);$Kh9tIMC=M('porder')->where(array('mobile'=>$mobile,'type'=>array('in',array(1,2)),'status'=>array('not in',array(4,5,6,7,12,13)),'is_del'=>0))->count();$shuliang=$Kh9tIMC;$Kh9MC=$shuliang>=intval(C('LIMIT_ONE_PORDER'));if($Kh9MC)goto Kh9eWjgx11;goto Kh9ldMhx11;Kh9eWjgx11:$Kh9vPMC='该号码已达到系统设置的次数上限</br>该号码系统已存在:' . $shuliang;$Kh9vPMD=$Kh9vPMC . '单</br>请等待充值成功后再下单';return rjson(1,$Kh9vPMD);goto Kh9xz;Kh9ldMhx11:Kh9xz:goto Kh9xx;Kh9ldMhxy:Kh9xx:$Kh9MC=intval(C('LIMITS_ONE_PORDER'))>0;if($Kh9MC)goto Kh9eWjgx13;goto Kh9ldMhx13;Kh9eWjgx13:unset($Kh9tIMC);$Kh9tIMC=M('porder')->where(array('mobile'=>$mobile,'type'=>3,'status'=>array('not in',array(4,5,6,7,12,13)),'is_del'=>0))->count();$shuliang=$Kh9tIMC;$Kh9MC=$shuliang>=intval(C('LIMITS_ONE_PORDER'));if($Kh9MC)goto Kh9eWjgx15;goto Kh9ldMhx15;Kh9eWjgx15:$Kh9vPMC='该号码已达到系统设置的次数上限</br>该号码系统已存在:' . $shuliang;$Kh9vPMD=$Kh9vPMC . '单</br>请等待充值成功后再下单';return rjson(1,$Kh9vPMD);goto Kh9x14;Kh9ldMhx15:Kh9x14:goto Kh9x12;Kh9ldMhx13:Kh9x12:$Kh9MC=C('LIMIT_ONE_CATE')==1;if($Kh9MC)goto Kh9eWjgx17;goto Kh9ldMhx17;Kh9eWjgx17:unset($Kh9tIMC);$Kh9tIMC=M('porder')->where(array('mobile'=>$mobile,'product_cate'=>array('not in',array(0,$prd['cate_id'])),'status'=>array('not in',array(4,5,6,7,12,13))))->count();$cates=$Kh9tIMC;$Kh9MC=$cates>0;if($Kh9MC)goto Kh9eWjgx19;goto Kh9ldMhx19;Kh9eWjgx19:return rjson(1,'请不要同时在多个分类下单!');goto Kh9x18;Kh9ldMhx19:Kh9x18:goto Kh9x16;Kh9ldMhx17:Kh9x16:unset($Kh9tIMC);$Kh9tIMC='';$province=$Kh9tIMC;unset($Kh9tIMC);$Kh9tIMC='';$city=$Kh9tIMC;unset($Kh9tIMC);$Kh9tIMC=M('customer')->where(array('id'=>$customer_id))->find();$user=$Kh9tIMC;switch($prd['typec_id']){case 1:case 2:$Kh9MC=!is_numeric($mobile);$Kh9ME=(bool)$Kh9MC