diff --git a/app/data/command/UserTransfer.php b/app/data/command/UserTransfer.php index 5d0fba852..656888b05 100644 --- a/app/data/command/UserTransfer.php +++ b/app/data/command/UserTransfer.php @@ -8,6 +8,12 @@ use think\admin\Exception; use think\admin\storage\LocalStorage; use think\console\Input; use think\console\Output; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use WeChat\Exceptions\InvalidDecryptException; +use WeChat\Exceptions\InvalidResponseException; +use WeChat\Exceptions\LocalCacheException; use WePay\Transfers; use WePay\TransfersBank; @@ -30,7 +36,7 @@ class UserTransfer extends Command * @param Output $output * @return void * @throws Exception - * @throws \think\db\exception\DbException + * @throws DbException */ protected function execute(Input $input, Output $output) { @@ -83,12 +89,12 @@ class UserTransfer extends Command * @param array $item * @return array [config, result] * @throws Exception - * @throws \WeChat\Exceptions\InvalidDecryptException - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws InvalidDecryptException + * @throws InvalidResponseException + * @throws LocalCacheException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ private function createTransferBank(array $item): array { @@ -103,103 +109,14 @@ class UserTransfer extends Command ])]; } - /** - * 尝试提现转账到微信钱包 - * @param array $item - * @return array [config, result] - * @throws Exception - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - private function createTransferWallet(array $item): array - { - $config = $this->getConfig($item['uid']); - return [$config, Transfers::instance($config)->create([ - 'openid' => $config['openid'], - 'amount' => intval($item['amount'] - $item['charge_amount']) * 100, - 'partner_trade_no' => $item['code'], - 'spbill_create_ip' => '127.0.0.1', - 'check_name' => 'NO_CHECK', - 'desc' => '微信余额提现', - ])]; - } - - /** - * 查询更新提现打款状态 - * @param array $item - * @throws Exception - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - private function queryTransferWallet(array $item) - { - $config = $this->getConfig($item['uid']); - [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']]; - $result = Transfers::instance($config)->query($item['partner_trade_no']); - if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ - 'status' => 5, - 'appid' => $config['appid'], - 'openid' => $config['openid'], - 'trade_time' => $result['payment_time'], - 'change_time' => date('Y-m-d H:i:s'), - 'change_desc' => '微信提现打款成功', - ]); - } - } - - /** - * 查询更新提现打款状态 - * @param array $item - * @throws Exception - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - private function queryTransferBank(array $item) - { - $config = $this->getConfig($item['uid']); - [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']]; - $result = TransfersBank::instance($config)->query($item['partner_trade_no']); - if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - if ($result['status'] === 'SUCCESS') { - $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ - 'status' => 5, - 'appid' => $config['appid'], - 'openid' => $config['openid'], - 'trade_time' => $result['pay_succ_time'] ?: date('Y-m-d H:i:s'), - 'change_time' => date('Y-m-d H:i:s'), - 'change_desc' => '微信提现打款成功', - ]); - } - if (in_array($result['status'], ['FAILED', 'BANK_FAIL'])) { - $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ - 'status' => 0, - 'change_time' => date('Y-m-d H:i:s'), - 'change_desc' => '微信提现打款失败', - ]); - // 刷新用户可提现余额 - UserRebateService::instance()->amount($item['uid']); - } - } - } - /** * 获取微信提现参数 * @param int $uid * @return array * @throws Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ private function getConfig(int $uid): array { @@ -232,9 +149,9 @@ class UserTransfer extends Command * @param int $uid * @param string $type * @return mixed|null - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ private function getWechatInfo(int $uid, string $type): ?array { @@ -258,4 +175,93 @@ class UserTransfer extends Command } return null; } + + /** + * 尝试提现转账到微信钱包 + * @param array $item + * @return array [config, result] + * @throws Exception + * @throws InvalidResponseException + * @throws LocalCacheException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + private function createTransferWallet(array $item): array + { + $config = $this->getConfig($item['uid']); + return [$config, Transfers::instance($config)->create([ + 'openid' => $config['openid'], + 'amount' => intval($item['amount'] - $item['charge_amount']) * 100, + 'partner_trade_no' => $item['code'], + 'spbill_create_ip' => '127.0.0.1', + 'check_name' => 'NO_CHECK', + 'desc' => '微信余额提现', + ])]; + } + + /** + * 查询更新提现打款状态 + * @param array $item + * @throws Exception + * @throws InvalidResponseException + * @throws LocalCacheException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + private function queryTransferBank(array $item) + { + $config = $this->getConfig($item['uid']); + [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']]; + $result = TransfersBank::instance($config)->query($item['partner_trade_no']); + if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { + if ($result['status'] === 'SUCCESS') { + $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ + 'status' => 5, + 'appid' => $config['appid'], + 'openid' => $config['openid'], + 'trade_time' => $result['pay_succ_time'] ?: date('Y-m-d H:i:s'), + 'change_time' => date('Y-m-d H:i:s'), + 'change_desc' => '微信提现打款成功', + ]); + } + if (in_array($result['status'], ['FAILED', 'BANK_FAIL'])) { + $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ + 'status' => 0, + 'change_time' => date('Y-m-d H:i:s'), + 'change_desc' => '微信提现打款失败', + ]); + // 刷新用户可提现余额 + UserRebateService::instance()->amount($item['uid']); + } + } + } + + /** + * 查询更新提现打款状态 + * @param array $item + * @throws Exception + * @throws InvalidResponseException + * @throws LocalCacheException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + private function queryTransferWallet(array $item) + { + $config = $this->getConfig($item['uid']); + [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']]; + $result = Transfers::instance($config)->query($item['partner_trade_no']); + if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { + $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([ + 'status' => 5, + 'appid' => $config['appid'], + 'openid' => $config['openid'], + 'trade_time' => $result['payment_time'], + 'change_time' => date('Y-m-d H:i:s'), + 'change_desc' => '微信提现打款成功', + ]); + } + } } \ No newline at end of file diff --git a/app/data/controller/ShopGoods.php b/app/data/controller/ShopGoods.php index 3992c99a0..22b321813 100644 --- a/app/data/controller/ShopGoods.php +++ b/app/data/controller/ShopGoods.php @@ -22,7 +22,7 @@ class ShopGoods extends Controller private $table = 'ShopGoods'; /** - * 最大分类级别 + * 最大分类等级 * @var integer */ protected $cateLevel; diff --git a/app/data/controller/ShopGoodsCate.php b/app/data/controller/ShopGoodsCate.php index 3b77847d9..898a0540c 100644 --- a/app/data/controller/ShopGoodsCate.php +++ b/app/data/controller/ShopGoodsCate.php @@ -20,7 +20,7 @@ class ShopGoodsCate extends Controller private $table = 'ShopGoodsCate'; /** - * 最大分类级别 + * 最大分类等级 * @var integer */ protected $cateLevel; diff --git a/app/data/service/ExpressService.php b/app/data/service/ExpressService.php index c9fe4634a..787bf93aa 100644 --- a/app/data/service/ExpressService.php +++ b/app/data/service/ExpressService.php @@ -63,7 +63,7 @@ class ExpressService extends Service /** * 配送区域树型数据 - * @param integer $level 最大级别 + * @param integer $level 最大等级 * @param null|integer $status 状态筛选 * @return array */ @@ -97,16 +97,6 @@ class ExpressService extends Service ]); } - /** - * 楚才开放平台快递公司 - * @return array - * @throws \think\admin\Exception - */ - public function company(): array - { - return $this->_getInterface()->doRequest('api.auth.express/getCompany'); - } - /** * 获取楚才开放平台接口实例 * @return InterfaceService @@ -120,4 +110,14 @@ class ExpressService extends Service return $service; } + /** + * 楚才开放平台快递公司 + * @return array + * @throws \think\admin\Exception + */ + public function company(): array + { + return $this->_getInterface()->doRequest('api.auth.express/getCompany'); + } + } \ No newline at end of file diff --git a/app/data/service/GoodsService.php b/app/data/service/GoodsService.php index 3694a1b0a..0c8be413d 100644 --- a/app/data/service/GoodsService.php +++ b/app/data/service/GoodsService.php @@ -13,15 +13,6 @@ use think\admin\Service; class GoodsService extends Service { - /** - * 最大分类级别 - * @return integer - */ - public function getCateMax(): int - { - return 3; - } - /** * 获取分类数据 * @param string $type 数据格式 arr2tree | arr2table @@ -37,33 +28,6 @@ class GoodsService extends Service return DataExtend::$type($query->withoutField('sort,status,deleted,create_at')->select()->toArray()); } - /** - * 获取分类数据 - * @param boolean $simple 简化数据 - * @return array - */ - public function getCateData($simple = true): array - { - $map = ['status' => 1, 'deleted' => 0]; - $cates = $this->app->db->name('ShopGoodsCate')->where($map)->column('id,pid,name', 'id'); - foreach ($cates as $cate) if (isset($cates[$cate['pid']])) $cates[$cate['id']]['parent'] =& $cates[$cate['pid']]; - foreach ($cates as $key => $cate) { - $id = $cate['id']; - $cates[$id]['ids'][] = $cate['id']; - $cates[$id]['names'][] = $cate['name']; - while (isset($cate['parent']) && $cate = $cate['parent']) { - $cates[$id]['ids'][] = $cate['id']; - $cates[$id]['names'][] = $cate['name']; - } - $cates[$id]['ids'] = array_reverse($cates[$id]['ids']); - $cates[$id]['names'] = array_reverse($cates[$id]['names']); - if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) { - unset($cates[$key]); - } - } - return $cates; - } - /** * 获取商品标签数据 * @return array @@ -141,4 +105,40 @@ class GoodsService extends Service return $data; } + /** + * 获取分类数据 + * @param boolean $simple 简化数据 + * @return array + */ + public function getCateData($simple = true): array + { + $map = ['status' => 1, 'deleted' => 0]; + $cates = $this->app->db->name('ShopGoodsCate')->where($map)->column('id,pid,name', 'id'); + foreach ($cates as $cate) if (isset($cates[$cate['pid']])) $cates[$cate['id']]['parent'] =& $cates[$cate['pid']]; + foreach ($cates as $key => $cate) { + $id = $cate['id']; + $cates[$id]['ids'][] = $cate['id']; + $cates[$id]['names'][] = $cate['name']; + while (isset($cate['parent']) && $cate = $cate['parent']) { + $cates[$id]['ids'][] = $cate['id']; + $cates[$id]['names'][] = $cate['name']; + } + $cates[$id]['ids'] = array_reverse($cates[$id]['ids']); + $cates[$id]['names'] = array_reverse($cates[$id]['names']); + if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) { + unset($cates[$key]); + } + } + return $cates; + } + + /** + * 最大分类等级 + * @return integer + */ + public function getCateMax(): int + { + return 3; + } + } \ No newline at end of file diff --git a/app/data/service/MessageService.php b/app/data/service/MessageService.php index ef0c6250a..862b9752e 100644 --- a/app/data/service/MessageService.php +++ b/app/data/service/MessageService.php @@ -23,35 +23,6 @@ class MessageService extends Service */ protected $password; - /** - * 短信服务初始化 - * @return MessageService - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - protected function initialize(): MessageService - { - $this->username = sysconf('zt.username'); - $this->password = sysconf('zt.password'); - return $this; - } - - /** - * 发送自定义短信内容 - * @param string $phone - * @param string $content - * @return array - */ - public function send(string $phone, string $content): array - { - [$state, $message, $record] = $this->_request('v2/sendSms', ['mobile' => $phone, 'content' => $content]); - $this->app->db->name('DataUserMessage')->insert([ - 'phone' => $phone, 'content' => $content, 'result' => $message, 'status' => $state ? 1 : 0, - ]); - return [$state, $message, $record]; - } - /** * 短信条数查询 */ @@ -61,53 +32,6 @@ class MessageService extends Service return [$state, $message, $state ? $result['sumSms'] : 0]; } - /** - * 验证手机短信验证码 - * @param string $code 验证码 - * @param string $phone 手机号验证 - * @param string $tplcode - * @return boolean - */ - public function checkVerifyCode(string $code, string $phone, string $tplcode = 'zt.tplcode_register'): bool - { - $cache = $this->app->cache->get($ckey = md5("code-{$tplcode}-{$phone}"), []); - return is_array($cache) && isset($cache['code']) && $cache['code'] == $code; - } - - /** - * 验证手机短信验证码 - * @param string $phone 手机号码 - * @param integer $wait 等待时间 - * @param string $tplcode 模板编号 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function sendVerifyCode(string $phone, int $wait = 120, string $tplcode = 'zt.tplcode_register'): array - { - $content = sysconf($tplcode) ?: '您的短信验证码为{code},请在十分钟内完成操作!'; - $cache = $this->app->cache->get($ckey = md5("code-{$tplcode}-{$phone}"), []); - // 检查是否已经发送 - if (is_array($cache) && isset($cache['time']) && $cache['time'] > time() - $wait) { - $dtime = ($cache['time'] + $wait < time()) ? 0 : ($wait - time() + $cache['time']); - return [1, '短信验证码已经发送!', ['time' => $dtime]]; - } - // 生成新的验证码 - [$code, $time] = [rand(100000, 999999), time()]; - $this->app->cache->set($ckey, ['code' => $code, 'time' => $time], 600); - // 尝试发送短信内容 - [$state] = $this->send($phone, preg_replace_callback("|{(.*?)}|", function ($matches) use ($code) { - return $matches[1] === 'code' ? $code : $matches[1]; - }, $content)); - if ($state) return [1, '短信验证码发送成功!', [ - 'time' => ($time + $wait < time()) ? 0 : ($wait - time() + $time)], - ]; else { - $this->app->cache->delete($ckey); - return [0, '短信发送失败,请稍候再试!', []]; - } - } - /** * 执行网络请求 * @param string $url 接口请求地址 @@ -174,4 +98,80 @@ class MessageService extends Service return $arrs[$code] ?? $code; } + /** + * 验证手机短信验证码 + * @param string $code 验证码 + * @param string $phone 手机号验证 + * @param string $tplcode + * @return boolean + */ + public function checkVerifyCode(string $code, string $phone, string $tplcode = 'zt.tplcode_register'): bool + { + $cache = $this->app->cache->get($ckey = md5("code-{$tplcode}-{$phone}"), []); + return is_array($cache) && isset($cache['code']) && $cache['code'] == $code; + } + + /** + * 验证手机短信验证码 + * @param string $phone 手机号码 + * @param integer $wait 等待时间 + * @param string $tplcode 模板编号 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function sendVerifyCode(string $phone, int $wait = 120, string $tplcode = 'zt.tplcode_register'): array + { + $content = sysconf($tplcode) ?: '您的短信验证码为{code},请在十分钟内完成操作!'; + $cache = $this->app->cache->get($ckey = md5("code-{$tplcode}-{$phone}"), []); + // 检查是否已经发送 + if (is_array($cache) && isset($cache['time']) && $cache['time'] > time() - $wait) { + $dtime = ($cache['time'] + $wait < time()) ? 0 : ($wait - time() + $cache['time']); + return [1, '短信验证码已经发送!', ['time' => $dtime]]; + } + // 生成新的验证码 + [$code, $time] = [rand(100000, 999999), time()]; + $this->app->cache->set($ckey, ['code' => $code, 'time' => $time], 600); + // 尝试发送短信内容 + [$state] = $this->send($phone, preg_replace_callback("|{(.*?)}|", function ($matches) use ($code) { + return $matches[1] === 'code' ? $code : $matches[1]; + }, $content)); + if ($state) return [1, '短信验证码发送成功!', [ + 'time' => ($time + $wait < time()) ? 0 : ($wait - time() + $time)], + ]; else { + $this->app->cache->delete($ckey); + return [0, '短信发送失败,请稍候再试!', []]; + } + } + + /** + * 发送自定义短信内容 + * @param string $phone + * @param string $content + * @return array + */ + public function send(string $phone, string $content): array + { + [$state, $message, $record] = $this->_request('v2/sendSms', ['mobile' => $phone, 'content' => $content]); + $this->app->db->name('DataUserMessage')->insert([ + 'phone' => $phone, 'content' => $content, 'result' => $message, 'status' => $state ? 1 : 0, + ]); + return [$state, $message, $record]; + } + + /** + * 短信服务初始化 + * @return MessageService + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected function initialize(): MessageService + { + $this->username = sysconf('zt.username'); + $this->password = sysconf('zt.password'); + return $this; + } + } \ No newline at end of file diff --git a/app/data/service/OrderService.php b/app/data/service/OrderService.php index f6c4ba261..cc1b853bb 100644 --- a/app/data/service/OrderService.php +++ b/app/data/service/OrderService.php @@ -96,7 +96,7 @@ class OrderService extends Service } /** - * 获取级别折扣比例 + * 获取等级折扣比例 * @param int $disId 折扣方案ID * @param int $vipCode 等级序号 * @param float $disRate 默认比例 diff --git a/app/data/service/PaymentService.php b/app/data/service/PaymentService.php index 6a670e2d7..f84f91571 100644 --- a/app/data/service/PaymentService.php +++ b/app/data/service/PaymentService.php @@ -120,36 +120,31 @@ abstract class PaymentService 'bind' => [UserAdminService::API_TYPE_WECHAT], ], ]; - - /** - * 当前应用 - * @var App - */ - protected $app; - - /** - * 支付参数编号 - * @var string - */ - protected $code; - - /** - * 默认支付类型 - * @var string - */ - protected $type; - - /** - * 当前支付参数 - * @var array - */ - protected $params; - /** * 支付服务对象 * @var array */ protected static $driver = []; + /** + * 当前应用 + * @var App + */ + protected $app; + /** + * 支付参数编号 + * @var string + */ + protected $code; + /** + * 默认支付类型 + * @var string + */ + protected $type; + /** + * 当前支付参数 + * @var array + */ + protected $params; /** * PaymentService constructor. @@ -195,31 +190,6 @@ abstract class PaymentService } } - /** - * 获取支付支付名称 - * @param string $type - * @return string - */ - public static function name(string $type): string - { - return self::TYPES[$type]['name'] ?? $type; - } - - /** - * 获取支付类型 - * @return array - */ - public static function types(): array - { - $types = []; - foreach (self::TYPES as $k => $v) if (isset($v['bind'])) { - if (array_intersect($v['bind'], array_keys(UserAdminService::TYPES))) { - $types[$k] = $v; - } - } - return $types; - } - /** * 获取支付配置参数 * @param string $code @@ -250,6 +220,101 @@ abstract class PaymentService } } + /** + * 获取支付支付名称 + * @param string $type + * @return string + */ + public static function name(string $type): string + { + return self::TYPES[$type]['name'] ?? $type; + } + + /** + * 获取支付类型 + * @return array + */ + public static function types(): array + { + $types = []; + foreach (self::TYPES as $k => $v) if (isset($v['bind'])) { + if (array_intersect($v['bind'], array_keys(UserAdminService::TYPES))) { + $types[$k] = $v; + } + } + return $types; + } + + /** + * 订单主动查询 + * @param string $orderNo + * @return array + */ + abstract public function query(string $orderNo): array; + + /** + * 支付通知处理 + * @return string + */ + abstract public function notify(): string; + + /** + * 创建支付订单 + * @param string $openid 用户OPENID + * @param string $orderNo 交易订单单号 + * @param string $paymentAmount 交易订单金额(元) + * @param string $paymentTitle 交易订单名称 + * @param string $paymentRemark 交易订单描述 + * @param string $paymentReturn 支付回跳地址 + * @param string $paymentImage 支付凭证图片 + * @return array + */ + abstract public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array; + + /** + * 创建支付行为 + * @param string $orderNo 商户订单单号 + * @param string $paymentTitle 商户订单标题 + * @param string $paymentAmount 需要支付金额 + */ + protected function createPaymentAction(string $orderNo, string $paymentTitle, string $paymentAmount) + { + $this->app->db->name('ShopPaymentItem')->insert([ + 'payment_code' => $this->code, 'payment_type' => $this->type, + 'order_amount' => $paymentAmount, 'order_name' => $paymentTitle, 'order_no' => $orderNo, + ]); + } + + /** + * 更新支付记录并更新订单 + * @param string $orderNo 商户订单单号 + * @param string $paymentTrade 平台交易单号 + * @param string $paymentAmount 实际到账金额 + * @param string $paymentRemark 平台支付备注 + * @return boolean + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected function updatePaymentAction(string $orderNo, string $paymentTrade, string $paymentAmount, string $paymentRemark = '在线支付'): bool + { + // 更新支付记录 + data_save('ShopPaymentItem', [ + 'order_no' => $orderNo, + 'payment_code' => $this->code, + 'payment_type' => $this->type, + 'payment_trade' => $paymentTrade, + 'payment_amount' => $paymentAmount, + 'payment_status' => 1, + 'payment_datatime' => date('Y-m-d H:i:s'), + ], 'order_no', [ + 'payment_code' => $this->code, + 'payment_type' => $this->type, + ]); + // 更新记录状态 + return $this->updateOrder($orderNo, $paymentTrade, $paymentAmount, $paymentRemark); + } + /** * 订单支付更新操作 * @param string $orderNo 订单单号 @@ -295,74 +360,4 @@ abstract class PaymentService } return true; } - - /** - * 创建支付行为 - * @param string $orderNo 商户订单单号 - * @param string $paymentTitle 商户订单标题 - * @param string $paymentAmount 需要支付金额 - */ - protected function createPaymentAction(string $orderNo, string $paymentTitle, string $paymentAmount) - { - $this->app->db->name('ShopPaymentItem')->insert([ - 'payment_code' => $this->code, 'payment_type' => $this->type, - 'order_amount' => $paymentAmount, 'order_name' => $paymentTitle, 'order_no' => $orderNo, - ]); - } - - /** - * 更新支付记录并更新订单 - * @param string $orderNo 商户订单单号 - * @param string $paymentTrade 平台交易单号 - * @param string $paymentAmount 实际到账金额 - * @param string $paymentRemark 平台支付备注 - * @return boolean - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - protected function updatePaymentAction(string $orderNo, string $paymentTrade, string $paymentAmount, string $paymentRemark = '在线支付'): bool - { - // 更新支付记录 - data_save('ShopPaymentItem', [ - 'order_no' => $orderNo, - 'payment_code' => $this->code, - 'payment_type' => $this->type, - 'payment_trade' => $paymentTrade, - 'payment_amount' => $paymentAmount, - 'payment_status' => 1, - 'payment_datatime' => date('Y-m-d H:i:s'), - ], 'order_no', [ - 'payment_code' => $this->code, - 'payment_type' => $this->type, - ]); - // 更新记录状态 - return $this->updateOrder($orderNo, $paymentTrade, $paymentAmount, $paymentRemark); - } - - /** - * 订单主动查询 - * @param string $orderNo - * @return array - */ - abstract public function query(string $orderNo): array; - - /** - * 支付通知处理 - * @return string - */ - abstract public function notify(): string; - - /** - * 创建支付订单 - * @param string $openid 用户OPENID - * @param string $orderNo 交易订单单号 - * @param string $paymentAmount 交易订单金额(元) - * @param string $paymentTitle 交易订单名称 - * @param string $paymentRemark 交易订单描述 - * @param string $paymentReturn 支付回跳地址 - * @param string $paymentImage 支付凭证图片 - * @return array - */ - abstract public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array; } \ No newline at end of file diff --git a/app/data/service/RebateService.php b/app/data/service/RebateService.php index 708dddaeb..996f13ba3 100644 --- a/app/data/service/RebateService.php +++ b/app/data/service/RebateService.php @@ -62,31 +62,6 @@ class RebateService extends Service */ private $table = 'DataUserRebate'; - /** - * 返利服务初始化 - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - protected function initialize() - { - // 返利奖励到账时机 - // settl_type 为 1 支付后立即到账 - // settl_type 为 2 确认后立即到账 - $this->status = $this->config('settl_type') > 1 ? 0 : 1; - } - - /** - * 获取奖励名称 - * @param string $prize - * @return string - */ - public function name(string $prize): string - { - return self::PRIZES[$prize]['name'] ?? $prize; - } - /** * 执行订单返利处理 * @param string $orderNo @@ -130,6 +105,36 @@ class RebateService extends Service } } + /** + * 返利服务初始化 + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected function initialize() + { + // 返利奖励到账时机 + // settl_type 为 1 支付后立即到账 + // settl_type 为 2 确认后立即到账 + $this->status = $this->config('settl_type') > 1 ? 0 : 1; + } + + /** + * 获取配置数据 + * @param ?string $name 配置名称 + * @return array|string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function config(?string $name = null) + { + static $data = []; + if (empty($data)) $data = sysdata('RebateRule'); + return is_null($name) ? $data : ($data[$name] ?? ''); + } + /** * 用户首推奖励 * @return boolean @@ -161,6 +166,53 @@ class RebateService extends Service return true; } + /** + * 检查等级是否有奖励 + * @param string $prize 奖励规则 + * @param integer $level 用户等级 + * @return boolean + */ + private function isPrizeStatus(string $prize, int $level): bool + { + $map = [['number', '=', $level], ['rebate_rule', 'like', "%,{$prize},%"]]; + return $this->app->db->name('DataBaseUpgrade')->where($map)->count() > 0; + } + + /** + * 获取奖励名称 + * @param string $prize + * @return string + */ + public function name(string $prize): string + { + return self::PRIZES[$prize]['name'] ?? $prize; + } + + /** + * 写返利记录 + * @param int $uid + * @param array $map + * @param string $name + * @param float $amount + * @throws \think\db\exception\DbException + */ + private function addRebateRecord(int $uid, array $map, string $name, float $amount) + { + $this->app->db->name($this->table)->insert(array_merge($map, [ + 'uid' => $uid, + 'date' => date('Y-m-d'), + 'code' => CodeExtend::uniqidDate(20, 'R'), + 'name' => $name, + 'amount' => $amount, + 'status' => $this->status, + 'order_no' => $this->order['order_no'], + 'order_uid' => $this->order['uid'], + 'order_amount' => $this->order['amount_total'], + ])); + // 刷新用户返利统计 + UserRebateService::instance()->amount($uid); + } + /** * 用户复购奖励 * @return boolean @@ -366,56 +418,4 @@ class RebateService extends Service } return true; } - - /** - * 获取配置数据 - * @param ?string $name 配置名称 - * @return array|string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function config(?string $name = null) - { - static $data = []; - if (empty($data)) $data = sysdata('RebateRule'); - return is_null($name) ? $data : ($data[$name] ?? ''); - } - - /** - * 写返利记录 - * @param int $uid - * @param array $map - * @param string $name - * @param float $amount - * @throws \think\db\exception\DbException - */ - private function addRebateRecord(int $uid, array $map, string $name, float $amount) - { - $this->app->db->name($this->table)->insert(array_merge($map, [ - 'uid' => $uid, - 'date' => date('Y-m-d'), - 'code' => CodeExtend::uniqidDate(20, 'R'), - 'name' => $name, - 'amount' => $amount, - 'status' => $this->status, - 'order_no' => $this->order['order_no'], - 'order_uid' => $this->order['uid'], - 'order_amount' => $this->order['amount_total'], - ])); - // 刷新用户返利统计 - UserRebateService::instance()->amount($uid); - } - - /** - * 检查等级是否有奖励 - * @param string $prize 奖励规则 - * @param integer $level 用户等级 - * @return boolean - */ - private function isPrizeStatus(string $prize, int $level): bool - { - $map = [['number', '=', $level], ['rebate_rule', 'like', "%,{$prize},%"]]; - return $this->app->db->name('DataBaseUpgrade')->where($map)->count() > 0; - } } \ No newline at end of file diff --git a/app/data/service/UserAdminService.php b/app/data/service/UserAdminService.php index 843715418..c83805ddd 100644 --- a/app/data/service/UserAdminService.php +++ b/app/data/service/UserAdminService.php @@ -48,30 +48,6 @@ class UserAdminService extends Service ], ]; - /** - * 获取用户数据 - * @param integer $uuid 用户UID - * @param ?string $type 接口类型 - * @return array - * @throws DbException - * @throws Exception - */ - public function get(int $uuid, ?string $type = null): array - { - $user = $this->app->db->name('DataUser')->where(['id' => $uuid, 'deleted' => 0])->findOrEmpty(); - if (empty($user)) throw new Exception('指定UID用户不存在'); - if (!is_null($type)) { - $data = $this->app->db->name('DataUserToken')->where(['uid' => $uuid, 'type' => $type])->findOrEmpty(); - if (empty($data)) { - [$state, $info, $data] = UserTokenService::instance()->token($uuid, $type); - if (empty($state) || empty($data)) throw new Exception($info); - } - $user['token'] = ['token' => $data['token'], 'expire' => $data['time']]; - } - unset($user['deleted'], $user['password']); - return $user; - } - /** * 更新用户用户参数 * @param array $map 查询条件 @@ -99,6 +75,30 @@ class UserAdminService extends Service return $this->get($uuid, $type); } + /** + * 获取用户数据 + * @param integer $uuid 用户UID + * @param ?string $type 接口类型 + * @return array + * @throws DbException + * @throws Exception + */ + public function get(int $uuid, ?string $type = null): array + { + $user = $this->app->db->name('DataUser')->where(['id' => $uuid, 'deleted' => 0])->findOrEmpty(); + if (empty($user)) throw new Exception('指定UID用户不存在'); + if (!is_null($type)) { + $data = $this->app->db->name('DataUserToken')->where(['uid' => $uuid, 'type' => $type])->findOrEmpty(); + if (empty($data)) { + [$state, $info, $data] = UserTokenService::instance()->token($uuid, $type); + if (empty($state) || empty($data)) throw new Exception($info); + } + $user['token'] = ['token' => $data['token'], 'expire' => $data['time']]; + } + unset($user['deleted'], $user['password']); + return $user; + } + /** * 获取用户数据统计 * @param int $uuid 用户UID diff --git a/app/data/service/UserBalanceService.php b/app/data/service/UserBalanceService.php index 36a9e6a89..c83c9fee5 100644 --- a/app/data/service/UserBalanceService.php +++ b/app/data/service/UserBalanceService.php @@ -12,30 +12,6 @@ use think\admin\Service; class UserBalanceService extends Service { - /** - * 同步刷新用户余额 - * @param int $uuid 用户UID - * @param array $nots 排除的订单 - * @return array [total, count] - * @throws \think\db\exception\DbException - */ - public function amount(int $uuid, array $nots = []): array - { - if ($uuid > 0) { - $total = abs($this->app->db->name('DataUserBalance')->whereRaw("uid='{$uuid}' and amount>0 and deleted=0")->sum('amount')); - $count = abs($this->app->db->name('DataUserBalance')->whereRaw("uid='{$uuid}' and amount<0 and deleted=0")->sum('amount')); - if (empty($nots)) { - $this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]); - } else { - $count -= $this->app->db->name('DataUserBalance')->whereRaw("uid={$uuid}")->whereIn('code', $nots)->sum('amount'); - } - } else { - $total = abs($this->app->db->name('DataUserBalance')->whereRaw("amount>0 and deleted=0")->sum('amount')); - $count = abs($this->app->db->name('DataUserBalance')->whereRaw("amount<0 and deleted=0")->sum('amount')); - } - return [$total, $count]; - } - /** * 验证订单发放余额 * @param string $orderNo @@ -62,4 +38,28 @@ class UserBalanceService extends Service return $this->amount($order['uid']); } + /** + * 同步刷新用户余额 + * @param int $uuid 用户UID + * @param array $nots 排除的订单 + * @return array [total, count] + * @throws \think\db\exception\DbException + */ + public function amount(int $uuid, array $nots = []): array + { + if ($uuid > 0) { + $total = abs($this->app->db->name('DataUserBalance')->whereRaw("uid='{$uuid}' and amount>0 and deleted=0")->sum('amount')); + $count = abs($this->app->db->name('DataUserBalance')->whereRaw("uid='{$uuid}' and amount<0 and deleted=0")->sum('amount')); + if (empty($nots)) { + $this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]); + } else { + $count -= $this->app->db->name('DataUserBalance')->whereRaw("uid={$uuid}")->whereIn('code', $nots)->sum('amount'); + } + } else { + $total = abs($this->app->db->name('DataUserBalance')->whereRaw("amount>0 and deleted=0")->sum('amount')); + $count = abs($this->app->db->name('DataUserBalance')->whereRaw("amount<0 and deleted=0")->sum('amount')); + } + return [$total, $count]; + } + } \ No newline at end of file diff --git a/app/data/service/UserTokenService.php b/app/data/service/UserTokenService.php index 18e9118e8..dac7b3a90 100644 --- a/app/data/service/UserTokenService.php +++ b/app/data/service/UserTokenService.php @@ -49,6 +49,29 @@ class UserTokenService extends Service } } + /** + * 获取令牌的认证值 + * @return string + */ + private function _buildTokenVerify(): string + { + return md5($this->app->request->server('HTTP_USER_AGENT', '-')); + } + + /** + * 延期 TOKEN 有效时间 + * @param string $type 接口类型 + * @param string $token 授权令牌 + * @throws DbException + */ + public function expire(string $type, string $token) + { + $map = ['type' => $type, 'token' => $token]; + $this->app->db->name('DataUserToken')->where($map)->update([ + 'time' => time() + $this->expire, + ]); + } + /** * 生成新的用户令牌 * @param int $uuid 授权用户 @@ -73,27 +96,4 @@ class UserTokenService extends Service return [0, '刷新认证失败', []]; } } - - /** - * 延期 TOKEN 有效时间 - * @param string $type 接口类型 - * @param string $token 授权令牌 - * @throws DbException - */ - public function expire(string $type, string $token) - { - $map = ['type' => $type, 'token' => $token]; - $this->app->db->name('DataUserToken')->where($map)->update([ - 'time' => time() + $this->expire, - ]); - } - - /** - * 获取令牌的认证值 - * @return string - */ - private function _buildTokenVerify(): string - { - return md5($this->app->request->server('HTTP_USER_AGENT', '-')); - } } \ No newline at end of file diff --git a/app/data/service/UserUpgradeService.php b/app/data/service/UserUpgradeService.php index fcac7abbe..c6746e4ff 100644 --- a/app/data/service/UserUpgradeService.php +++ b/app/data/service/UserUpgradeService.php @@ -22,6 +22,43 @@ class UserUpgradeService extends Service return $query->where(['status' => 1])->order('number asc')->column('*', 'number'); } + /** + * 尝试绑定上级代理 + * @param integer $uid 用户UID + * @param integer $pid 代理UID + * @param boolean $force 正式绑定 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function bindAgent(int $uid, int $pid = 0, bool $force = true): array + { + $user = $this->app->db->name('DataUser')->where(['id' => $uid])->find(); + if (empty($user)) return [0, '用户查询失败']; + if (!empty($user['pids'])) return [1, '已绑定推荐人']; + // 检查代理用户 + if (empty($pid)) $pid = $user['pid0']; + if (empty($pid)) return [0, '绑定推荐人不存在']; + if ($uid == $pid) return [0, '推荐人不能是自己']; + $parant = $this->app->db->name('DataUser')->where(['id' => $pid])->find(); + if (empty($parant['vip_code'])) return [0, '推荐人无推荐资格']; + if (stripos($parant['path'], "-{$uid}-") !== false) return [0, '不能绑定下属']; + // 组装代理数据 + $path = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-"; + $data = [ + 'pid0' => $parant['id'], 'pid1' => $parant['id'], 'pid2' => $parant['pid1'], + 'pids' => $force ? 1 : 0, 'path' => $path, 'layer' => substr_count($path, '-'), + ]; + // 更新用户代理 + if ($this->app->db->name('DataUser')->where(['id' => $uid])->update($data) !== false) { + $this->upgrade($uid); + return [1, '绑定代理成功']; + } else { + return [0, '绑定代理失败']; + } + } + /** * 同步计算用户等级 * @param integer $uid 指定用户UID @@ -101,41 +138,4 @@ class UserUpgradeService extends Service ]); return ($parent && $user['pid1'] > 0) ? $this->upgrade($user['pid1'], false) : true; } - - /** - * 尝试绑定上级代理 - * @param integer $uid 用户UID - * @param integer $pid 代理UID - * @param boolean $force 正式绑定 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function bindAgent(int $uid, int $pid = 0, bool $force = true): array - { - $user = $this->app->db->name('DataUser')->where(['id' => $uid])->find(); - if (empty($user)) return [0, '用户查询失败']; - if (!empty($user['pids'])) return [1, '已绑定推荐人']; - // 检查代理用户 - if (empty($pid)) $pid = $user['pid0']; - if (empty($pid)) return [0, '绑定推荐人不存在']; - if ($uid == $pid) return [0, '推荐人不能是自己']; - $parant = $this->app->db->name('DataUser')->where(['id' => $pid])->find(); - if (empty($parant['vip_code'])) return [0, '推荐人无推荐资格']; - if (stripos($parant['path'], "-{$uid}-") !== false) return [0, '不能绑定下属']; - // 组装代理数据 - $path = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-"; - $data = [ - 'pid0' => $parant['id'], 'pid1' => $parant['id'], 'pid2' => $parant['pid1'], - 'pids' => $force ? 1 : 0, 'path' => $path, 'layer' => substr_count($path, '-'), - ]; - // 更新用户代理 - if ($this->app->db->name('DataUser')->where(['id' => $uid])->update($data) !== false) { - $this->upgrade($uid); - return [1, '绑定代理成功']; - } else { - return [0, '绑定代理失败']; - } - } } \ No newline at end of file diff --git a/app/data/service/payment/AlipayPaymentService.php b/app/data/service/payment/AlipayPaymentService.php index 4b2ee2825..a4ad08778 100644 --- a/app/data/service/payment/AlipayPaymentService.php +++ b/app/data/service/payment/AlipayPaymentService.php @@ -19,41 +19,6 @@ class AlipayPaymentService extends PaymentService */ protected $config = []; - /** - * 支付服务初始化 - * @return $this - */ - protected function initialize(): AlipayPaymentService - { - $this->config = [ - // 沙箱模式 - 'debug' => false, - // 签名类型(RSA|RSA2) - 'sign_type' => "RSA2", - // 应用ID - 'appid' => $this->params['alipay_appid'], - // 支付宝公钥 (1行填写,特别注意,这里是支付宝公钥,不是应用公钥,最好从开发者中心的网页上去复制) - 'public_key' => $this->_trimCertHeader($this->params['alipay_public_key']), - // 支付宝私钥 (1行填写) - 'private_key' => $this->_trimCertHeader($this->params['alipay_private_key']), - // 支付成功通知地址 - 'notify_url' => '', - // 网页支付回跳地址 - 'return_url' => '', - ]; - return $this; - } - - /** - * 去除证书内容前后缀 - * @param string $content - * @return string - */ - private function _trimCertHeader(string $content): string - { - return preg_replace(['/\s+/', '/-{5}.*?-{5}/'], '', $content); - } - /** * 创建订单支付参数 * @param string $openid 用户OPENID @@ -138,4 +103,39 @@ class AlipayPaymentService extends PaymentService { return \AliPay\App::instance($this->config)->query($orderNo); } + + /** + * 支付服务初始化 + * @return $this + */ + protected function initialize(): AlipayPaymentService + { + $this->config = [ + // 沙箱模式 + 'debug' => false, + // 签名类型(RSA|RSA2) + 'sign_type' => "RSA2", + // 应用ID + 'appid' => $this->params['alipay_appid'], + // 支付宝公钥 (1行填写,特别注意,这里是支付宝公钥,不是应用公钥,最好从开发者中心的网页上去复制) + 'public_key' => $this->_trimCertHeader($this->params['alipay_public_key']), + // 支付宝私钥 (1行填写) + 'private_key' => $this->_trimCertHeader($this->params['alipay_private_key']), + // 支付成功通知地址 + 'notify_url' => '', + // 网页支付回跳地址 + 'return_url' => '', + ]; + return $this; + } + + /** + * 去除证书内容前后缀 + * @param string $content + * @return string + */ + private function _trimCertHeader(string $content): string + { + return preg_replace(['/\s+/', '/-{5}.*?-{5}/'], '', $content); + } } \ No newline at end of file diff --git a/app/data/service/payment/EmptyPaymentService.php b/app/data/service/payment/EmptyPaymentService.php index 78dbe444c..3aecd480c 100644 --- a/app/data/service/payment/EmptyPaymentService.php +++ b/app/data/service/payment/EmptyPaymentService.php @@ -5,6 +5,9 @@ namespace app\data\service\payment; use app\data\service\PaymentService; use think\admin\Exception; use think\admin\extend\CodeExtend; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * 空支付支付 @@ -44,9 +47,9 @@ class EmptyPaymentService extends PaymentService * @param string $paymentImage 支付凭证图片 * @return array * @throws Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = '', string $paymentImage = ''): array { diff --git a/app/data/service/payment/JoinpayPaymentService.php b/app/data/service/payment/JoinpayPaymentService.php index cd7fda9cb..182a6c9ae 100644 --- a/app/data/service/payment/JoinpayPaymentService.php +++ b/app/data/service/payment/JoinpayPaymentService.php @@ -43,19 +43,6 @@ class JoinpayPaymentService extends PaymentService */ protected $mchkey; - /** - * 汇聚支付服务初始化 - * @return JoinpayPaymentService - */ - protected function initialize(): JoinpayPaymentService - { - $this->appid = $this->params['joinpay_appid']; - $this->trade = $this->params['joinpay_trade'];; - $this->mchid = $this->params['joinpay_mch_id']; - $this->mchkey = $this->params['joinpay_mch_key']; - return $this; - } - /** * 创建订单支付参数 * @param string $openid 用户OPENID @@ -110,6 +97,29 @@ class JoinpayPaymentService extends PaymentService } } + /** + * 执行数据请求 + * @param array $data + * @return array + */ + private function _doReuest($data = []): array + { + $data['hmac'] = $this->_doSign($data); + return json_decode(HttpExtend::post($this->uri, $data), true); + } + + /** + * 请求数据签名 + * @param array $data + * @return string + */ + private function _doSign(array $data): string + { + ksort($data); + unset($data['hmac']); + return md5(join('', $data) . $this->mchkey); + } + /** * 查询订单数据 * @param string $orderNo @@ -147,25 +157,15 @@ class JoinpayPaymentService extends PaymentService } /** - * 请求数据签名 - * @param array $data - * @return string + * 汇聚支付服务初始化 + * @return JoinpayPaymentService */ - private function _doSign(array $data): string + protected function initialize(): JoinpayPaymentService { - ksort($data); - unset($data['hmac']); - return md5(join('', $data) . $this->mchkey); - } - - /** - * 执行数据请求 - * @param array $data - * @return array - */ - private function _doReuest($data = []): array - { - $data['hmac'] = $this->_doSign($data); - return json_decode(HttpExtend::post($this->uri, $data), true); + $this->appid = $this->params['joinpay_appid']; + $this->trade = $this->params['joinpay_trade'];; + $this->mchid = $this->params['joinpay_mch_id']; + $this->mchkey = $this->params['joinpay_mch_key']; + return $this; } } \ No newline at end of file diff --git a/app/data/service/payment/WechatPaymentService.php b/app/data/service/payment/WechatPaymentService.php index 622669088..7bfd5b27e 100644 --- a/app/data/service/payment/WechatPaymentService.php +++ b/app/data/service/payment/WechatPaymentService.php @@ -19,21 +19,6 @@ class WechatPaymentService extends PaymentService */ protected $payment; - /** - * 微信支付服务初始化 - * @return WechatPaymentService - */ - protected function initialize(): WechatPaymentService - { - $this->payment = Order::instance([ - 'appid' => $this->params['wechat_appid'], - 'mch_id' => $this->params['wechat_mch_id'], - 'mch_key' => $this->params['wechat_mch_key'], - 'cache_path' => $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . 'wechat', - ]); - return $this; - } - /** * 创建订单支付参数 * @param string $openid 用户OPENID @@ -127,4 +112,19 @@ class WechatPaymentService extends PaymentService return $this->payment->getNotifySuccessReply(); } } + + /** + * 微信支付服务初始化 + * @return WechatPaymentService + */ + protected function initialize(): WechatPaymentService + { + $this->payment = Order::instance([ + 'appid' => $this->params['wechat_appid'], + 'mch_id' => $this->params['wechat_mch_id'], + 'mch_key' => $this->params['wechat_mch_key'], + 'cache_path' => $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . 'wechat', + ]); + return $this; + } } \ No newline at end of file diff --git a/app/data/view/base_config/cropper.html b/app/data/view/base_config/cropper.html index 26bda2651..a862d6599 100644 --- a/app/data/view/base_config/cropper.html +++ b/app/data/view/base_config/cropper.html @@ -9,10 +9,10 @@

3. 保存位置数据,下次可直接显示

- img + img
- - + +
diff --git a/app/data/view/base_config/page_form.html b/app/data/view/base_config/page_form.html index 91930db81..ad3c1961b 100644 --- a/app/data/view/base_config/page_form.html +++ b/app/data/view/base_config/page_form.html @@ -1,13 +1,13 @@ {extend name="../../admin/view/main"} {block name='content'} -
+
@@ -21,8 +21,8 @@
- - + +
diff --git a/app/data/view/base_config/slider.html b/app/data/view/base_config/slider.html index f40f2fa1b..4a2884472 100644 --- a/app/data/view/base_config/slider.html +++ b/app/data/view/base_config/slider.html @@ -2,14 +2,14 @@ {block name="content"}
- +
{$title|default='图片数据管理'} ( 建议上传图片尺寸为 690px 250px )
@@ -20,23 +20,23 @@
-
+
diff --git a/app/data/view/base_config/wxapp.html b/app/data/view/base_config/wxapp.html index 2a02ce780..be63da2e0 100644 --- a/app/data/view/base_config/wxapp.html +++ b/app/data/view/base_config/wxapp.html @@ -2,7 +2,7 @@ {block name="content"}
-
+
{$title|default='小程序接口配置'} ( 微信公众号平台配置获取 )
@@ -10,13 +10,13 @@ diff --git a/app/data/view/base_discount/form.html b/app/data/view/base_discount/form.html index 7044e10fe..b8b746ca6 100644 --- a/app/data/view/base_discount/form.html +++ b/app/data/view/base_discount/form.html @@ -1,10 +1,10 @@ - +
@@ -26,7 +26,7 @@ @@ -39,15 +39,15 @@
- {notempty name='vo.id'}{/notempty} + {notempty name='vo.id'}{/notempty}
- +
diff --git a/app/data/view/base_discount/index.html b/app/data/view/base_discount/index.html index e130bb04b..7420f9ca9 100644 --- a/app/data/view/base_discount/index.html +++ b/app/data/view/base_discount/index.html @@ -2,7 +2,7 @@ {block name="button"} - + {/block} @@ -19,7 +19,7 @@ - + 折扣方案 等级折扣 @@ -32,10 +32,10 @@ {foreach $list as $key=>$vo} - + - + {$vo.name|default=''} @@ -55,13 +55,13 @@ - 禁 用 + 禁 用 - 启 用 + 启 用 - 删 除 + 删 除 diff --git a/app/data/view/base_notify/form.html b/app/data/view/base_notify/form.html index 597c354a8..aaf356b61 100644 --- a/app/data/view/base_notify/form.html +++ b/app/data/view/base_notify/form.html @@ -1,30 +1,30 @@ {extend name="../../admin/view/main"} {block name='content'} - +
- +
通知内容 Notify Content
- {notempty name='vo.id'}{/notempty} - {notempty name='vo.code'}{/notempty} + {notempty name='vo.id'}{/notempty} + {notempty name='vo.code'}{/notempty}
- - + +
diff --git a/app/data/view/base_notify/index.html b/app/data/view/base_notify/index.html index a066303b7..de2b06802 100644 --- a/app/data/view/base_notify/index.html +++ b/app/data/view/base_notify/index.html @@ -3,11 +3,11 @@ {block name="button"} - + - + {/block} @@ -22,7 +22,7 @@ - + 通知标题 通知状态 @@ -35,10 +35,10 @@ {foreach $list as $key=>$vo} - + - + {$vo.name|default=''} {if $vo.status eq 0}已禁用{elseif $vo.status eq 1}已激活{/if} @@ -46,7 +46,7 @@ - 编 辑 + 编 辑 @@ -56,7 +56,7 @@ - 删 除 + 删 除 diff --git a/app/data/view/base_notify/index_search.html b/app/data/view/base_notify/index_search.html index c8ab79de5..e10953e67 100644 --- a/app/data/view/base_notify/index_search.html +++ b/app/data/view/base_notify/index_search.html @@ -1,10 +1,10 @@
条件搜索 - +
@@ -26,7 +26,7 @@
diff --git a/app/data/view/base_upgrade/form.html b/app/data/view/base_upgrade/form.html index 2ac844a0f..c3060b5f7 100644 --- a/app/data/view/base_upgrade/form.html +++ b/app/data/view/base_upgrade/form.html @@ -1,4 +1,4 @@ - +
@@ -16,7 +16,7 @@
@@ -27,9 +27,9 @@ {php}$vo['upgrade_type'] = $vo['upgrade_type'] ?? 1;{/php} {foreach [1=>'达成所有条件',0=>'达成任何条件'] as $k => $v} {if isset($vo.upgrade_type) and $vo.upgrade_type eq $k} - + {else} - + {/if}{/foreach}
@@ -39,54 +39,54 @@
@@ -96,9 +96,9 @@ 发放奖利
{foreach $prizes as $prize}{if isset($vo.rebate_rule) && is_array($vo.rebate_rule) && in_array($prize.code, $vo.rebate_rule)} - + {else} - + {/if}{/foreach}
@@ -106,17 +106,17 @@
等级描述
- {notempty name='vo.id'}{/notempty} - {notempty name='vo.number'}{/notempty} + {notempty name='vo.id'}{/notempty} + {notempty name='vo.number'}{/notempty}
- +
diff --git a/app/data/view/base_upgrade/index.html b/app/data/view/base_upgrade/index.html index 9399e73fb..ac54390c6 100644 --- a/app/data/view/base_upgrade/index.html +++ b/app/data/view/base_upgrade/index.html @@ -2,11 +2,11 @@ {block name="button"} - + - + {/block} @@ -40,7 +40,7 @@ {foreach $list as $key=>$vo} - + [ {$vo.number} ] {$vo.name|default=''} {if $vo.upgrade_type eq 1}全部完成{else}任何条件{/if} @@ -63,7 +63,7 @@ - 删 除 + 删 除 diff --git a/app/data/view/news_item/form.html b/app/data/view/news_item/form.html index 4afce8e01..03ab4e9b7 100644 --- a/app/data/view/news_item/form.html +++ b/app/data/view/news_item/form.html @@ -1,7 +1,7 @@ {extend name="../../admin/view/main"} {block name='content'} - +
{notempty name='marks'}
@@ -9,9 +9,9 @@ Mark Name
{foreach $marks as $tag}{if isset($vo.mark) && is_array($vo.mark) && in_array($tag.name, $vo.mark)} - + {else} - + {/if}{/foreach}
@@ -21,8 +21,8 @@ 文章封面 Conver Image
@@ -30,30 +30,30 @@
富文本内容 Article Content
- {notempty name='vo.id'}{/notempty} - {notempty name='vo.code'}{/notempty} + {notempty name='vo.id'}{/notempty} + {notempty name='vo.code'}{/notempty}
- - + +
diff --git a/app/data/view/news_item/index.html b/app/data/view/news_item/index.html index 8894e41a3..7daca71d0 100644 --- a/app/data/view/news_item/index.html +++ b/app/data/view/news_item/index.html @@ -2,15 +2,15 @@ {block name="button"} - + - + - + {/block} @@ -25,7 +25,7 @@ - + 文章编号 文章名称 @@ -40,10 +40,10 @@ {foreach $list as $key=>$vo} - + - + {$vo.code|default=''} {$vo.name|default=''} @@ -53,7 +53,7 @@ - 编 辑 + 编 辑 @@ -65,7 +65,7 @@ - 删 除 + 删 除 diff --git a/app/data/view/news_item/index_search.html b/app/data/view/news_item/index_search.html index de8bb342e..14eac751b 100644 --- a/app/data/view/news_item/index_search.html +++ b/app/data/view/news_item/index_search.html @@ -1,17 +1,17 @@
条件搜索 - +
@@ -33,7 +33,7 @@
diff --git a/app/data/view/news_item/select_search.html b/app/data/view/news_item/select_search.html index 7643216e9..73ab0cbdb 100644 --- a/app/data/view/news_item/select_search.html +++ b/app/data/view/news_item/select_search.html @@ -1,10 +1,10 @@
条件搜索 - +
@@ -25,7 +25,7 @@
diff --git a/app/data/view/news_mark/form.html b/app/data/view/news_mark/form.html index 605bd56d6..7544521d4 100644 --- a/app/data/view/news_mark/form.html +++ b/app/data/view/news_mark/form.html @@ -1,9 +1,9 @@ - +
@@ -11,16 +11,16 @@ 标签描述 Mark Remark
- {notempty name='vo.id'}{/notempty} + {notempty name='vo.id'}{/notempty}
- +
\ No newline at end of file diff --git a/app/data/view/news_mark/index.html b/app/data/view/news_mark/index.html index 59dc4310b..4adc3a372 100644 --- a/app/data/view/news_mark/index.html +++ b/app/data/view/news_mark/index.html @@ -11,7 +11,7 @@ - + 标签名称 标签状态 @@ -24,17 +24,17 @@ {foreach $list as $key=>$vo} - + - + {$vo.name|default=''} {if $vo.status eq 0}已禁用{elseif $vo.status eq 1}已激活{/if} {$vo.create_at|format_datetime} {if auth("edit")} - 编 辑 + 编 辑 {/if} {if auth("state") and $vo.status eq 1} 禁 用 @@ -43,7 +43,7 @@ 激 活 {/if} {if auth("remove")} - 删 除 + 删 除 {/if} @@ -53,7 +53,7 @@ {empty name='list'}没有记录哦{else}{$pagehtml|raw|default=''}{/empty}
- +
diff --git a/app/data/view/news_mark/index_search.html b/app/data/view/news_mark/index_search.html index 89ed46871..fae0d6a7b 100644 --- a/app/data/view/news_mark/index_search.html +++ b/app/data/view/news_mark/index_search.html @@ -1,10 +1,10 @@
条件搜索 -
@@ -50,14 +50,14 @@