DROP TABLE IF EXISTS `edu_order`;
CREATE TABLE `edu_order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`out_trade_no` varchar(55) NOT NULL COMMENT '自定义的订单号',
`transaction_id` varchar(55) DEFAULT NULL COMMENT '微信订单号',
`courseid` int(11) NOT NULL DEFAULT '0' COMMENT '课程id',
`price` decimal(5,2) NOT NULL,
`create_time` int(11) NOT NULL DEFAULT '0',
`userid` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
`trade_type` varchar(50) NOT NULL DEFAULT '' COMMENT '支付方式,默认为空',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0:未付款,1:已付款,-1:已过期',
`trade_state` varchar(55) NOT NULL DEFAULT '' COMMENT '微信订单中工单交易状态',
PRIMARY KEY (`id`,`out_trade_no`),
UNIQUE KEY `out_trade_no` (`out_trade_no`),
UNIQUE KEY `transaction_id` (`transaction_id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of edu_order
-- ----------------------------
INSERT INTO `edu_order` VALUES ('13', '25620191211181735256961371', '0', '71', '0.01', '1576059458', '256', '0', '0', 'NOTPAY');
INSERT INTO `edu_order` VALUES ('14', '256201912111835202564453971', '01', '71', '0.01', '1576060523', '256', '0', '0', 'NOTPAY');
INSERT INTO `edu_order` VALUES ('15', '156201912120951252562471671', '', '71', '0.01', '1576115646', '256', '-', '1', 'NOTPAY');在postman测试打印出来是save()方法返回为1,debug发现更新语句为UPDATE `edu_order` SET `transaction_id`='1008450740201411110005820875',`trade_type`='MICROPAY',`status`=1,`trade_state`='SUCCESS' WHERE `id` = 15 AND `out_trade_no` = '156201912120951252562471671'这语句在Navicat运行更新正常,但是在postman运行成功的情况下,后台数据库没有任何更新,新手求助下面的是代码:
class Wxpay
{
//微信回调
public function notify(){
$orderData=[];//这里省略返回的xm
......
.......
$ret=model('Order')->get_one_order_by_out_trade_no($data['out_trade_no']);
$orderData['id']=$ret->id;
$res=model('Order')->update_order($orderData);
halt($res);
}
namespace app\common\model;
class Order extends BaseModel
{
//通过订单号查找记录
public function get_one_order_by_out_trade_no($id){
$res=$this->where('out_trade_no','=',$id)->field('id,status')->find();
// echo $this->getLastSql();
return $res;
}
//更新订单
public function update_order($data=''){
$res=$this->isUpdate(true)->save($data);
echo $this->getLastSql();
return $res;
}
}下图postman测试结果:
最佳答案