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, false); $this->yes($data); } # 提交接口 一般用于提交数据,异步执行 public function submit(): void { $settingStatus = sysconf('settingStatus'); if ($settingStatus == 1) { $this->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 cancel() { } # 提交接口 一般用于提交数据,异步执行 public function submit_test(): void { $settingStatus = sysconf('settingStatus'); if ($settingStatus == 1) { $this->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); $this->yes($data); } #======================================================================================================== #获取手机验证码 public function MobileCode() { $settingStatus = sysconf('settingStatus'); if ($settingStatus == 1) { $this->no(-1000); } $this->checkOpenTime(sysconf('settingOpenTime')); if (isset($this->merchant['opentime']) && $this->merchant['opentime']) { $this->checkOpenTime($this->merchant['opentime']); } $this->input['is_getMobileCode'] = 1; $data = $this->channel($this->mid, $this->product, false); var_dump($data); } # 查询订单接口 public function order(): 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); } $result['cash'] = $data['cash']; $result['order_id'] = $data['order_id']; $result['merchant_order_id'] = $data['merchant_order_id']; if ($data['status'] < 0) { $data['status'] = 1; } $result['status'] = $data['status']; if (!$data['channel_callback_msg']) { $data['channel_callback_msg'] = '{}'; } $request = json_decode($data['channel_callback_msg'], true); $number = ''; if (isset($request['s_number']) && $request['s_number']) { $number = $request['s_number']; } $order_name = sysconf('order_name'); if ($number && $order_name) { $result[$order_name] = $number; } elseif ($number) { $result['s_number'] = $number; } $this->yes($result); } # 查询账户接口 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; } }