no(-1000); } $this->checkOpenTime(sysconf('settingOpenTime')); if (isset($this->merchant['opentime']) && $this->merchant['opentime']) { $this->checkOpenTime($this->merchant['opentime']); } $data = $this->channel($this->mid, $this->product, true); $this->yes($data); } # 提交接口 一般用于提交数据,异步执行 public function dc_submit(): void { $this->submit(); } # 查询订单接口 public function query(): void { $order = input('order_id'); $merchant_order = input('merchant_order_id'); if (!$order && !$merchant_order) { $this->no(-100); } $data = $this->getOrder($order, $merchant_order); if (!$data) { $this->no(-101); } if(!$order){ $order = $data['order_id']; } $result['cash'] = $data['cash']; $result['order_id'] = $data['order_id']; $result['merchant_order_id'] = $data['merchant_order_id']; $result['card']=''; if ($data['status'] < 0) { $data['status'] = 1; } $result['status'] = $data['status']; if(in_array($data['status'], [2,7])){ $response = json_decode($data['response'],true); if(isset($response['kami'])) { $cardno = $response['kami']['cardno']; $cardpwd = $response['kami']['cardpwd']; $expire_time= $response['kami']['expired']; $kami = [ 'cardno' =>$cardno, 'cardpwd' =>$cardpwd, 'expire_time' =>$expire_time, ]; $kami=implode(',',$kami); $result['card']=$this->set_seacret($kami,$order); $this->yes($result); }elseif(isset($data['channel_callback_msg']) && str_contains($data['channel_callback_msg'], "kami")){ $msg = json_decode($data['channel_callback_msg'],true); $cardno = $msg['kami']['cardno']; $cardpwd = $msg['kami']['cardpwd']; $expire_time= $msg['kami']['expired']; $kami = [ 'cardno' =>$cardno, 'cardpwd' =>$cardpwd, 'expire_time' =>$expire_time, ]; $kami=implode(',',$kami); $result['card']=$this->set_seacret($kami,$order); $this->yes($data); } } $this->yes($result); } public function set_seacret($kami,$order_id){ $seacret=strtolower(md5(md5($this->key).$order_id)); // var_dump($seacret);die; $v=substr($seacret, 0,strlen($seacret)/8); $str=openssl_encrypt($kami, 'DES-EDE3', $seacret, OPENSSL_RAW_DATA); // var_dump($str);die; return base64_encode($str); } public function decrypt($str,$order_id){ $str = base64_decode($str); $seacret=strtolower(md5(md5($this->key).$order_id)); $str=openssl_decrypt($str, 'DES-EDE3', $seacret, OPENSSL_RAW_DATA); return $str; } # 查询账户接口 public function account(): void { $data = $this->merchant; $result['name'] = $data['name']; $result['account'] = $data['account_surplus']; $result['credit'] = $data['credit_surplus']; $result['appid'] = $data['appid']; $this->yes($result); } # 根据日期查询账户数据 public function accountByDay(): void { $this->merchantLogService = \app\merchant\service\MerchantLogService::instance(); $orderService = \app\merchant\service\OrderService::instance(); $data = $this->merchant; $day = input('day'); if (!$day) { $day = date('Y-m-d', strtotime('-1 day')); } $begin = $day . ' 00:00:00'; $after = $day . ' 23:59:59'; $time = [$begin, $after]; # 获取昨天 $yday = $day . ' 00:00:00'; $yday = $this->maketime($yday); $yday = date('Y-m-d', strtotime('-1 day', $yday)); $begin = $yday . ' 00:00:00'; $after = $yday . ' 23:59:59'; $stime = [$begin, $after]; $where['mid'] = $data['id']; # 加款 $where['type'] = 1; $chongzhi = $this->merchantLogService->getDb($where, $time); $where['type'] = 2; $jianshao = $this->merchantLogService->getDb($where, $time); $add = round($chongzhi - $jianshao, 2); # 冻结 $dong = $orderService->getDong($where['mid'], $time); $result['name'] = $data['name']; $result['account'] = $this->merchant_yue($where['mid'], $time); $yaccount = $this->merchant_yue($where['mid'], $stime); $result['dong'] = $dong; $result['add'] = $add; $where['type'] = 3; $kou = $this->merchantLogService->getDb($where, $time); $where['type'] = 4; $huifu = $this->merchantLogService->getDb($where, $time); $kou -= $huifu; $result['zhang'] = round($yaccount + $result['add'] - $kou, 2); $this->yes($result); } # 计算商户的的一天的余额 private function merchant_yue($mid, $time): float { $time[0] = '2020-01-01 00:00:00'; $where['mid'] = $mid; $where['account_type'] = 1; $where['oper'] = 1; $shouru = $this->merchantLogService->getDb($where, $time); $where['oper'] = 2; $zhichu = $this->merchantLogService->getDb($where, $time); $yue = round($shouru - $zhichu, 2); unset($where['oper']); $where['account_type'] = 2; $where['type'] = 3; $kou = $this->merchantLogService->getDb($where, $time); $where['type'] = 4; $huifu = $this->merchantLogService->getDb($where, $time); $where['type'] = 1; $zonghuikuan = $this->merchantLogService->getDb($where, $time); $where['type'] = 2; $zonghuifu = $this->merchantLogService->getDb($where, $time); $zonghuikuan -= $zonghuifu; $hui = round($kou - $huifu - $zonghuikuan, 2); return $yue - $hui; } protected function maketime($v): float|false|int|string { if (!$v) { return ''; } if (is_numeric($v)) { return $v; } if (is_array($v)) { $v = $v[1]; } if (strstr($v, ' ')) { $t = explode(' ', $v); $v = $t[0]; $s = explode(':', $t[1]); } else { $s = array(0, 0, 0); } if (!isset($s[1])) { $s[1] = 0; } if (!isset($s[2])) { $s[2] = 0; } if (strstr($v, '-')) { $t = explode('-', $v); } elseif (strstr($v, '/')) { $u = explode('/', $v); $t[0] = $u[2]; $t[1] = $u[0]; $t[2] = $u[1]; } if (!isset($t)) { $t = array(0, 0, 0); } if (!isset($t[1])) { $t[1] = 0; } if (!isset($t[2])) { $t[2] = 0; } $v = mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]); return $v; } }