diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index fdb009e..0480e38 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -21,6 +21,7 @@ use Webman\RedisQueue\Redis; use Yansongda\Pay\Pay; use Webman\Push\Api; use JPush\Client as JPush; +use support\Log; class IndexController extends BaseApiController { @@ -28,19 +29,17 @@ class IndexController extends BaseApiController public function index() { - - // $select=(new Goods())->column('class'); - // $a=array_unique($select); - // $arr=[]; - // foreach($a as $k=>$v){ - // $pid=Goodsclass::where('id',$v)->value('pid'); - // $arr[$pid][]=$v; - // } - // foreach($arr as $k=>$v){ - // Goodsclass::where('id',$k)->update(['children'=>json_encode($v,true)]); - // } - $a=Goodsclass::where('pid',0)->where('children','<>',null)->column('id'); - d ($a); + $auth_code=$this->request->get('auth_code'); + $config = Config::get('payment'); + Pay::config($config); + + $result = Pay::alipay()->pos([ + 'out_trade_no' => time(), + 'auth_code' => $auth_code, + 'total_amount' => '0.01', + 'subject' => 'yansongda 测试 - 01', + ]); + d($result); // $arr = []; // foreach ($a as $k => $v) { // $pid = Goodsclass::where('id', $v)->value('pid'); diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index d7bed88..ed32a0b 100644 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -6,6 +6,7 @@ use app\common\enum\PayEnum; use app\common\logic\PayNotifyLogic; use app\common\model\retail\Cashierclass; use app\common\service\pay\PayService; +use support\Log; /** * 支付 @@ -15,7 +16,7 @@ use app\common\service\pay\PayService; class PayController extends BaseApiController { - public $notNeedLogin = ['notifyMnp']; + public $notNeedLogin = ['notifyMnp','alipay_return','alipay_notify']; /** * @notes 小程序支付回调 @@ -57,4 +58,34 @@ class PayController extends BaseApiController return $this->fail('订单支付中'); } } + + /** + * 支付宝同步回调地址 + */ + public function alipay_return(){ + $app=new PayService(); + $result = $app->alipay->callback(Request()->post()); + Log::error('支付宝同步回调',$result->toArray()); + // if($result && $result->event_type=='TRANSACTION.SUCCESS'){ + // $ciphertext=$result->resource['ciphertext']; + // if ($ciphertext['trade_state'] === 'SUCCESS') { + // $extra['transaction_id'] = $ciphertext['transaction_id']; + // $attach = $ciphertext['attach']; + // switch ($attach) { + // case 'cashierclass': + // PayNotifyLogic::handle('cashierclass', $ciphertext['out_trade_no'], $ciphertext); + // $app->wechat->success(); + // break; + // } + // } + // } + } + /** + * 支付宝异步回调地址 + */ + public function alipay_notify(){ + $app=new PayService(); + $result = $app->alipay->callback(Request()->post()); + Log::error('支付宝异步回调',$result->toArray()); + } } diff --git a/app/api/controller/goods/GoodsController.php b/app/api/controller/goods/GoodsController.php index 3769157..7ec6cc0 100644 --- a/app/api/controller/goods/GoodsController.php +++ b/app/api/controller/goods/GoodsController.php @@ -13,5 +13,12 @@ class GoodsController extends BaseApiController{ return $this->dataLists(new GoodsLists()); } + /** + * 商品列表 + */ + public function mer_list(){ + $this->request->__set('mer_id',$this->request->userInfo['merchant']['mer_id']??0); + return $this->dataLists(new GoodsLists()); + } } \ No newline at end of file diff --git a/app/api/lists/goods/GoodsLists.php b/app/api/lists/goods/GoodsLists.php index 93cdc14..46f883c 100644 --- a/app/api/lists/goods/GoodsLists.php +++ b/app/api/lists/goods/GoodsLists.php @@ -8,6 +8,7 @@ use app\common\model\goods\Goods; use app\common\lists\ListsSearchInterface; use app\common\model\goods\Goodsclass; use app\common\model\goods\GoodsLabel; +use think\facade\Db; /** * 商品列表列表 @@ -96,6 +97,20 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface }else{ $order['id'] = 'desc'; } + $mer_id=$this->request->__get('mer_id'); + if($mer_id){ + $goods_id=Db::name('merchant_bind_goods')->where('mer_id',$mer_id)->limit($this->limitOffset, $this->limitLength)->column('goods_id'); + if($goods_id){ + return Goods::where($this->searchWhere)->where('id','in',$goods_id) + ->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs','sales','spec']) + ->with(['className','brandName','unitName']) + ->order($order) + ->select() + ->toArray(); + }else{ + return []; + } + } return Goods::where($this->searchWhere)->where($where) ->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs','sales','spec']) ->limit($this->limitOffset, $this->limitLength) @@ -127,6 +142,10 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface $where[]=['class','=',$class_all]; } } + $mer_id=$this->request->__get('mer_id'); + if($mer_id){ + return Db::name('merchant_bind_goods')->where('mer_id',$mer_id)->count(); + } return Goods::where($this->searchWhere)->where($where)->count(); } diff --git a/app/common/service/pay/PayService.php b/app/common/service/pay/PayService.php index bfd3132..3fab754 100644 --- a/app/common/service/pay/PayService.php +++ b/app/common/service/pay/PayService.php @@ -33,7 +33,7 @@ class PayService extends BasePayService * @var */ public $wechat; - protected $alipay; + public $alipay; /** @@ -57,6 +57,7 @@ class PayService extends BasePayService $this->auth = UserAuth::where(['user_id' => $userId, 'terminal' => $terminal])->findOrEmpty(); } $this->wechat=Pay::wechat(); + $this->alipay=Pay::alipay(); } diff --git a/config/payment.php b/config/payment.php index c0aa7e2..9b81ce6 100644 --- a/config/payment.php +++ b/config/payment.php @@ -13,15 +13,15 @@ return [ // 必填-应用私钥 字符串或路径 'app_secret_cert' => 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCktKWIoqSZ8BoSpALMsvTEsEQ1kF++wBeneams0Q17LvqGDBgiGuuICU0tnhBrjEkJFIw+5ApiHdkwbjFRqDqXyNj7B9fMBWp+QeHf6KvmRsPOHZegyvmQlqvMYf6hF4OwVKDrtVi6I1hVdrwf35h8KEGh4QM0WyXno2bJ7OVQDL49enrG7dXZQkwnwiluuxgjKphC2WYHCERGiYbrRKWXtQmzivjw7YTtfSXvypp8N3pSWXkWeLqpGGK3GG3pcUu4U+y4RFknnzSpiv20EJ6gw3pjUDkzexJoGh9byFOMoRVTJpIV8iTshdozd69ny5FjmIoXIouGCjdwp6M+XCXVAgMBAAECggEAJ1Dn4sHQQN7Lmn+EG5DsVLcu0QpxkHsSKmwkUJhme20vaCgi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DTZBtL/1OmpDV2yPYi+xpipgzETB44mQnpcAcvaxU59j0oZQxXsWXHKNfOBzO2KgrReHnY7oUurPPq1A76yEcGmtn', // 必填-应用公钥证书 路径 - 'app_public_cert_path' => runtime_path() . '/cert/ali/RSA2048.txt', + 'app_public_cert_path' => runtime_path() . '/cert/ali/appCertPublicKey_2021004146699603.crt', // 必填-支付宝公钥证书 路径 - 'alipay_public_cert_path' => runtime_path() . '/cert/ali/alipayPublicKey_RSA2.txt', + 'alipay_public_cert_path' => runtime_path() . '/cert/ali/alipayCertPublicKey_RSA2.crt', // 必填-支付宝根证书 路径 - 'alipay_root_cert_path' => runtime_path() . '/cert/ali/CSR.csr', + 'alipay_root_cert_path' => runtime_path() . '/cert/ali/alipayRootCert.crt', // 选填-同步回调地址 - 'return_url' => 'https://erp.lihaink.cn/api/pay/alipay-return', + 'return_url' => 'https://erp.lihaink.cn/api/pay/alipay_return', // 选填-异步回调地址 - 'notify_url' => 'https://erp.lihaink.cn/api/pay/alipay-notify', + 'notify_url' => 'https://erp.lihaink.cn/api/pay/alipay_notify', // 选填-服务商模式下的服务商 id,当 mode 为 Pay::MODE_SERVICE 时使用该参数 'service_provider_id' => '', // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE