租房掌柜微信小程序Api以及小程序前端模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
2.2 KiB

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Notify extends Controller{
public function clean(){
$wechat = new \WeChat\Pay(config('wechat.miniapp'));
// 4. 获取通知参数
$data = $wechat->getNotify();
//file_put_contents('./wechat_pay.log', var_export($data,true),FILE_APPEND);
if ($data['return_code'] === 'SUCCESS' && $data['result_code'] === 'SUCCESS') {
// @todo 去更新下原订单的支付状态
$order_no = $data['out_trade_no'];
$update = [
'order_no'=>$order_no,
'pay_money'=>$data['total_fee'] / 100,
'pay_time'=>time(),
'transaction_no'=>$data['transaction_id'],
'state'=> 1,
];
try {
$res = Db::name('CloudCleanOrder')->where('order_no',$order_no)->update($update);
if ($res){
$this->selectClean($order_no, $data['openid']);
// 返回接收成功的回复
ob_clean();
echo $wechat->getNotifySuccessReply();
}
}catch (\Throwable $e){
file_put_contents('./wechat_pay.log', $e->getMessage(),FILE_APPEND);
}
}
}
/**
* 分配保洁
*/
public function selectClean($order_no = 0,$openid = 0){
$sql = Db::name('CloudCleanOrder')
->alias('o')
->where('m.openid',Db::raw('o.service_openid'))
->where('complete','<',Db::raw('second'))
->field('count(*)')
->buildSql();
$clean = Db::name('CloudMember')
->alias('m')
->field($sql.' as counts,m.id, m.openid, m.nickname')
->where('is_clean',1)
->where('m.openid','<>',$openid)
->order('counts','asc')
->order('id','asc')
->select();
if (!$clean) {
file_put_contents('./wechat_pay.log', "\nnot find cleaner\n",FILE_APPEND);
return false;
}
$first = current($clean);
Db::name('CloudCleanOrder')->where('order_no',$order_no)->update(['service_openid'=>$first['openid']]);
//dump($res);
}
}