快付生态系统重要单位是积分,积分的产出也是通过系统的任务模型来产生的。会员要赚取更多的积分也是需要向平台的会员购买会员之间积分互转涉及到以下流程:
积分交易购买流程:
1.卖家设积分挂单到系统公海
2.买家选择要购买积分单
3.卖家付款并上传付款凭证
4.卖家确认收款,并确认积分转出
以下是开发快付生态系统积分交易核心代码段
public function creditOrderDetailAction()
{
$post = input('post.');
$data = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
do{
//参数不正确
if( !$post['id']
OR !in_array($post['type'],['confirm_expend','refund','appeal','confirm_income']))
{
break;
}
//比对用户id和卖家id和对应的类型是否一致
$order_info = Order::find($post['id'])->toArray();
if( ( $order_info['status'] == 1 && !in_array($post['type'],['confirm_expend','refund','appeal']))
OR ( $order_info['status'] == 2 && !in_array($post['type'],['appeal','confirm_income']))
OR ($order_info['status'] == 3 && !in_array($post['type'],['refund','confirm_income']))
OR $order_info['status'] == 4
OR $order_info['status'] == 5
)
{
$data['msg'] = '订单状态错误';
break;
}
$post_info = Jfyz::find($order_info['post_id'])->toArray();
if( ( in_array($post['type'],['appeal','confirm_income']) && $order_info['uid'] != self::$userInfo['id'] )
OR ( in_array($post['type'],['refund','confirm_expend']) && $post_info['uid'] != self::$userInfo['id'] )
)
{
break;
}
if( $post['type'] == 'confirm_expend' && !$post['thumb'])
{
$data['msg'] = '请上传转款凭证';
break;
}
if( in_array($post['type'],['appeal','refund']) && !$post['note'])
{
$data['msg'] = '请填写原因';
}
$status = [
'confirm_expend' => 2,
'appeal' => 3,
'refund' => 4,
'confirm_income' => 5
];
Jfyz::startTrans();
$mobile = '';
$json_data = '';
if( in_array($post['type'],['confirm_expend','refund']))
{
$member_info = Member::field('id,openid,credit1,mobile')->where('id',$order_info['uid'])->find()->toArray();
$mobile = $member_info['mobile'];
$json_data = $post['type'] == 'confirm_expend' ? '{money:"'.bcsub(bcmul($order_info['credit'],0.97,2),2,2).'"}' : '{credit:"'.$order_info['credit'].'"}';
}
try{
//修改订单状态;
$order_update = ['status'=>$status[$post['type']],'edit_time'=>time()];
if($post['type'] == 'confirm_expend') $order_update['thumb'] = $post['thumb'];
if($post['type'] == 'refund' OR $post['type'] == 'appeal') $order_update['note'] = $post['note'];
Order::where('id',$post['id'])->update($order_update);
//如果是驳回,就得退回积分给用户,同时增加驿站可收入积分,减少卖家锁定的积分。
if( $post['type'] == 'refund')
{
//增加日志:
$member_info['credit1'] = Member::getUserCredit($order_info['uid'],'credit1');
MemberCreditRecord::creditLog($member_info,$order_info['credit'],'credit1','积分兑换被驳回,退回'.$order_info['credit'].'积分','10');
//减少用户积分
Member::creditAction( $order_info['uid'],$order_info['credit'],0,'credit1');
//返回可收积分的值
Jfyz::where('id',$order_info['post_id'])->exp('lock_credit','lock_credit - '.$order_info['credit'])->exp('allow_credit','allow_credit + '.$order_info['credit'])->update();
//如果状态为已过期,则恢复状态
if(Jfyz::where('id',$order_info['post_id'])->where('status',4)->value('allow_credit') > 1000 )
Jfyz::where('id',$order_info['post_id'])->update(['status'=>3]);
}
//如果是确认收款,就得释放卖家锁定的积分,增加卖家的可提现积分。
if( $post['type'] == 'confirm_income' )
Jfyz::where('id',$order_info['post_id'])->exp('lock_credit','lock_credit - '.$order_info['credit'])->exp('income_credit','income_credit + '.$order_info['credit'])->update();
Jfyz::commit();
$data['code'] = 1;
$data['msg'] = '操作成功!';
//发送短信
if( $mobile )
@Sms::main($mobile,$json_data,($post['type'] == 'refund' ? 'refund' : 'exchange') );
} catch ( \Exception $e)
{
var_dump($e->getMessage());
var_dump($e->getLine());
var_dump($e->getFile());
Jfyz::rollback();
}
}while(0);
return json($data);
}