1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\store\controller\api;
- use app\store\service\OrderService;
- use think\Db;
- class Notify
- {
-
- public function wxpay()
- {
- $wechat = \We::WePayOrder(config('wechat.miniapp'));
- $notify = $wechat->getNotify();
- if ($notify['result_code'] == 'SUCCESS' && $notify['return_code'] == 'SUCCESS') {
- if ($this->update($notify['out_trade_no'], $notify['transaction_id'], $notify['cash_fee'] / 100, 'wechat')) {
- return $wechat->getNotifySuccessReply();
- }
- } else {
- return $wechat->getNotifySuccessReply();
- }
- }
-
- private function update($order_no, $pay_no, $pay_price, $type = 'wechat')
- {
-
- $where = ['order_no' => $order_no, 'pay_state' => '0', 'status' => '2'];
- $order = Db::name('StoreOrder')->where($where)->find();
- if (empty($order)) return false;
-
- $result = Db::name('StoreOrder')->where($where)->update([
- 'pay_type' => $type, 'pay_no' => $pay_no, 'status' => '3',
- 'pay_price' => $pay_price, 'pay_state' => '1', 'pay_at' => date('Y-m-d H:i:s'),
- ]);
-
- OrderService::update($order['order_no']);
- return $result !== false;
- }
- }
|