Пример #1
0
/**
 * 创建推广代理
 * @param int $user_id
 */
function create_promotion_agent($user_id)
{
    global $ecs, $db;
    // 查询可用的微信二维码
    $sql = "SELECT id FROM " . $ecs->table('weixin_qrcode') . " WHERE in_use = 0 ORDER BY id ASC";
    $qrcode = $db->getOne($sql);
    if (empty($qrcode)) {
        $db->autoExecute($ecs->table('weixin_qrcode'), array('type' => 1, 'purpose' => 1, 'in_use' => 1));
        $qrcode = $db->insert_id();
        // 通过微信接口创建
        include_once ROOT_PATH . '/includes/cls_wechat.php';
        $wechat = new WechatApi();
        $wx_qr = $wechat->create_permanent_qrcode(WechatApi::QRCODE_SCENE_LIMIT, $qrcode);
        $db->autoExecute($ecs->table('weixin_qrcode'), array('ticket' => $wx_qr['ticket'], 'content' => $wx_qr['url']), 'UPDATE', "id = {$qrcode}");
    } else {
        $db->autoExecute($ecs->table('weixin_qrcode'), array('purpose' => 1, 'in_use' => 1), 'UPDATE', "id = {$qrcode}");
    }
    $db->autoExecute($ecs->table('promotion_agent'), array('user_id' => $user_id, 'wx_qrcode' => $qrcode));
}